]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
656a35fb04908f17bf759bce1c6fc161c07d200d
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2  *  Copyright 2010 Sun Microsystems, Inc.
3  *  All rights reserved. Use is subject to license terms.
4  *
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.
8  *
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.
13  *
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
17  */
18
19 package com.mysql.clusterj.bindings;
20
21 import com.mysql.cluster.ndbj.NdbApiException;
22 import com.mysql.cluster.ndbj.NdbIndexScanOperation;
23
24 import com.mysql.clusterj.ClusterJDatastoreException;
25 import com.mysql.clusterj.ClusterJFatalInternalException;
26
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;
32
33 import java.math.BigDecimal;
34
35 import java.sql.Date;
36 import java.sql.Time;
37 import java.sql.Timestamp;
38
39 /**
40  *
41  */
42 class IndexScanOperationImpl extends ScanOperationImpl implements IndexScanOperation {
43
44     /** My message translator */
45     static final I18NHelper local = I18NHelper.getInstance(ClusterConnectionImpl.class);
46
47     /** My logger */
48     static final Logger logger = LoggerFactoryService.getFactory()
49             .getInstance(IndexScanOperationImpl.class);
50
51     private NdbIndexScanOperation ndbIndexScanOperation;
52
53     public IndexScanOperationImpl(NdbIndexScanOperation selectIndexScanOperation,
54             ClusterTransactionImpl transaction) {
55         super(selectIndexScanOperation, transaction);
56         this.ndbIndexScanOperation = selectIndexScanOperation;
57     }
58
59     public void setBoundByte(Column storeColumn, BoundType type, byte byteValue) {
60         try {
61             ndbIndexScanOperation.setBoundInt(storeColumn.getName(), convertBoundType(type), (int)byteValue);
62         } catch (NdbApiException ndbApiException) {
63             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
64                     ndbApiException);
65         }
66     }
67
68     public void setBoundBytes(Column storeColumn, BoundType type, byte[] value) {
69         try {
70             ndbIndexScanOperation.setBoundBytes(storeColumn.getName(), convertBoundType(type), value);
71         } catch (NdbApiException ndbApiException) {
72             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
73                     ndbApiException);
74         }
75     }
76
77     public void setBoundDatetime(Column storeColumn, BoundType type, Timestamp value) {
78         try {
79             ndbIndexScanOperation.setBoundDatetime(storeColumn.getName(), convertBoundType(type), value);
80         } catch (NdbApiException ndbApiException) {
81             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
82                     ndbApiException);
83         }
84     }
85
86     public void setBoundDate(Column storeColumn, BoundType type, Date value) {
87         try {
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"),
92                     ndbApiException);
93         }
94     }
95
96     public void setBoundTime(Column storeColumn, BoundType type, Time value) {
97         try {
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"),
102                     ndbApiException);
103         }
104     }
105
106     public void setBoundDecimal(Column storeColumn, BoundType type, BigDecimal value) {
107         try {
108             ndbIndexScanOperation.setBoundDecimal(storeColumn.getName(), convertBoundType(type), value);
109         } catch (NdbApiException ndbApiException) {
110             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
111                     ndbApiException);
112         }
113     }
114
115     public void setBoundDouble(Column storeColumn, BoundType type, Double value) {
116         try {
117             ndbIndexScanOperation.setBoundDouble(storeColumn.getName(), convertBoundType(type), value);
118         } catch (NdbApiException ndbApiException) {
119             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
120                     ndbApiException);
121         }
122     }
123
124     public void setBoundFloat(Column storeColumn, BoundType type, Float value) {
125         try {
126             ndbIndexScanOperation.setBoundFloat(storeColumn.getName(), convertBoundType(type), value);
127         } catch (NdbApiException ndbApiException) {
128             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
129                     ndbApiException);
130         }
131     }
132
133     public void setBoundInt(Column storeColumn, BoundType type, Integer value) {
134         try {
135             ndbIndexScanOperation.setBoundInt(storeColumn.getName(), convertBoundType(type), value);
136         } catch (NdbApiException ndbApiException) {
137             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
138                     ndbApiException);
139         }
140     }
141
142     public void setBoundLong(Column storeColumn, BoundType type, long value) {
143         try {
144             ndbIndexScanOperation.setBoundLong(storeColumn.getName(), convertBoundType(type), value);
145         } catch (NdbApiException ndbApiException) {
146             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
147                     ndbApiException);
148         }
149     }
150
151     public void setBoundString(Column storeColumn, BoundType type, String value) {
152         try {
153             ndbIndexScanOperation.setBoundString(storeColumn.getName(), convertBoundType(type), value);
154         } catch (NdbApiException ndbApiException) {
155             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
156                     ndbApiException);
157         }
158     }
159
160     public void setBoundTimestamp(Column storeColumn, BoundType type, Timestamp value) {
161         try {
162             ndbIndexScanOperation.setBoundTimestamp(storeColumn.getName(), convertBoundType(type), value);
163         } catch (NdbApiException ndbApiException) {
164             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
165                     ndbApiException);
166         }
167     }
168
169     private NdbIndexScanOperation.BoundType convertBoundType(BoundType type) {
170         switch (type) {
171             case BoundEQ:
172                 return NdbIndexScanOperation.BoundType.BoundEQ;
173             case BoundGE:
174                 return NdbIndexScanOperation.BoundType.BoundGE;
175             case BoundGT:
176                 return NdbIndexScanOperation.BoundType.BoundGT;
177             case BoundLE:
178                 return NdbIndexScanOperation.BoundType.BoundLE;
179             case BoundLT:
180                 return NdbIndexScanOperation.BoundType.BoundLT;
181             default:
182                 throw new ClusterJFatalInternalException(
183                         local.message("ERR_Implementation_Should_Not_Occur"));
184         }
185     }
186
187 }