~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ScanOperationImpl.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2010, 2012, 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
}