58bdae4a141bd3d720394f46fe26c4c26142688d
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2  *  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16  */
17
18 package com.mysql.clusterj.tie;
19
20 import java.util.List;
21
22 import com.mysql.clusterj.core.store.Column;
23
24 import com.mysql.clusterj.core.util.I18NHelper;
25 import com.mysql.clusterj.core.util.Logger;
26 import com.mysql.clusterj.core.util.LoggerFactoryService;
27 import com.mysql.clusterj.tie.DbImpl.BufferManager;
28
29 import com.mysql.ndbjtie.ndbapi.NdbScanOperation;
30
31 /**
32  *
33  */
34 class ScanResultDataImpl extends ResultDataImpl {
35
36     /** My message translator */
37     static final I18NHelper local = I18NHelper
38             .getInstance(ScanResultDataImpl.class);
39
40     /** My logger */
41     static final Logger logger = LoggerFactoryService.getFactory()
42             .getInstance(ScanResultDataImpl.class);
43
44     private NdbScanOperation ndbScanOperation = null;
45
46
47     /** Flags for iterating a scan */
48     protected final int RESULT_READY = 0;
49     protected final int SCAN_FINISHED = 1;
50     protected final int CACHE_EMPTY = 2;
51
52     public ScanResultDataImpl(NdbScanOperation ndbScanOperation, List<Column> storeColumns,
53             int maximumColumnId, int bufferSize, int[] offsets, int[] lengths, int maximumColumnLength,
54             BufferManager bufferManager) {
55         super(ndbScanOperation, storeColumns, maximumColumnId, bufferSize, offsets, lengths,
56                 bufferManager, false);
57         this.ndbScanOperation = ndbScanOperation;
58     }
59
60     @Override
61     public boolean next() {
62         // NdbScanOperation may have many results.
63         boolean done = false;
64         boolean fetch = false;
65         boolean force = true; // always true for scans
66         while (!done) {
67             int result = ndbScanOperation.nextResult(fetch, force);
68             switch (result) {
69                 case RESULT_READY:
70                     return true;
71                 case SCAN_FINISHED:
72                     ndbScanOperation.close(true, true);
73                     return false;
74                 case CACHE_EMPTY:
75                     fetch = true;
76                     break;
77                 default:
78                     Utility.throwError(result, ndbScanOperation.getNdbError());
79             }
80         }
81         return true; // this statement is needed to make the compiler happy but it's never executed
82     }
83
84 }