d34a877d2355a1d309f930c9ad60efaeaa30a80f
[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.NdbOperation;
23
24 import com.mysql.clusterj.ClusterJDatastoreException;
25 import com.mysql.clusterj.core.store.Blob;
26 import com.mysql.clusterj.core.store.Column;
27 import com.mysql.clusterj.core.store.Operation;
28 import com.mysql.clusterj.core.store.ResultData;
29
30 import com.mysql.clusterj.core.util.I18NHelper;
31 import com.mysql.clusterj.core.util.Logger;
32 import com.mysql.clusterj.core.util.LoggerFactoryService;
33
34 import java.math.BigDecimal;
35
36 import java.sql.Date;
37 import java.sql.Time;
38 import java.sql.Timestamp;
39
40 /**
41  *
42  */
43 class OperationImpl implements Operation {
44
45     /** My message translator */
46     static final I18NHelper local = I18NHelper.getInstance(OperationImpl.class);
47
48     /** My logger */
49     static final Logger logger = LoggerFactoryService.getFactory()
50             .getInstance(OperationImpl.class);
51
52     private NdbOperation ndbOperation;
53
54     private ClusterTransactionImpl clusterTransaction;
55
56     public OperationImpl(NdbOperation operation, ClusterTransactionImpl transaction) {
57         this.ndbOperation = operation;
58         this.clusterTransaction = transaction;
59     }
60
61     public void equalBoolean(Column storeColumn, boolean booleanValue) {
62         throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
63     }
64
65     public void equalByte(Column storeColumn, byte b) {
66         try {
67             ndbOperation.equalInt(storeColumn.getName(), (int)b);
68         } catch (NdbApiException ndbApiException) {
69             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
70                     ndbApiException);
71         }
72     }
73
74     public void equalBytes(Column storeColumn, byte[] value) {
75         try {
76             ndbOperation.equalBytes(storeColumn.getName(), value);
77         } catch (NdbApiException ndbApiException) {
78             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
79                     ndbApiException);
80         }
81     }
82
83     public void equalDecimal(Column storeColumn, BigDecimal value) {
84         try {
85             ndbOperation.equalDecimal(storeColumn.getName(), value);
86         } catch (NdbApiException ndbApiException) {
87             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
88                     ndbApiException);
89         }
90     }
91
92     public void equalInt(Column storeColumn, int value) {
93         try {
94             ndbOperation.equalInt(storeColumn.getName(), value);
95         } catch (NdbApiException ndbApiException) {
96             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
97                     ndbApiException);
98         }
99     }
100
101     public void equalLong(Column storeColumn, long value) {
102         try {
103             ndbOperation.equalLong(storeColumn.getName(), value);
104         } catch (NdbApiException ndbApiException) {
105             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
106                     ndbApiException);
107         }
108     }
109
110     public void equalString(Column storeColumn, String value) {
111         try {
112             ndbOperation.equalString(storeColumn.getName(), value);
113         } catch (NdbApiException ndbApiException) {
114             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
115                     ndbApiException);
116         }
117     }
118
119     public void equalTimestamp(Column storeColumn, Timestamp value) {
120         try {
121             ndbOperation.equalTimestamp(storeColumn.getName(), value);
122         } catch (NdbApiException ndbApiException) {
123             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
124                     ndbApiException);
125         }
126     }
127
128     public void equalDatetime(Column storeColumn, Timestamp value) {
129         try {
130             ndbOperation.equalDatetime(storeColumn.getName(), value);
131         } catch (NdbApiException ndbApiException) {
132             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
133                     ndbApiException);
134         }
135     }
136
137     public void equalDate(Column storeColumn, Date value) {
138         try {
139             Timestamp timestamp = new Timestamp(((Date)value).getTime());
140             ndbOperation.equalDatetime(storeColumn.getName(), timestamp);
141         } catch (NdbApiException ndbApiException) {
142             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
143                     ndbApiException);
144         }
145     }
146
147     public void equalTime(Column storeColumn, Time value) {
148         try {
149             Timestamp timestamp = new Timestamp(((Time)value).getTime());
150             ndbOperation.equalDatetime(storeColumn.getName(), timestamp);
151         } catch (NdbApiException ndbApiException) {
152             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
153                     ndbApiException);
154         }
155     }
156
157     public void getBlob(Column storeColumn) {
158         try {
159             ndbOperation.getBlob(storeColumn.getName());
160         } catch (NdbApiException ndbApiException) {
161             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
162                     ndbApiException);
163         }
164     }
165
166     public Blob getBlobHandle(Column storeColumn) {
167         try {
168             return new BlobImpl(ndbOperation.getBlobHandle(storeColumn.getName()));
169         } catch (NdbApiException ndbApiException) {
170             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
171                     ndbApiException);
172         }
173     }
174
175     public void getValue(Column storeColumn) {
176         try {
177             ndbOperation.getValue(storeColumn.getName());
178         } catch (NdbApiException ndbApiException) {
179             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
180                     ndbApiException);
181         }
182     }
183
184     public void postExecuteCallback(Runnable callback) {
185         clusterTransaction.postExecuteCallback(callback);
186     }
187
188     public ResultData resultData() {
189         // execute the transaction to get results
190         clusterTransaction.executeNoCommit();
191         return new ResultDataImpl(ndbOperation.resultData());
192     }
193
194     public void setBoolean(Column storeColumn, Boolean value) {
195         throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
196     }
197
198     public void setByte(Column storeColumn, byte value) {
199         try {
200             ndbOperation.setInt(storeColumn.getName(), (int)value);
201         } catch (NdbApiException ndbApiException) {
202             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
203                     ndbApiException);
204         }
205     }
206
207     public void setBytes(Column storeColumn, byte[] value) {
208         try {
209             ndbOperation.setBytes(storeColumn.getName(), value);
210         } catch (NdbApiException ndbApiException) {
211             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
212                     ndbApiException);
213         }
214     }
215
216     public void setDate(Column storeColumn, Date value) {
217         try {
218             ndbOperation.setDate(storeColumn.getName(), value);
219         } catch (NdbApiException ndbApiException) {
220             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
221                     ndbApiException);
222         }
223     }
224
225     public void setDecimal(Column storeColumn, BigDecimal value) {
226         try {
227             ndbOperation.setDecimal(storeColumn.getName(), value);
228         } catch (NdbApiException ndbApiException) {
229             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
230                     ndbApiException);
231         }
232     }
233
234     public void setDouble(Column storeColumn, Double value) {
235         try {
236             ndbOperation.setDouble(storeColumn.getName(), value);
237         } catch (NdbApiException ndbApiException) {
238             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
239                     ndbApiException);
240         }
241     }
242
243     public void setFloat(Column storeColumn, Float value) {
244         try {
245             ndbOperation.setFloat(storeColumn.getName(), value);
246         } catch (NdbApiException ndbApiException) {
247             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
248                     ndbApiException);
249         }
250     }
251
252     public void setInt(Column storeColumn, Integer value) {
253         try {
254             ndbOperation.setInt(storeColumn.getName(), value);
255         } catch (NdbApiException ndbApiException) {
256             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
257                     ndbApiException);
258         }
259     }
260
261     public void setLong(Column storeColumn, long value) {
262         try {
263             ndbOperation.setLong(storeColumn.getName(), value);
264         } catch (NdbApiException ndbApiException) {
265             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
266                     ndbApiException);
267         }
268     }
269
270     public void setNull(Column storeColumn) {
271         try {
272             ndbOperation.setNull(storeColumn.getName());
273         } catch (NdbApiException ndbApiException) {
274             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
275                     ndbApiException);
276         }
277     }
278
279     public void setShort(Column storeColumn, Short value) {
280         try {
281             ndbOperation.setShort(storeColumn.getName(), value);
282         } catch (NdbApiException ndbApiException) {
283             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
284                     ndbApiException);
285         }
286     }
287
288     public void setString(Column storeColumn, String value) {
289         try {
290             ndbOperation.setString(storeColumn.getName(), value);
291         } catch (NdbApiException ndbApiException) {
292             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
293                     ndbApiException);
294         }
295     }
296
297     public void setTime(Column storeColumn, Time value) {
298         try {
299             ndbOperation.setTime(storeColumn.getName(), value);
300         } catch (NdbApiException ndbApiException) {
301             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
302                     ndbApiException);
303         }
304     }
305
306     public void setTimestamp(Column storeColumn, Timestamp value) {
307         try {
308             ndbOperation.setTimestamp(storeColumn.getName(), value);
309         } catch (NdbApiException ndbApiException) {
310             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
311                     ndbApiException);
312         }
313     }
314
315     public void setDatetime(Column storeColumn, Timestamp value) {
316         try {
317             ndbOperation.setDatetime(storeColumn.getName(), value);
318         } catch (NdbApiException ndbApiException) {
319             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
320                     ndbApiException);
321         }
322     }
323
324 }