58948627b04a3e0496ce9dd9f80ff97ae444dfc7
[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.NdbIndexScanOperation;
21
22 import com.mysql.clusterj.ClusterJFatalInternalException;
23
24 import com.mysql.clusterj.core.store.Column;
25 import com.mysql.clusterj.core.store.IndexScanOperation;
26 import com.mysql.clusterj.core.store.Table;
27 import com.mysql.clusterj.core.util.I18NHelper;
28 import com.mysql.clusterj.core.util.Logger;
29 import com.mysql.clusterj.core.util.LoggerFactoryService;
30
31 import java.math.BigDecimal;
32 import java.math.BigInteger;
33
34 /**
35  *
36  */
37 class IndexScanOperationImpl extends ScanOperationImpl implements IndexScanOperation {
38
39     /** My message translator */
40     static final I18NHelper local = I18NHelper
41             .getInstance(IndexScanOperationImpl.class);
42
43     /** My logger */
44     static final Logger logger = LoggerFactoryService.getFactory()
45             .getInstance(IndexScanOperationImpl.class);
46
47     private NdbIndexScanOperation ndbIndexScanOperation;
48
49     public IndexScanOperationImpl(Table storeTable, NdbIndexScanOperation ndbIndexScanOperation,
50             ClusterTransactionImpl transaction) {
51         super(storeTable, ndbIndexScanOperation, transaction);
52         this.ndbIndexScanOperation = ndbIndexScanOperation;
53     }
54
55     public void setBoundBigInteger(Column storeColumn, BoundType type, BigInteger value) {
56         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
57                 Utility.convertValue(storeColumn, value));
58         handleError(returnCode, ndbIndexScanOperation);
59     }
60
61     public void setBoundByte(Column storeColumn, BoundType type, byte value) {
62         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
63                 Utility.convertValue(storeColumn, value));
64         handleError(returnCode, ndbIndexScanOperation);
65     }
66
67     public void setBoundBytes(Column storeColumn, BoundType type, byte[] value) {
68         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
69                 Utility.convertValue(storeColumn, value));
70         handleError(returnCode, ndbIndexScanOperation);
71     }
72
73     public void setBoundDecimal(Column storeColumn, BoundType type, BigDecimal value) {
74         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
75                 Utility.convertValue(storeColumn, value));
76         handleError(returnCode, ndbIndexScanOperation);
77     }
78
79     public void setBoundDouble(Column storeColumn, BoundType type, Double value) {
80         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
81                 Utility.convertValue(storeColumn, value));
82         handleError(returnCode, ndbIndexScanOperation);
83     }
84
85     public void setBoundFloat(Column storeColumn, BoundType type, Float value) {
86         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
87                 Utility.convertValue(storeColumn, value));
88         handleError(returnCode, ndbIndexScanOperation);
89     }
90
91     public void setBoundShort(Column storeColumn, BoundType type, short value) {
92         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
93                 Utility.convertValue(storeColumn, value));
94         handleError(returnCode, ndbIndexScanOperation);
95     }
96
97     public void setBoundInt(Column storeColumn, BoundType type, Integer value) {
98         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
99                 Utility.convertValue(storeColumn, value));
100         handleError(returnCode, ndbIndexScanOperation);
101     }
102
103     public void setBoundLong(Column storeColumn, BoundType type, long value) {
104         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
105                 Utility.convertValue(storeColumn, value));
106         handleError(returnCode, ndbIndexScanOperation);
107     }
108
109     public void setBoundString(Column storeColumn, BoundType type, String value) {
110         int returnCode = ndbIndexScanOperation.setBound(storeColumn.getName(), convertBoundType(type),
111                 Utility.convertValue(storeColumn, value));
112         handleError(returnCode, ndbIndexScanOperation);
113     }
114
115     private int convertBoundType(BoundType type) {
116         switch (type) {
117             case BoundEQ:
118                 return NdbIndexScanOperation.BoundType.BoundEQ;
119             case BoundGE:
120                 return NdbIndexScanOperation.BoundType.BoundGE;
121             case BoundGT:
122                 return NdbIndexScanOperation.BoundType.BoundGT;
123             case BoundLE:
124                 return NdbIndexScanOperation.BoundType.BoundLE;
125             case BoundLT:
126                 return NdbIndexScanOperation.BoundType.BoundLT;
127             default:
128                 throw new ClusterJFatalInternalException(
129                         local.message("ERR_Implementation_Should_Not_Occur"));
130         }
131     }
132
133     public void endBound(int rangeNumber) {
134         if (logger.isDetailEnabled()) logger.detail("IndexScanOperationImpl.endBound(" + rangeNumber + ")");
135         int returnCode = ndbIndexScanOperation.end_of_bound(rangeNumber);
136         handleError(returnCode, ndbIndexScanOperation);
137     }
138
139 }