MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ValueHandlerImpl.java
1 /*
2  * Copyright (c) 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.jdbc;
19 
20 import java.math.BigDecimal;
21 import java.math.BigInteger;
22 import java.sql.Date;
23 import java.sql.SQLException;
24 import java.sql.Time;
25 import java.sql.Timestamp;
26 
27 import com.mysql.clusterj.ClusterJDatastoreException;
28 import com.mysql.clusterj.ClusterJFatalInternalException;
29 import com.mysql.clusterj.ColumnMetadata;
30 import com.mysql.clusterj.core.spi.DomainTypeHandler;
31 import com.mysql.clusterj.core.spi.ValueHandler;
32 import com.mysql.clusterj.core.util.I18NHelper;
33 import com.mysql.clusterj.core.util.Logger;
34 import com.mysql.clusterj.core.util.LoggerFactoryService;
35 
36 import com.mysql.jdbc.ParameterBindings;
37 
41 public class ValueHandlerImpl implements ValueHandler {
42 
44  static final I18NHelper local = I18NHelper.getInstance(ValueHandlerImpl.class);
45 
47  static final Logger logger = LoggerFactoryService.getFactory().getInstance(ValueHandlerImpl.class);
48 
49  private ParameterBindings parameterBindings;
50  private int[] fieldNumberMap;
51 
53  private int offset;
54 
55  public ValueHandlerImpl(ParameterBindings parameterBindings, int[] fieldNumberMap, int offset) {
56  this.parameterBindings = parameterBindings;
57  this.fieldNumberMap = fieldNumberMap;
58  this.offset = offset;
59  }
60 
61  public ValueHandlerImpl(ParameterBindings parameterBindings, int[] fieldNumberMap) {
62  this(parameterBindings, fieldNumberMap, 0);
63  }
64 
65  public BigDecimal getBigDecimal(int fieldNumber) {
66  try {
67  return parameterBindings.getBigDecimal(offset + fieldNumberMap[fieldNumber]);
68  } catch (SQLException e) {
69  throw new ClusterJDatastoreException(e);
70  }
71  }
72 
73  public BigInteger getBigInteger(int fieldNumber) {
74  try {
75  return parameterBindings.getBigDecimal(offset + fieldNumberMap[fieldNumber]).toBigInteger();
76  } catch (SQLException e) {
77  throw new ClusterJDatastoreException(e);
78  }
79  }
80 
81  public boolean getBoolean(int fieldNumber) {
82  try {
83  return parameterBindings.getBoolean(offset + fieldNumberMap[fieldNumber]);
84  } catch (SQLException e) {
85  throw new ClusterJDatastoreException(e);
86  }
87  }
88 
89  public boolean[] getBooleans(int fieldNumber) {
90  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
91  }
92 
93  public byte getByte(int fieldNumber) {
94  try {
95  return parameterBindings.getByte(offset + fieldNumberMap[fieldNumber]);
96  } catch (SQLException e) {
97  throw new ClusterJDatastoreException(e);
98  }
99  }
100 
101  public byte[] getBytes(int fieldNumber) {
102  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
103  }
104 
105  public double getDouble(int fieldNumber) {
106  try {
107  return parameterBindings.getDouble(offset + fieldNumberMap[fieldNumber]);
108  } catch (SQLException e) {
109  throw new ClusterJDatastoreException(e);
110  }
111  }
112 
113  public float getFloat(int fieldNumber) {
114  try {
115  return parameterBindings.getFloat(offset + fieldNumberMap[fieldNumber]);
116  } catch (SQLException e) {
117  throw new ClusterJDatastoreException(e);
118  }
119  }
120 
121  public int getInt(int fieldNumber) {
122  try {
123  return parameterBindings.getInt(offset + fieldNumberMap[fieldNumber]);
124  } catch (SQLException e) {
125  throw new ClusterJDatastoreException(e);
126  }
127  }
128 
129  public Date getJavaSqlDate(int fieldNumber) {
130  try {
131  return parameterBindings.getDate(offset + fieldNumberMap[fieldNumber]);
132  } catch (SQLException e) {
133  throw new ClusterJDatastoreException(e);
134  }
135  }
136 
137  public Time getJavaSqlTime(int fieldNumber) {
138  try {
139  return parameterBindings.getTime(offset + fieldNumberMap[fieldNumber]);
140  } catch (SQLException e) {
141  throw new ClusterJDatastoreException(e);
142  }
143  }
144 
145  public Timestamp getJavaSqlTimestamp(int fieldNumber) {
146  try {
147  return parameterBindings.getTimestamp(offset + fieldNumberMap[fieldNumber]);
148  } catch (SQLException e) {
149  throw new ClusterJDatastoreException(e);
150  }
151  }
152 
153  public java.util.Date getJavaUtilDate(int fieldNumber) {
154  try {
155  return parameterBindings.getDate(offset + fieldNumberMap[fieldNumber]);
156  } catch (SQLException e) {
157  throw new ClusterJDatastoreException(e);
158  }
159  }
160 
161  public long getLong(int fieldNumber) {
162  try {
163  return parameterBindings.getLong(offset + fieldNumberMap[fieldNumber]);
164  } catch (SQLException e) {
165  throw new ClusterJDatastoreException(e);
166  }
167  }
168 
169  public Boolean getObjectBoolean(int fieldNumber) {
170  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
171  }
172 
173  public Byte getObjectByte(int fieldNumber) {
174  try {
175  return parameterBindings.getByte(offset + fieldNumberMap[fieldNumber]);
176  } catch (SQLException e) {
177  throw new ClusterJDatastoreException(e);
178  }
179  }
180 
181  public Double getObjectDouble(int fieldNumber) {
182  try {
183  return parameterBindings.getDouble(offset + fieldNumberMap[fieldNumber]);
184  } catch (SQLException e) {
185  throw new ClusterJDatastoreException(e);
186  }
187  }
188 
189  public Float getObjectFloat(int fieldNumber) {
190  try {
191  return parameterBindings.getFloat(offset + fieldNumberMap[fieldNumber]);
192  } catch (SQLException e) {
193  throw new ClusterJDatastoreException(e);
194  }
195  }
196 
197  public Integer getObjectInt(int fieldNumber) {
198  try {
199  return parameterBindings.getInt(offset + fieldNumberMap[fieldNumber]);
200  } catch (SQLException e) {
201  throw new ClusterJDatastoreException(e);
202  }
203  }
204 
205  public Long getObjectLong(int fieldNumber) {
206  try {
207  return parameterBindings.getLong(offset + fieldNumberMap[fieldNumber]);
208  } catch (SQLException e) {
209  throw new ClusterJDatastoreException(e);
210  }
211  }
212 
213  public Short getObjectShort(int fieldNumber) {
214  try {
215  return parameterBindings.getShort(offset + fieldNumberMap[fieldNumber]);
216  } catch (SQLException e) {
217  throw new ClusterJDatastoreException(e);
218  }
219  }
220 
221  public short getShort(int fieldNumber) {
222  try {
223  return parameterBindings.getShort(offset + fieldNumberMap[fieldNumber]);
224  } catch (SQLException e) {
225  throw new ClusterJDatastoreException(e);
226  }
227  }
228 
229  public String getString(int fieldNumber) {
230  try {
231  return parameterBindings.getString(offset + fieldNumberMap[fieldNumber]);
232  } catch (SQLException e) {
233  throw new ClusterJDatastoreException(e);
234  }
235  }
236 
237  public boolean isModified(int fieldNumber) {
238  return fieldNumberMap[fieldNumber] != -1;
239  }
240 
241  public boolean isNull(int fieldNumber) {
242  try {
243  return parameterBindings.isNull(offset + fieldNumberMap[fieldNumber]);
244  } catch (SQLException e) {
245  throw new ClusterJDatastoreException(e);
246  }
247  }
248 
249  public void markModified(int fieldNumber) {
250  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
251  }
252 
253  public String pkToString(DomainTypeHandler<?> domainTypeHandler) {
254  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
255  }
256 
257  public void resetModified() {
258  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
259  }
260 
261  public void setBigDecimal(int fieldNumber, BigDecimal value) {
262  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
263  }
264 
265  public void setBigInteger(int fieldNumber, BigInteger bigIntegerExact) {
266  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
267  }
268 
269  public void setBoolean(int fieldNumber, boolean b) {
270  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
271  }
272 
273  public void setBooleans(int fieldNumber, boolean[] b) {
274  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
275  }
276 
277  public void setByte(int fieldNumber, byte value) {
278  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
279  }
280 
281  public void setBytes(int fieldNumber, byte[] value) {
282  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
283  }
284 
285  public void setDouble(int fieldNumber, double value) {
286  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
287  }
288 
289  public void setFloat(int fieldNumber, float value) {
290  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
291  }
292 
293  public void setInt(int fieldNumber, int value) {
294  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
295  }
296 
297  public void setJavaSqlDate(int fieldNumber, Date value) {
298  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
299  }
300 
301  public void setJavaSqlTime(int fieldNumber, Time value) {
302  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
303  }
304 
305  public void setJavaSqlTimestamp(int fieldNumber, Timestamp value) {
306  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
307  }
308 
309  public void setJavaUtilDate(int fieldNumber, java.util.Date value) {
310  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
311  }
312 
313  public void setLong(int fieldNumber, long value) {
314  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
315  }
316 
317  public void setObject(int fieldNumber, Object value) {
318  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
319  }
320 
321  public void setObjectBoolean(int fieldNumber, Boolean value) {
322  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
323  }
324 
325  public void setObjectByte(int fieldNumber, Byte value) {
326  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
327  }
328 
329  public void setObjectDouble(int fieldNumber, Double value) {
330  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
331  }
332 
333  public void setObjectFloat(int fieldNumber, Float value) {
334  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
335  }
336 
337  public void setObjectInt(int fieldNumber, Integer value) {
338  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
339  }
340 
341  public void setObjectLong(int fieldNumber, Long value) {
342  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
343  }
344 
345  public void setObjectShort(int fieldNumber, Short value) {
346  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
347  }
348 
349  public void setShort(int fieldNumber, short value) {
350  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
351  }
352 
353  public void setString(int fieldNumber, String value) {
354  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
355  }
356 
357  public ColumnMetadata[] columnMetadata() {
358  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
359  }
360 
361  public Boolean found() {
362  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
363  }
364 
365  public void found(Boolean found) {
366  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
367  }
368 
369  public Object get(int columnNumber) {
370  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
371  }
372 
373  public void set(int columnNumber, Object value) {
374  throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
375  }
376 
377 }