2 * Copyright 2010 Sun Microsystems, Inc.
3 * All rights reserved. Use is subject to license terms.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package com.mysql.clusterj.bindings;
21 import com.mysql.cluster.ndbj.NdbApiException;
22 import com.mysql.cluster.ndbj.NdbIndexScanOperation;
24 import com.mysql.clusterj.ClusterJDatastoreException;
25 import com.mysql.clusterj.ClusterJFatalInternalException;
27 import com.mysql.clusterj.core.store.Column;
28 import com.mysql.clusterj.core.store.IndexScanOperation;
29 import com.mysql.clusterj.core.util.I18NHelper;
30 import com.mysql.clusterj.core.util.Logger;
31 import com.mysql.clusterj.core.util.LoggerFactoryService;
33 import java.math.BigDecimal;
37 import java.sql.Timestamp;
42 class IndexScanOperationImpl extends ScanOperationImpl implements IndexScanOperation {
44 /** My message translator */
45 static final I18NHelper local = I18NHelper.getInstance(ClusterConnectionImpl.class);
48 static final Logger logger = LoggerFactoryService.getFactory()
49 .getInstance(IndexScanOperationImpl.class);
51 private NdbIndexScanOperation ndbIndexScanOperation;
53 public IndexScanOperationImpl(NdbIndexScanOperation selectIndexScanOperation,
54 ClusterTransactionImpl transaction) {
55 super(selectIndexScanOperation, transaction);
56 this.ndbIndexScanOperation = selectIndexScanOperation;
59 public void setBoundByte(Column storeColumn, BoundType type, byte byteValue) {
61 ndbIndexScanOperation.setBoundInt(storeColumn.getName(), convertBoundType(type), (int)byteValue);
62 } catch (NdbApiException ndbApiException) {
63 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
68 public void setBoundBytes(Column storeColumn, BoundType type, byte[] value) {
70 ndbIndexScanOperation.setBoundBytes(storeColumn.getName(), convertBoundType(type), value);
71 } catch (NdbApiException ndbApiException) {
72 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
77 public void setBoundDatetime(Column storeColumn, BoundType type, Timestamp value) {
79 ndbIndexScanOperation.setBoundDatetime(storeColumn.getName(), convertBoundType(type), value);
80 } catch (NdbApiException ndbApiException) {
81 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
86 public void setBoundDate(Column storeColumn, BoundType type, Date value) {
88 Timestamp timestamp = new Timestamp(value.getTime());
89 ndbIndexScanOperation.setBoundDatetime(storeColumn.getName(), convertBoundType(type), timestamp);
90 } catch (NdbApiException ndbApiException) {
91 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
96 public void setBoundTime(Column storeColumn, BoundType type, Time value) {
98 Timestamp timestamp = new Timestamp(value.getTime());
99 ndbIndexScanOperation.setBoundDatetime(storeColumn.getName(), convertBoundType(type), timestamp);
100 } catch (NdbApiException ndbApiException) {
101 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
106 public void setBoundDecimal(Column storeColumn, BoundType type, BigDecimal value) {
108 ndbIndexScanOperation.setBoundDecimal(storeColumn.getName(), convertBoundType(type), value);
109 } catch (NdbApiException ndbApiException) {
110 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
115 public void setBoundDouble(Column storeColumn, BoundType type, Double value) {
117 ndbIndexScanOperation.setBoundDouble(storeColumn.getName(), convertBoundType(type), value);
118 } catch (NdbApiException ndbApiException) {
119 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
124 public void setBoundFloat(Column storeColumn, BoundType type, Float value) {
126 ndbIndexScanOperation.setBoundFloat(storeColumn.getName(), convertBoundType(type), value);
127 } catch (NdbApiException ndbApiException) {
128 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
133 public void setBoundInt(Column storeColumn, BoundType type, Integer value) {
135 ndbIndexScanOperation.setBoundInt(storeColumn.getName(), convertBoundType(type), value);
136 } catch (NdbApiException ndbApiException) {
137 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
142 public void setBoundLong(Column storeColumn, BoundType type, long value) {
144 ndbIndexScanOperation.setBoundLong(storeColumn.getName(), convertBoundType(type), value);
145 } catch (NdbApiException ndbApiException) {
146 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
151 public void setBoundString(Column storeColumn, BoundType type, String value) {
153 ndbIndexScanOperation.setBoundString(storeColumn.getName(), convertBoundType(type), value);
154 } catch (NdbApiException ndbApiException) {
155 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
160 public void setBoundTimestamp(Column storeColumn, BoundType type, Timestamp value) {
162 ndbIndexScanOperation.setBoundTimestamp(storeColumn.getName(), convertBoundType(type), value);
163 } catch (NdbApiException ndbApiException) {
164 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
169 private NdbIndexScanOperation.BoundType convertBoundType(BoundType type) {
172 return NdbIndexScanOperation.BoundType.BoundEQ;
174 return NdbIndexScanOperation.BoundType.BoundGE;
176 return NdbIndexScanOperation.BoundType.BoundGT;
178 return NdbIndexScanOperation.BoundType.BoundLE;
180 return NdbIndexScanOperation.BoundType.BoundLT;
182 throw new ClusterJFatalInternalException(
183 local.message("ERR_Implementation_Should_Not_Occur"));