MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryExecutionContextImpl.java
1 /*
2  Copyright (c) 2010, 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.core.query;
19 
20 import com.mysql.clusterj.ClusterJFatalInternalException;
21 import com.mysql.clusterj.ClusterJUserException;
22 import com.mysql.clusterj.core.spi.QueryExecutionContext;
23 import com.mysql.clusterj.core.spi.SessionSPI;
24 import com.mysql.clusterj.core.store.ResultData;
25 import com.mysql.clusterj.core.store.ScanFilter;
26 import com.mysql.clusterj.core.util.I18NHelper;
27 import com.mysql.clusterj.core.util.Logger;
28 import com.mysql.clusterj.core.util.LoggerFactoryService;
29 import com.mysql.clusterj.query.QueryDomainType;
30 
31 import java.math.BigDecimal;
32 import java.math.BigInteger;
33 import java.sql.Date;
34 import java.sql.Time;
35 import java.sql.Timestamp;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 
46 
48  static final I18NHelper local = I18NHelper.getInstance(BetweenPredicateImpl.class);
49 
52 
53  protected Map<String, Object> boundParameters =
54  new HashMap<String, Object>();
55 
57  protected SessionSPI session;
58 
60  private List<ScanFilter> filters = new ArrayList<ScanFilter>();
61 
63  protected Map<String, Object> explain = null;
64 
69  if (session == null) {
71  local.message("ERR_Session_Must_Not_Be_Null"));
72  }
73  this.session = session;
74  }
75 
81  this.session = context.getSession();
82  boundParameters = new HashMap<String, Object>(context.boundParameters);
83  }
84 
89  public QueryExecutionContextImpl(SessionSPI session, Map<String, Object> parameterMap) {
90  this.session = session;
91  this.boundParameters = parameterMap;
92  }
93 
99  public void bindParameterValue(String parameterName, Object value) {
100  if (parameterName == null) {
101  throw new ClusterJUserException(
102  local.message("ERR_Parameter_Null"));
103  }
104  boundParameters.put(parameterName, value);
105  }
108  public Object getParameterValue(String parameterName) {
109  if (!isBound(parameterName)) {
110  throw new ClusterJUserException(
111  local.message("ERR_Parameter_Not_Bound", parameterName));
112  }
113  return boundParameters.get(parameterName);
114  }
115 
121  public boolean isBound(String parameterName) {
122  return boundParameters.containsKey(parameterName);
123  }
124 
125  public SessionSPI getSession() {
126  return session;
127  }
128 
129  public ResultData getResultData(QueryDomainType<?> queryDomainType) {
130  return ((QueryDomainTypeImpl<?>)queryDomainType).getResultData(this);
131  }
132 
136  public void addFilter(ScanFilter scanFilter) {
137  filters.add(scanFilter);
138  }
139 
142  public void deleteFilters() {
143  for (ScanFilter filter: filters) {
144  filter.delete();
145  }
146  filters.clear();
147  }
148 
149  public void setExplain(Map<String, Object> explain) {
150  this.explain = explain;
151  }
152 
153  public Map<String, Object> getExplain() {
154  return explain;
155  }
156 
157  public Byte getByte(String index) {
158  Object result = boundParameters.get(index);
159  if (result == null) {
160  return null;
161  }
162  if (result instanceof Byte) {
163  return (Byte)result;
164  } else {
165  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Byte"));
166  }
167  }
168 
169  public BigDecimal getBigDecimal(String index) {
170  Object result = boundParameters.get(index);
171  if (result == null) {
172  return null;
173  }
174  if (result instanceof BigDecimal) {
175  return (BigDecimal)result;
176  } else {
177  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "BigDecimal"));
178  }
179  }
180 
181  public BigInteger getBigInteger(String index) {
182  Object result = boundParameters.get(index);
183  if (result == null) {
184  return null;
185  }
186  if (result instanceof BigInteger) {
187  return (BigInteger)result;
188  } else {
189  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "BigInteger"));
190  }
191  }
192 
193  public Boolean getBoolean(String index) {
194  Object result = boundParameters.get(index);
195  if (result == null) {
196  return null;
197  }
198  if (result instanceof Boolean) {
199  return (Boolean)result;
200  } else {
201  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Boolean"));
202  }
203  }
204 
205  public byte[] getBytes(String index) {
206  Object result = boundParameters.get(index);
207  if (result == null) {
208  return null;
209  }
210  if (result instanceof byte[]) {
211  return (byte[])result;
212  } else {
213  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "byte[]"));
214  }
215  }
216 
217  public Double getDouble(String index) {
218  Object result = boundParameters.get(index);
219  if (result == null) {
220  return null;
221  }
222  if (result instanceof Double) {
223  return (Double)result;
224  } else {
225  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Double"));
226  }
227  }
228 
229  public Float getFloat(String index) {
230  Object result = boundParameters.get(index);
231  if (result == null) {
232  return null;
233  }
234  if (result instanceof Float) {
235  return (Float)result;
236  } else {
237  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Float"));
238  }
239  }
240 
241  public Integer getInt(String index) {
242  Object result = boundParameters.get(index);
243  if (result == null) {
244  return null;
245  }
246  if (result instanceof Integer) {
247  return (Integer)result;
248  } else {
249  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Integer"));
250  }
251  }
252 
253  public Date getJavaSqlDate(String index) {
254  Object result = boundParameters.get(index);
255  if (result == null) {
256  return null;
257  }
258  if (result instanceof java.sql.Date) {
259  return (java.sql.Date)result;
260  } else {
261  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "java.sql.Date"));
262  }
263  }
264 
265  public Time getJavaSqlTime(String index) {
266  Object result = boundParameters.get(index);
267  if (result == null) {
268  return null;
269  }
270  if (result instanceof java.sql.Time) {
271  return (java.sql.Time)result;
272  } else {
273  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "java.sql.Time"));
274  }
275  }
276 
277  public Timestamp getJavaSqlTimestamp(String index) {
278  Object result = boundParameters.get(index);
279  if (result == null) {
280  return null;
281  }
282  if (result instanceof java.sql.Timestamp) {
283  return (java.sql.Timestamp)result;
284  } else {
285  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "java.sql.Timestamp"));
286  }
287  }
288 
289  public java.util.Date getJavaUtilDate(String index) {
290  Object result = boundParameters.get(index);
291  if (result == null) {
292  return null;
293  }
294  if (result instanceof java.util.Date) {
295  return (java.util.Date)result;
296  } else {
297  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "java.util.Date"));
298  }
299  }
300 
301  public Long getLong(String index) {
302  Object result = boundParameters.get(index);
303  if (result == null) {
304  return null;
305  }
306  if (result instanceof Long) {
307  return (Long)result;
308  } else {
309  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Long"));
310  }
311  }
312 
313  public Short getShort(String index) {
314  Object result = boundParameters.get(index);
315  if (result == null) {
316  return null;
317  }
318  if (result instanceof Short) {
319  return (Short)result;
320  } else {
321  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "Short"));
322  }
323  }
324 
325  public String getString(String index) {
326  Object result = boundParameters.get(index);
327  if (result == null) {
328  return null;
329  }
330  if (result instanceof String) {
331  return (String)result;
332  } else {
333  throw new ClusterJUserException(local.message("ERR_Parameter_Wrong_Type", index, result.getClass(), "String"));
334  }
335  }
336 
337  public Object getObject(String index) {
338  return boundParameters.get(index);
339  }
340 
341 }