2 * Copyright (c) 2010, 2011, 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.NdbIndexScanOperation;
22 import com.mysql.clusterj.ClusterJFatalInternalException;
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;
31 import java.math.BigDecimal;
32 import java.math.BigInteger;
37 class IndexScanOperationImpl extends ScanOperationImpl implements IndexScanOperation {
39 /** My message translator */
40 static final I18NHelper local = I18NHelper
41 .getInstance(IndexScanOperationImpl.class);
44 static final Logger logger = LoggerFactoryService.getFactory()
45 .getInstance(IndexScanOperationImpl.class);
47 private NdbIndexScanOperation ndbIndexScanOperation;
49 public IndexScanOperationImpl(Table storeTable, NdbIndexScanOperation ndbIndexScanOperation,
50 ClusterTransactionImpl transaction) {
51 super(storeTable, ndbIndexScanOperation, transaction);
52 this.ndbIndexScanOperation = ndbIndexScanOperation;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
115 private int convertBoundType(BoundType type) {
118 return NdbIndexScanOperation.BoundType.BoundEQ;
120 return NdbIndexScanOperation.BoundType.BoundGE;
122 return NdbIndexScanOperation.BoundType.BoundGT;
124 return NdbIndexScanOperation.BoundType.BoundLE;
126 return NdbIndexScanOperation.BoundType.BoundLT;
128 throw new ClusterJFatalInternalException(
129 local.message("ERR_Implementation_Should_Not_Occur"));
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);