]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
0a811613bbf9b359253da1a90fbacd8c2d2d75ed
[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 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;
24
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;
30
31 /**
32  *
33  */
34 class ScanOperationImpl extends OperationImpl implements ScanOperation {
35
36     private NdbScanOperation ndbScanOperation;
37
38     ScanOperationImpl(Table storeTable, NdbScanOperation operation,
39             ClusterTransactionImpl clusterTransaction) {
40         super(storeTable, operation, clusterTransaction);
41         this.ndbScanOperation = operation;
42     }
43
44     public void close() {
45         ndbScanOperation.close(true, true);
46     }
47
48     public void deleteCurrentTuple() {
49         int returnCode = ndbScanOperation.deleteCurrentTuple();
50         handleError(returnCode, ndbScanOperation);
51     }
52
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);
58         return scanFilter;
59     }
60
61     public int nextResult(boolean fetch) {
62         int result = ndbScanOperation.nextResult(fetch, false);
63         clusterTransaction.handleError(result);
64         return result;
65     }
66
67     @Override
68     public ResultData resultData() {
69         ResultData result = new ScanResultDataImpl(ndbScanOperation, storeColumns,
70                 maximumColumnId, bufferSize, offsets, lengths, maximumColumnLength, bufferManager);
71         clusterTransaction.executeNoCommit(false, true);
72         return result;
73     }
74
75     @Override
76     protected void handleError(int returnCode, NdbOperation ndbOperation) {
77         if (returnCode == 0) {
78             return;
79         } else {
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);
85             } else {
86                 // the error must be in the NdbTransaction
87                 clusterTransaction.handleError(returnCode);
88             }
89         }
90     }
91
92 }