2 * Copyright (c) 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.jdbc;
20 import java.math.BigDecimal;
21 import java.math.BigInteger;
23 import java.sql.SQLException;
25 import java.sql.Timestamp;
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;
36 import com.mysql.jdbc.ParameterBindings;
38 /** This class handles retrieving parameter values from the parameterBindings
39 * associated with a PreparedStatement.
41 public class ValueHandlerImpl implements ValueHandler {
43 /** My message translator */
44 static final I18NHelper local = I18NHelper.getInstance(ValueHandlerImpl.class);
47 static final Logger logger = LoggerFactoryService.getFactory().getInstance(ValueHandlerImpl.class);
49 private ParameterBindings parameterBindings;
50 private int[] fieldNumberMap;
52 /** The offset into the parameter bindings, used for batch processing */
55 public ValueHandlerImpl(ParameterBindings parameterBindings, int[] fieldNumberMap, int offset) {
56 this.parameterBindings = parameterBindings;
57 this.fieldNumberMap = fieldNumberMap;
61 public ValueHandlerImpl(ParameterBindings parameterBindings, int[] fieldNumberMap) {
62 this(parameterBindings, fieldNumberMap, 0);
65 public BigDecimal getBigDecimal(int fieldNumber) {
67 return parameterBindings.getBigDecimal(offset + fieldNumberMap[fieldNumber]);
68 } catch (SQLException e) {
69 throw new ClusterJDatastoreException(e);
73 public BigInteger getBigInteger(int fieldNumber) {
75 return parameterBindings.getBigDecimal(offset + fieldNumberMap[fieldNumber]).toBigInteger();
76 } catch (SQLException e) {
77 throw new ClusterJDatastoreException(e);
81 public boolean getBoolean(int fieldNumber) {
83 return parameterBindings.getBoolean(offset + fieldNumberMap[fieldNumber]);
84 } catch (SQLException e) {
85 throw new ClusterJDatastoreException(e);
89 public boolean[] getBooleans(int fieldNumber) {
90 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
93 public byte getByte(int fieldNumber) {
95 return parameterBindings.getByte(offset + fieldNumberMap[fieldNumber]);
96 } catch (SQLException e) {
97 throw new ClusterJDatastoreException(e);
101 public byte[] getBytes(int fieldNumber) {
102 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
105 public double getDouble(int fieldNumber) {
107 return parameterBindings.getDouble(offset + fieldNumberMap[fieldNumber]);
108 } catch (SQLException e) {
109 throw new ClusterJDatastoreException(e);
113 public float getFloat(int fieldNumber) {
115 return parameterBindings.getFloat(offset + fieldNumberMap[fieldNumber]);
116 } catch (SQLException e) {
117 throw new ClusterJDatastoreException(e);
121 public int getInt(int fieldNumber) {
123 return parameterBindings.getInt(offset + fieldNumberMap[fieldNumber]);
124 } catch (SQLException e) {
125 throw new ClusterJDatastoreException(e);
129 public Date getJavaSqlDate(int fieldNumber) {
131 return parameterBindings.getDate(offset + fieldNumberMap[fieldNumber]);
132 } catch (SQLException e) {
133 throw new ClusterJDatastoreException(e);
137 public Time getJavaSqlTime(int fieldNumber) {
139 return parameterBindings.getTime(offset + fieldNumberMap[fieldNumber]);
140 } catch (SQLException e) {
141 throw new ClusterJDatastoreException(e);
145 public Timestamp getJavaSqlTimestamp(int fieldNumber) {
147 return parameterBindings.getTimestamp(offset + fieldNumberMap[fieldNumber]);
148 } catch (SQLException e) {
149 throw new ClusterJDatastoreException(e);
153 public java.util.Date getJavaUtilDate(int fieldNumber) {
155 return parameterBindings.getDate(offset + fieldNumberMap[fieldNumber]);
156 } catch (SQLException e) {
157 throw new ClusterJDatastoreException(e);
161 public long getLong(int fieldNumber) {
163 return parameterBindings.getLong(offset + fieldNumberMap[fieldNumber]);
164 } catch (SQLException e) {
165 throw new ClusterJDatastoreException(e);
169 public Boolean getObjectBoolean(int fieldNumber) {
170 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
173 public Byte getObjectByte(int fieldNumber) {
175 return parameterBindings.getByte(offset + fieldNumberMap[fieldNumber]);
176 } catch (SQLException e) {
177 throw new ClusterJDatastoreException(e);
181 public Double getObjectDouble(int fieldNumber) {
183 return parameterBindings.getDouble(offset + fieldNumberMap[fieldNumber]);
184 } catch (SQLException e) {
185 throw new ClusterJDatastoreException(e);
189 public Float getObjectFloat(int fieldNumber) {
191 return parameterBindings.getFloat(offset + fieldNumberMap[fieldNumber]);
192 } catch (SQLException e) {
193 throw new ClusterJDatastoreException(e);
197 public Integer getObjectInt(int fieldNumber) {
199 return parameterBindings.getInt(offset + fieldNumberMap[fieldNumber]);
200 } catch (SQLException e) {
201 throw new ClusterJDatastoreException(e);
205 public Long getObjectLong(int fieldNumber) {
207 return parameterBindings.getLong(offset + fieldNumberMap[fieldNumber]);
208 } catch (SQLException e) {
209 throw new ClusterJDatastoreException(e);
213 public Short getObjectShort(int fieldNumber) {
215 return parameterBindings.getShort(offset + fieldNumberMap[fieldNumber]);
216 } catch (SQLException e) {
217 throw new ClusterJDatastoreException(e);
221 public short getShort(int fieldNumber) {
223 return parameterBindings.getShort(offset + fieldNumberMap[fieldNumber]);
224 } catch (SQLException e) {
225 throw new ClusterJDatastoreException(e);
229 public String getString(int fieldNumber) {
231 return parameterBindings.getString(offset + fieldNumberMap[fieldNumber]);
232 } catch (SQLException e) {
233 throw new ClusterJDatastoreException(e);
237 public boolean isModified(int fieldNumber) {
238 return fieldNumberMap[fieldNumber] != -1;
241 public boolean isNull(int fieldNumber) {
243 return parameterBindings.isNull(offset + fieldNumberMap[fieldNumber]);
244 } catch (SQLException e) {
245 throw new ClusterJDatastoreException(e);
249 public void markModified(int fieldNumber) {
250 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
253 public String pkToString(DomainTypeHandler<?> domainTypeHandler) {
254 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
257 public void resetModified() {
258 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
261 public void setBigDecimal(int fieldNumber, BigDecimal value) {
262 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
265 public void setBigInteger(int fieldNumber, BigInteger bigIntegerExact) {
266 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
269 public void setBoolean(int fieldNumber, boolean b) {
270 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
273 public void setBooleans(int fieldNumber, boolean[] b) {
274 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
277 public void setByte(int fieldNumber, byte value) {
278 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
281 public void setBytes(int fieldNumber, byte[] value) {
282 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
285 public void setDouble(int fieldNumber, double value) {
286 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
289 public void setFloat(int fieldNumber, float value) {
290 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
293 public void setInt(int fieldNumber, int value) {
294 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
297 public void setJavaSqlDate(int fieldNumber, Date value) {
298 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
301 public void setJavaSqlTime(int fieldNumber, Time value) {
302 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
305 public void setJavaSqlTimestamp(int fieldNumber, Timestamp value) {
306 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
309 public void setJavaUtilDate(int fieldNumber, java.util.Date value) {
310 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
313 public void setLong(int fieldNumber, long value) {
314 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
317 public void setObject(int fieldNumber, Object value) {
318 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
321 public void setObjectBoolean(int fieldNumber, Boolean value) {
322 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
325 public void setObjectByte(int fieldNumber, Byte value) {
326 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
329 public void setObjectDouble(int fieldNumber, Double value) {
330 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
333 public void setObjectFloat(int fieldNumber, Float value) {
334 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
337 public void setObjectInt(int fieldNumber, Integer value) {
338 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
341 public void setObjectLong(int fieldNumber, Long value) {
342 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
345 public void setObjectShort(int fieldNumber, Short value) {
346 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
349 public void setShort(int fieldNumber, short value) {
350 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
353 public void setString(int fieldNumber, String value) {
354 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
357 public ColumnMetadata[] columnMetadata() {
358 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
361 public Boolean found() {
362 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
365 public void found(Boolean found) {
366 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
369 public Object get(int columnNumber) {
370 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));
373 public void set(int columnNumber, Object value) {
374 throw new ClusterJFatalInternalException(local.message("ERR_Should_Not_Occur"));