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.ClusterJUserException;
28 import com.mysql.clusterj.core.query.QueryExecutionContextImpl;
29 import com.mysql.clusterj.core.spi.SessionSPI;
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 import com.mysql.jdbc.ParameterBindings;
35 /** This class handles retrieving parameter values from the parameterBindings
36 * associated with a PreparedStatement.
38 public class QueryExecutionContextJDBCImpl extends QueryExecutionContextImpl {
40 /** My message translator */
41 static final I18NHelper local = I18NHelper.getInstance(QueryExecutionContextJDBCImpl.class);
44 static final Logger logger = LoggerFactoryService.getFactory().getInstance(QueryExecutionContextJDBCImpl.class);
46 /** The wrapped ParameterBindings */
47 ParameterBindings parameterBindings;
49 /** The current offset */
52 /** The number of parameters */
53 int numberOfParameters;
55 /** Create a new execution context with parameter bindings.
56 * @param parameterBindings the jdbc parameter bindings for the statement
57 * @param session the session for this context
58 * @param numberOfParameters the number of parameters per statement
60 public QueryExecutionContextJDBCImpl(SessionSPI session,
61 ParameterBindings parameterBindings, int numberOfParameters) {
63 this.parameterBindings = parameterBindings;
64 this.numberOfParameters = numberOfParameters;
67 /** Advance to the next statement (and next number of affected rows).
69 public void nextStatement() {
70 offset += numberOfParameters;
73 public Byte getByte(String index) {
75 int parameterIndex = Integer.valueOf(index) + offset;
76 Byte result = parameterBindings.getByte(parameterIndex);
78 } catch (SQLException ex) {
79 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
83 public BigDecimal getBigDecimal(String index) {
85 int parameterIndex = Integer.valueOf(index) + offset;
86 BigDecimal result = parameterBindings.getBigDecimal(parameterIndex);
88 } catch (SQLException ex) {
89 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
93 public BigInteger getBigInteger(String index) {
95 int parameterIndex = Integer.valueOf(index) + offset;
96 BigInteger result = parameterBindings.getBigDecimal(parameterIndex).toBigInteger();
98 } catch (SQLException ex) {
99 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
103 public Boolean getBoolean(String index) {
105 int parameterIndex = Integer.valueOf(index) + offset;
106 Boolean result = parameterBindings.getBoolean(parameterIndex);
108 } catch (SQLException ex) {
109 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
113 public byte[] getBytes(String index) {
115 int parameterIndex = Integer.valueOf(index) + offset;
116 byte[] result = parameterBindings.getBytes(parameterIndex);
118 } catch (SQLException ex) {
119 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
123 public Double getDouble(String index) {
125 int parameterIndex = Integer.valueOf(index) + offset;
126 Double result = parameterBindings.getDouble(parameterIndex);
128 } catch (SQLException ex) {
129 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
133 public Float getFloat(String index) {
135 int parameterIndex = Integer.valueOf(index) + offset;
136 Float result = parameterBindings.getFloat(parameterIndex);
138 } catch (SQLException ex) {
139 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
143 public Integer getInt(String index) {
145 int parameterIndex = Integer.valueOf(index) + offset;
146 Integer result = parameterBindings.getInt(parameterIndex);
148 } catch (SQLException ex) {
149 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
153 public Date getJavaSqlDate(String index) {
155 int parameterIndex = Integer.valueOf(index) + offset;
156 java.sql.Date result = parameterBindings.getDate(parameterIndex);
158 } catch (SQLException ex) {
159 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
163 public Time getJavaSqlTime(String index) {
165 int parameterIndex = Integer.valueOf(index) + offset;
166 Time result = parameterBindings.getTime(parameterIndex);
168 } catch (SQLException ex) {
169 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
173 public Timestamp getJavaSqlTimestamp(String index) {
175 int parameterIndex = Integer.valueOf(index) + offset;
176 java.sql.Timestamp result = parameterBindings.getTimestamp(parameterIndex);
178 } catch (SQLException ex) {
179 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
183 public java.util.Date getJavaUtilDate(String index) {
185 int parameterIndex = Integer.valueOf(index) + offset;
186 java.util.Date result = parameterBindings.getDate(parameterIndex);
188 } catch (SQLException ex) {
189 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
193 public Long getLong(String index) {
195 int parameterIndex = Integer.valueOf(index) + offset;
196 Long result = parameterBindings.getLong(parameterIndex);
198 } catch (SQLException ex) {
199 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
203 public Short getShort(String index) {
205 int parameterIndex = Integer.valueOf(index) + offset;
206 Short result = parameterBindings.getShort(parameterIndex);
208 } catch (SQLException ex) {
209 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
213 public String getString(String index) {
215 int parameterIndex = Integer.valueOf(index) + offset;
216 String result = parameterBindings.getString(parameterIndex);
218 } catch (SQLException ex) {
219 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
223 public Object getObject(String index) {
225 int parameterIndex = Integer.valueOf(index) + offset;
226 Object result = parameterBindings.getObject(parameterIndex);
228 } catch (SQLException ex) {
229 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);