]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
7747ff5ea853cb3b1f9adc742ae8f8ea408fbf82
[packages/trusty/mysql-wsrep-5.6.git] /
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.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;
34
35 /** This class handles retrieving parameter values from the parameterBindings
36  * associated with a PreparedStatement.
37  */
38 public class QueryExecutionContextJDBCImpl extends QueryExecutionContextImpl {
39
40     /** My message translator */
41     static final I18NHelper local = I18NHelper.getInstance(QueryExecutionContextJDBCImpl.class);
42
43     /** My logger */
44     static final Logger logger = LoggerFactoryService.getFactory().getInstance(QueryExecutionContextJDBCImpl.class);
45
46     /** The wrapped ParameterBindings */
47     ParameterBindings parameterBindings;
48
49     /** The current offset */
50     int offset = 0;
51
52     /** The number of parameters */
53     int numberOfParameters;
54
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
59      */
60     public QueryExecutionContextJDBCImpl(SessionSPI session,
61             ParameterBindings parameterBindings, int numberOfParameters) {
62         super(session);
63         this.parameterBindings = parameterBindings;
64         this.numberOfParameters = numberOfParameters;
65     }
66
67     /** Advance to the next statement (and next number of affected rows).
68      */
69     public void nextStatement() {
70         offset += numberOfParameters;
71     }
72
73     public Byte getByte(String index) {
74         try {
75             int parameterIndex = Integer.valueOf(index) + offset;
76             Byte result = parameterBindings.getByte(parameterIndex);
77             return result;
78         } catch (SQLException ex) {
79                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
80         }
81     }
82
83     public BigDecimal getBigDecimal(String index) {
84         try {
85             int parameterIndex = Integer.valueOf(index) + offset;
86             BigDecimal result = parameterBindings.getBigDecimal(parameterIndex);
87             return result;
88         } catch (SQLException ex) {
89                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
90         }
91     }
92
93     public BigInteger getBigInteger(String index) {
94         try {
95             int parameterIndex = Integer.valueOf(index) + offset;
96             BigInteger result = parameterBindings.getBigDecimal(parameterIndex).toBigInteger();
97             return result;
98         } catch (SQLException ex) {
99                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
100         }
101     }
102
103     public Boolean getBoolean(String index) {
104         try {
105             int parameterIndex = Integer.valueOf(index) + offset;
106             Boolean result = parameterBindings.getBoolean(parameterIndex);
107             return result;
108         } catch (SQLException ex) {
109                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
110         }
111     }
112
113     public byte[] getBytes(String index) {
114         try {
115             int parameterIndex = Integer.valueOf(index) + offset;
116             byte[] result = parameterBindings.getBytes(parameterIndex);
117             return result;
118         } catch (SQLException ex) {
119                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
120         }
121     }
122
123     public Double getDouble(String index) {
124         try {
125             int parameterIndex = Integer.valueOf(index) + offset;
126             Double result = parameterBindings.getDouble(parameterIndex);
127             return result;
128         } catch (SQLException ex) {
129                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
130         }
131     }
132
133     public Float getFloat(String index) {
134         try {
135             int parameterIndex = Integer.valueOf(index) + offset;
136             Float result = parameterBindings.getFloat(parameterIndex);
137             return result;
138         } catch (SQLException ex) {
139                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
140         }
141     }
142
143     public Integer getInt(String index) {
144         try {
145             int parameterIndex = Integer.valueOf(index) + offset;
146             Integer result = parameterBindings.getInt(parameterIndex);
147             return result;
148         } catch (SQLException ex) {
149                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
150         }
151     }
152
153     public Date getJavaSqlDate(String index) {
154         try {
155             int parameterIndex = Integer.valueOf(index) + offset;
156             java.sql.Date result = parameterBindings.getDate(parameterIndex);
157             return result;
158         } catch (SQLException ex) {
159                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
160         }
161     }
162
163     public Time getJavaSqlTime(String index) {
164         try {
165             int parameterIndex = Integer.valueOf(index) + offset;
166             Time result = parameterBindings.getTime(parameterIndex);
167             return result;
168         } catch (SQLException ex) {
169                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
170         }
171     }
172
173     public Timestamp getJavaSqlTimestamp(String index) {
174         try {
175             int parameterIndex = Integer.valueOf(index) + offset;
176             java.sql.Timestamp result = parameterBindings.getTimestamp(parameterIndex);
177             return result;
178         } catch (SQLException ex) {
179                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
180         }
181     }
182
183     public java.util.Date getJavaUtilDate(String index) {
184         try {
185             int parameterIndex = Integer.valueOf(index) + offset;
186             java.util.Date result = parameterBindings.getDate(parameterIndex);
187             return result;
188         } catch (SQLException ex) {
189                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
190         }
191     }
192
193     public Long getLong(String index) {
194         try {
195             int parameterIndex = Integer.valueOf(index) + offset;
196             Long result = parameterBindings.getLong(parameterIndex);
197             return result;
198         } catch (SQLException ex) {
199                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
200         }
201     }
202
203     public Short getShort(String index) {
204         try {
205             int parameterIndex = Integer.valueOf(index) + offset;
206             Short result = parameterBindings.getShort(parameterIndex);
207             return result;
208         } catch (SQLException ex) {
209                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
210         }
211     }
212
213     public String getString(String index) {
214         try {
215             int parameterIndex = Integer.valueOf(index) + offset;
216             String result = parameterBindings.getString(parameterIndex);
217             return result;
218         } catch (SQLException ex) {
219                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
220         }
221     }
222
223     public Object getObject(String index) {
224         try {
225             int parameterIndex = Integer.valueOf(index) + offset;
226             Object result = parameterBindings.getObject(parameterIndex);
227             return result;
228         } catch (SQLException ex) {
229                 throw new ClusterJUserException(local.message("ERR_Getting_Parameter_Value", offset, index), ex);
230         }
231     }
232
233 }