2
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18
package com.mysql.clusterj.tie;
20
import com.mysql.ndbjtie.ndbapi.NdbErrorConst;
21
import com.mysql.ndbjtie.ndbapi.NdbOperation;
22
import com.mysql.ndbjtie.ndbapi.NdbScanFilter;
23
import com.mysql.ndbjtie.ndbapi.NdbScanOperation;
25
import com.mysql.clusterj.core.spi.QueryExecutionContext;
26
import com.mysql.clusterj.core.store.ResultData;
27
import com.mysql.clusterj.core.store.ScanFilter;
28
import com.mysql.clusterj.core.store.ScanOperation;
29
import com.mysql.clusterj.core.store.Table;
34
class ScanOperationImpl extends OperationImpl implements ScanOperation {
36
private NdbScanOperation ndbScanOperation;
38
ScanOperationImpl(Table storeTable, NdbScanOperation operation,
39
ClusterTransactionImpl clusterTransaction) {
40
super(storeTable, operation, clusterTransaction);
41
this.ndbScanOperation = operation;
45
ndbScanOperation.close(true, true);
48
public void deleteCurrentTuple() {
49
int returnCode = ndbScanOperation.deleteCurrentTuple();
50
handleError(returnCode, ndbScanOperation);
53
public ScanFilter getScanFilter(QueryExecutionContext context) {
54
NdbScanFilter ndbScanFilter = NdbScanFilter.create(ndbScanOperation);
55
handleError(ndbScanFilter, ndbScanOperation);
56
ScanFilter scanFilter = new ScanFilterImpl(ndbScanFilter);
57
context.addFilter(scanFilter);
61
public int nextResult(boolean fetch) {
62
int result = ndbScanOperation.nextResult(fetch, false);
63
clusterTransaction.handleError(result);
68
public ResultData resultData() {
69
ResultData result = new ScanResultDataImpl(ndbScanOperation, storeColumns,
70
maximumColumnId, bufferSize, offsets, lengths, maximumColumnLength, bufferManager);
71
clusterTransaction.executeNoCommit(false, true);
76
protected void handleError(int returnCode, NdbOperation ndbOperation) {
77
if (returnCode == 0) {
80
// first check if the error is reported in the NdbOperation
81
NdbErrorConst ndbError = ndbOperation.getNdbError();
82
if (ndbError != null) {
83
// the error is in NdbOperation
84
Utility.throwError(returnCode, ndbError);
86
// the error must be in the NdbTransaction
87
clusterTransaction.handleError(returnCode);