OmniSciDB  5ade3759e0
OmniSciPreparedStatement.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.omnisci.jdbc;
17 
18 import com.mapd.thrift.server.MapD;
19 import com.mapd.thrift.server.TColumnType;
20 import com.mapd.thrift.server.TMapDException;
21 import com.mapd.thrift.server.TStringRow;
22 import com.mapd.thrift.server.TStringValue;
23 import com.mapd.thrift.server.TTableDetails;
24 
25 import org.apache.thrift.TException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 
29 import java.io.InputStream;
30 import java.io.Reader;
31 import java.math.BigDecimal;
32 import java.net.URL;
33 import java.sql.Array;
34 import java.sql.Blob;
35 import java.sql.Clob;
36 import java.sql.Connection;
37 import java.sql.Date;
38 import java.sql.NClob;
39 import java.sql.ParameterMetaData;
40 import java.sql.PreparedStatement;
41 import java.sql.Ref;
42 import java.sql.ResultSet;
43 import java.sql.ResultSetMetaData;
44 import java.sql.RowId;
45 import java.sql.SQLException;
46 import java.sql.SQLWarning;
47 import java.sql.SQLXML;
48 import java.sql.Time;
49 import java.sql.Timestamp;
50 import java.util.ArrayList;
51 import java.util.Arrays;
52 import java.util.Calendar;
53 import java.util.List;
54 import java.util.regex.Matcher;
55 import java.util.regex.Pattern;
56 
61 class OmniSciPreparedStatement implements PreparedStatement {
62  final static Logger MAPDLOGGER =
63  LoggerFactory.getLogger(OmniSciPreparedStatement.class);
64  public SQLWarning rootWarning = null;
65 
66  private String currentSQL;
68  private int parmCount = 0;
69  private String brokenSQL[];
70  private String parmRep[];
71  private boolean parmIsNull[];
72  private int fieldsOrder[];
73  private int repCount;
74  private String session;
75  private MapD.Client client;
76  private OmniSciStatement stmt = null;
77  private boolean isInsert = false;
78  private boolean isNewBatch = true;
79  private boolean[] parmIsString = null;
80  private List<TStringRow> rows = null;
81  private static final Pattern REGEX_PATTERN = Pattern.compile("(?i)\\s+INTO\\s+(\\w+)");
82  private static final Pattern REGEX_LOF_PATTERN = Pattern.compile(
83  "(?i)\\s*insert\\s+into\\s+[\\w:\\.]+\\s*\\(([\\w:\\s:\\,:\\']+)\\)[\\w:\\s]+\\(");
84 
86  MAPDLOGGER.debug("Entered");
87  currentSQL = sql;
88  this.client = client;
89  this.session = session;
90  this.stmt = new OmniSciStatement(session, client);
91  MAPDLOGGER.debug("Prepared statement is " + currentSQL);
92  // TODO in real life this needs to check if the ? is inside quotes before we assume it
93  // a parameter
94  brokenSQL = currentSQL.split("\\?", -1);
95  parmCount = brokenSQL.length - 1;
96  parmRep = new String[parmCount];
97  parmIsNull = new boolean[parmCount];
98  parmIsString = new boolean[parmCount];
99  repCount = 0;
100  if (currentSQL.toUpperCase().contains("INSERT ")) {
101  // remove double quotes required for queries generated with " around all names like
102  // kafka connect
103  currentSQL = currentSQL.replaceAll("\"", " ");
104  MAPDLOGGER.debug("Insert Prepared statement is " + currentSQL);
105  isInsert = true;
106  Matcher matcher = REGEX_PATTERN.matcher(currentSQL);
107  while (matcher.find()) {
108  insertTableName = matcher.group(1);
109  MAPDLOGGER.debug("Table name for insert is '" + insertTableName + "'");
110  }
111  }
112  }
113 
114  private String getQuery() {
115  String qsql;
116  // put string together if required
117  if (parmCount > 0) {
118  if (repCount != parmCount) {
119  throw new UnsupportedOperationException(
120  "Incorrect number of replace parameters for prepared statement "
121  + currentSQL + " has only " + repCount + " parameters");
122  }
123  StringBuilder modQuery = new StringBuilder(currentSQL.length() * 5);
124  for (int i = 0; i < repCount; i++) {
125  modQuery.append(brokenSQL[i]);
126  if (parmIsNull[i]) {
127  modQuery.append("NULL");
128  } else {
129  if (parmIsString[i]) {
130  modQuery.append("'").append(parmRep[i]).append("'");
131  } else {
132  modQuery.append(parmRep[i]);
133  }
134  }
135  }
136  modQuery.append(brokenSQL[parmCount]);
137  qsql = modQuery.toString();
138  } else {
139  qsql = currentSQL;
140  }
141 
142  qsql = qsql.replace(" WHERE 1=0", " LIMIT 1 ");
143  MAPDLOGGER.debug("Query is now " + qsql);
144  repCount = 0; // reset the parameters
145  return qsql;
146  }
147 
148  @Override
149  public ResultSet executeQuery() throws SQLException {
150  if (isNewBatch) {
151  String qsql = getQuery();
152  MAPDLOGGER.debug("executeQuery, sql=" + qsql);
153  return stmt.executeQuery(qsql);
154  }
155  throw new UnsupportedOperationException("Not supported yet,"
156  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
157  + " class:" + new Throwable().getStackTrace()[0].getClassName()
158  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
159  }
160 
161  @Override
162  public int executeUpdate() throws SQLException {
163  MAPDLOGGER.debug("Entered");
164  executeQuery();
165  return 1;
166  }
167 
168  @Override
169  public void setNull(int parameterIndex, int sqlType) throws SQLException {
170  MAPDLOGGER.debug("Entered");
171  parmIsNull[parameterIndex - 1] = true;
172  repCount++;
173  }
174 
175  @Override
176  public void setBoolean(int parameterIndex, boolean x) throws SQLException {
177  MAPDLOGGER.debug("Entered");
178  parmRep[parameterIndex - 1] = x ? "true" : "false";
179  parmIsString[parameterIndex - 1] = false;
180  parmIsNull[parameterIndex - 1] = false;
181  repCount++;
182  }
183 
184  @Override
185  public void setByte(int parameterIndex, byte x) throws SQLException {
186  MAPDLOGGER.debug("Entered");
187  throw new UnsupportedOperationException("Not supported yet,"
188  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
189  + " class:" + new Throwable().getStackTrace()[0].getClassName()
190  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
191  }
192 
193  @Override
194  public void setShort(int parameterIndex, short x) throws SQLException {
195  MAPDLOGGER.debug("Entered");
196  parmRep[parameterIndex - 1] = Short.toString(x);
197  parmIsNull[parameterIndex - 1] = false;
198  repCount++;
199  }
200 
201  @Override
202  public void setInt(int parameterIndex, int x) throws SQLException {
203  MAPDLOGGER.debug("Entered");
204  parmRep[parameterIndex - 1] = Integer.toString(x);
205  parmIsNull[parameterIndex - 1] = false;
206  repCount++;
207  }
208 
209  @Override
210  public void setLong(int parameterIndex, long x) throws SQLException {
211  MAPDLOGGER.debug("Entered");
212  parmRep[parameterIndex - 1] = Long.toString(x);
213  parmIsNull[parameterIndex - 1] = false;
214  repCount++;
215  }
216 
217  @Override
218  public void setFloat(int parameterIndex, float x) throws SQLException {
219  MAPDLOGGER.debug("Entered");
220  parmRep[parameterIndex - 1] = Float.toString(x);
221  parmIsNull[parameterIndex - 1] = false;
222  repCount++;
223  }
224 
225  @Override
226  public void setDouble(int parameterIndex, double x) throws SQLException {
227  MAPDLOGGER.debug("Entered");
228  parmRep[parameterIndex - 1] = Double.toString(x);
229  parmIsNull[parameterIndex - 1] = false;
230  repCount++;
231  }
232 
233  @Override
234  public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
235  MAPDLOGGER.debug("Entered");
236  parmRep[parameterIndex - 1] = x.toString();
237  parmIsNull[parameterIndex - 1] = false;
238  repCount++;
239  }
240 
241  @Override
242  public void setString(int parameterIndex, String x) throws SQLException {
243  MAPDLOGGER.debug("Entered");
244  // add extra ' if there are any in string
245  x = x.replaceAll("'", "''");
246  parmRep[parameterIndex - 1] = x;
247  parmIsString[parameterIndex - 1] = true;
248  parmIsNull[parameterIndex - 1] = false;
249  repCount++;
250  }
251 
252  @Override
253  public void setBytes(int parameterIndex, byte[] x) throws SQLException {
254  MAPDLOGGER.debug("Entered");
255  throw new UnsupportedOperationException("Not supported yet,"
256  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
257  + " class:" + new Throwable().getStackTrace()[0].getClassName()
258  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
259  }
260 
261  @Override
262  public void setDate(int parameterIndex, Date x) throws SQLException {
263  MAPDLOGGER.debug("Entered");
264  parmRep[parameterIndex - 1] = x.toString();
265  parmIsString[parameterIndex - 1] = true;
266  parmIsNull[parameterIndex - 1] = false;
267  repCount++;
268  }
269 
270  @Override
271  public void setTime(int parameterIndex, Time x) throws SQLException {
272  MAPDLOGGER.debug("Entered");
273  parmRep[parameterIndex - 1] = x.toString();
274  parmIsString[parameterIndex - 1] = true;
275  parmIsNull[parameterIndex - 1] = false;
276  repCount++;
277  }
278 
279  @Override
280  public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
281  MAPDLOGGER.debug("Entered");
282  parmRep[parameterIndex - 1] =
283  x.toString(); // new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(x);
284  parmIsString[parameterIndex - 1] = true;
285  parmIsNull[parameterIndex - 1] = false;
286  repCount++;
287  }
288 
289  @Override
290  public void setAsciiStream(int parameterIndex, InputStream x, int length)
291  throws SQLException {
292  MAPDLOGGER.debug("Entered");
293  throw new UnsupportedOperationException("Not supported yet,"
294  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
295  + " class:" + new Throwable().getStackTrace()[0].getClassName()
296  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
297  }
298 
299  @Override
300  public void setUnicodeStream(int parameterIndex, InputStream x, int length)
301  throws SQLException {
302  MAPDLOGGER.debug("Entered");
303  throw new UnsupportedOperationException("Not supported yet,"
304  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
305  + " class:" + new Throwable().getStackTrace()[0].getClassName()
306  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
307  }
308 
309  @Override
310  public void setBinaryStream(int parameterIndex, InputStream x, int length)
311  throws SQLException {
312  MAPDLOGGER.debug("Entered");
313  throw new UnsupportedOperationException("Not supported yet,"
314  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
315  + " class:" + new Throwable().getStackTrace()[0].getClassName()
316  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
317  }
318 
319  @Override
320  public void clearParameters() throws SQLException {
321  MAPDLOGGER.debug("Entered");
322  // TODO MAT we will actually need to do something here one day
323  }
324 
325  @Override
326  public void setObject(int parameterIndex, Object x, int targetSqlType)
327  throws SQLException {
328  MAPDLOGGER.debug("Entered");
329  throw new UnsupportedOperationException("Not supported yet,"
330  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
331  + " class:" + new Throwable().getStackTrace()[0].getClassName()
332  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
333  }
334 
335  @Override
336  public void setObject(int parameterIndex, Object x) throws SQLException {
337  MAPDLOGGER.debug("Entered");
338  throw new UnsupportedOperationException("Not supported yet,"
339  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
340  + " class:" + new Throwable().getStackTrace()[0].getClassName()
341  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
342  }
343 
344  @Override
345  public boolean execute() throws SQLException {
346  MAPDLOGGER.debug("Entered");
347  String tQuery = getQuery();
348  return stmt.execute(tQuery);
349  }
350 
351  @Override
352  public void addBatch() throws SQLException {
353  MAPDLOGGER.debug("Entered");
354  if (isInsert) {
355  // take the values and use stream inserter to add them
356  if (isNewBatch) {
357  // check for columns names
358  Matcher matcher = REGEX_LOF_PATTERN.matcher(currentSQL);
359  if (matcher.find()) {
360  String listOfFields[] = matcher.group(1).trim().split("\\s*,+\\s*,*\\s*");
361  if (listOfFields.length != parmCount) {
362  throw new SQLException("Too many or too few values");
363  } else if (Arrays.stream(listOfFields).distinct().toArray().length
364  != listOfFields.length) {
365  throw new SQLException("Duplicated column name");
366  }
367  fieldsOrder = new int[listOfFields.length];
368  List<String> listOfColumns = new ArrayList<String>();
369  try {
370  TTableDetails tableDetails =
371  client.get_table_details(session, insertTableName);
372  for (TColumnType column : tableDetails.row_desc) {
373  listOfColumns.add(column.col_name.toLowerCase());
374  }
375  } catch (TException ex) {
376  throw new SQLException(ex.toString());
377  }
378  for (int i = 0; i < fieldsOrder.length; i++) {
379  fieldsOrder[i] = listOfColumns.indexOf(listOfFields[i].toLowerCase());
380  if (fieldsOrder[i] == -1) {
381  throw new SQLException(
382  "Column " + listOfFields[i].toLowerCase() + " does not exist");
383  }
384  }
385  }
386 
387  rows = new ArrayList(5000);
388  isNewBatch = false;
389  }
390  // add data to stream
391  TStringRow tsr = new TStringRow();
392  for (int i = 0; i < parmCount; i++) {
393  // place string in rows array
394  TStringValue tsv = new TStringValue();
395  int colID = fieldsOrder == null ? i : fieldsOrder[i];
396  if (parmIsNull[colID]) {
397  tsv.is_null = true;
398  } else {
399  tsv.str_val = this.parmRep[colID];
400  tsv.is_null = false;
401  }
402  tsr.addToCols(tsv);
403  }
404  rows.add(tsr);
405  MAPDLOGGER.debug("addBatch, rows=" + rows.size());
406  } else {
407  throw new UnsupportedOperationException("addBatch only supported for insert, line:"
408  + new Throwable().getStackTrace()[0].getLineNumber());
409  }
410  }
411 
412  @Override
413  public void setCharacterStream(int parameterIndex, Reader reader, int length)
414  throws SQLException {
415  MAPDLOGGER.debug("Entered");
416  throw new UnsupportedOperationException("Not supported yet,"
417  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
418  + " class:" + new Throwable().getStackTrace()[0].getClassName()
419  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
420  }
421 
422  @Override
423  public void setRef(int parameterIndex, Ref x) throws SQLException {
424  MAPDLOGGER.debug("Entered");
425  throw new UnsupportedOperationException("Not supported yet,"
426  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
427  + " class:" + new Throwable().getStackTrace()[0].getClassName()
428  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
429  }
430 
431  @Override
432  public void setBlob(int parameterIndex, Blob x) throws SQLException {
433  MAPDLOGGER.debug("Entered");
434  throw new UnsupportedOperationException("Not supported yet,"
435  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
436  + " class:" + new Throwable().getStackTrace()[0].getClassName()
437  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
438  }
439 
440  @Override
441  public void setClob(int parameterIndex, Clob x) throws SQLException {
442  MAPDLOGGER.debug("Entered");
443  throw new UnsupportedOperationException("Not supported yet,"
444  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
445  + " class:" + new Throwable().getStackTrace()[0].getClassName()
446  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
447  }
448 
449  @Override
450  public void setArray(int parameterIndex, Array x) throws SQLException {
451  MAPDLOGGER.debug("Entered");
452  throw new UnsupportedOperationException("Not supported yet,"
453  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
454  + " class:" + new Throwable().getStackTrace()[0].getClassName()
455  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
456  }
457 
458  @Override
459  public ResultSetMetaData getMetaData() throws SQLException {
460  MAPDLOGGER.debug("Entered");
461  throw new UnsupportedOperationException("Not supported yet,"
462  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
463  + " class:" + new Throwable().getStackTrace()[0].getClassName()
464  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
465  }
466 
467  @Override
468  public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
469  MAPDLOGGER.debug("Entered");
470  throw new UnsupportedOperationException("Not supported yet,"
471  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
472  + " class:" + new Throwable().getStackTrace()[0].getClassName()
473  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
474  }
475 
476  @Override
477  public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
478  MAPDLOGGER.debug("Entered");
479  throw new UnsupportedOperationException("Not supported yet,"
480  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
481  + " class:" + new Throwable().getStackTrace()[0].getClassName()
482  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
483  }
484 
485  @Override
486  public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
487  throws SQLException {
488  MAPDLOGGER.debug("Entered");
489  throw new UnsupportedOperationException("Not supported yet,"
490  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
491  + " class:" + new Throwable().getStackTrace()[0].getClassName()
492  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
493  }
494 
495  @Override
496  public void setNull(int parameterIndex, int sqlType, String typeName)
497  throws SQLException {
498  MAPDLOGGER.debug("Entered");
499  throw new UnsupportedOperationException("Not supported yet,"
500  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
501  + " class:" + new Throwable().getStackTrace()[0].getClassName()
502  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
503  }
504 
505  @Override
506  public void setURL(int parameterIndex, URL x) throws SQLException {
507  MAPDLOGGER.debug("Entered");
508  throw new UnsupportedOperationException("Not supported yet,"
509  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
510  + " class:" + new Throwable().getStackTrace()[0].getClassName()
511  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
512  }
513 
514  @Override
515  public ParameterMetaData getParameterMetaData() throws SQLException {
516  MAPDLOGGER.debug("Entered");
517  throw new UnsupportedOperationException("Not supported yet,"
518  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
519  + " class:" + new Throwable().getStackTrace()[0].getClassName()
520  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
521  }
522 
523  @Override
524  public void setRowId(int parameterIndex, RowId x) throws SQLException {
525  MAPDLOGGER.debug("Entered");
526  throw new UnsupportedOperationException("Not supported yet,"
527  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
528  + " class:" + new Throwable().getStackTrace()[0].getClassName()
529  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
530  }
531 
532  @Override
533  public void setNString(int parameterIndex, String value) throws SQLException {
534  MAPDLOGGER.debug("Entered");
535  throw new UnsupportedOperationException("Not supported yet,"
536  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
537  + " class:" + new Throwable().getStackTrace()[0].getClassName()
538  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
539  }
540 
541  @Override
542  public void setNCharacterStream(int parameterIndex, Reader value, long length)
543  throws SQLException {
544  MAPDLOGGER.debug("Entered");
545  throw new UnsupportedOperationException("Not supported yet,"
546  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
547  + " class:" + new Throwable().getStackTrace()[0].getClassName()
548  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
549  }
550 
551  @Override
552  public void setNClob(int parameterIndex, NClob value) throws SQLException {
553  MAPDLOGGER.debug("Entered");
554  throw new UnsupportedOperationException("Not supported yet,"
555  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
556  + " class:" + new Throwable().getStackTrace()[0].getClassName()
557  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
558  }
559 
560  @Override
561  public void setClob(int parameterIndex, Reader reader, long length)
562  throws SQLException {
563  MAPDLOGGER.debug("Entered");
564  throw new UnsupportedOperationException("Not supported yet,"
565  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
566  + " class:" + new Throwable().getStackTrace()[0].getClassName()
567  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
568  }
569 
570  @Override
571  public void setBlob(int parameterIndex, InputStream inputStream, long length)
572  throws SQLException {
573  MAPDLOGGER.debug("Entered");
574  throw new UnsupportedOperationException("Not supported yet,"
575  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
576  + " class:" + new Throwable().getStackTrace()[0].getClassName()
577  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
578  }
579 
580  @Override
581  public void setNClob(int parameterIndex, Reader reader, long length)
582  throws SQLException {
583  MAPDLOGGER.debug("Entered");
584  throw new UnsupportedOperationException("Not supported yet,"
585  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
586  + " class:" + new Throwable().getStackTrace()[0].getClassName()
587  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
588  }
589 
590  @Override
591  public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
592  MAPDLOGGER.debug("Entered");
593  throw new UnsupportedOperationException("Not supported yet,"
594  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
595  + " class:" + new Throwable().getStackTrace()[0].getClassName()
596  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
597  }
598 
599  @Override
600  public void setObject(
601  int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
602  throws SQLException {
603  MAPDLOGGER.debug("Entered");
604  throw new UnsupportedOperationException("Not supported yet,"
605  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
606  + " class:" + new Throwable().getStackTrace()[0].getClassName()
607  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
608  }
609 
610  @Override
611  public void setAsciiStream(int parameterIndex, InputStream x, long length)
612  throws SQLException {
613  MAPDLOGGER.debug("Entered");
614  throw new UnsupportedOperationException("Not supported yet,"
615  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
616  + " class:" + new Throwable().getStackTrace()[0].getClassName()
617  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
618  }
619 
620  @Override
621  public void setBinaryStream(int parameterIndex, InputStream x, long length)
622  throws SQLException {
623  MAPDLOGGER.debug("Entered");
624  throw new UnsupportedOperationException("Not supported yet,"
625  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
626  + " class:" + new Throwable().getStackTrace()[0].getClassName()
627  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
628  }
629 
630  @Override
631  public void setCharacterStream(int parameterIndex, Reader reader, long length)
632  throws SQLException {
633  MAPDLOGGER.debug("Entered");
634  throw new UnsupportedOperationException("Not supported yet,"
635  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
636  + " class:" + new Throwable().getStackTrace()[0].getClassName()
637  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
638  }
639 
640  @Override
641  public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
642  MAPDLOGGER.debug("Entered");
643  throw new UnsupportedOperationException("Not supported yet,"
644  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
645  + " class:" + new Throwable().getStackTrace()[0].getClassName()
646  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
647  }
648 
649  @Override
650  public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
651  MAPDLOGGER.debug("Entered");
652  throw new UnsupportedOperationException("Not supported yet,"
653  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
654  + " class:" + new Throwable().getStackTrace()[0].getClassName()
655  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
656  }
657 
658  @Override
659  public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
660  MAPDLOGGER.debug("Entered");
661  throw new UnsupportedOperationException("Not supported yet,"
662  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
663  + " class:" + new Throwable().getStackTrace()[0].getClassName()
664  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
665  }
666 
667  @Override
668  public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
669  MAPDLOGGER.debug("Entered");
670  throw new UnsupportedOperationException("Not supported yet,"
671  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
672  + " class:" + new Throwable().getStackTrace()[0].getClassName()
673  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
674  }
675 
676  @Override
677  public void setClob(int parameterIndex, Reader reader) throws SQLException {
678  MAPDLOGGER.debug("Entered");
679  throw new UnsupportedOperationException("Not supported yet,"
680  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
681  + " class:" + new Throwable().getStackTrace()[0].getClassName()
682  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
683  }
684 
685  @Override
686  public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
687  MAPDLOGGER.debug("Entered");
688  throw new UnsupportedOperationException("Not supported yet,"
689  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
690  + " class:" + new Throwable().getStackTrace()[0].getClassName()
691  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
692  }
693 
694  @Override
695  public void setNClob(int parameterIndex, Reader reader) throws SQLException {
696  MAPDLOGGER.debug("Entered");
697  throw new UnsupportedOperationException("Not supported yet,"
698  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
699  + " class:" + new Throwable().getStackTrace()[0].getClassName()
700  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
701  }
702 
703  @Override
704  public ResultSet executeQuery(String sql) throws SQLException {
705  MAPDLOGGER.debug("Entered");
706  throw new UnsupportedOperationException("Not supported yet,"
707  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
708  + " class:" + new Throwable().getStackTrace()[0].getClassName()
709  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
710  }
711 
712  @Override
713  public int executeUpdate(String sql) throws SQLException {
714  MAPDLOGGER.debug("Entered");
715  throw new UnsupportedOperationException("Not supported yet,"
716  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
717  + " class:" + new Throwable().getStackTrace()[0].getClassName()
718  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
719  }
720 
721  @Override
722  public void close() throws SQLException {
723  MAPDLOGGER.debug("close");
724  if (stmt != null) {
725  // TODO MAT probably more needed here
726  stmt.close();
727  stmt = null;
728  }
729  }
730 
731  @Override
732  public int getMaxFieldSize() throws SQLException {
733  MAPDLOGGER.debug("Entered");
734  throw new UnsupportedOperationException("Not supported yet,"
735  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
736  + " class:" + new Throwable().getStackTrace()[0].getClassName()
737  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
738  }
739 
740  @Override
741  public void setMaxFieldSize(int max) throws SQLException {
742  MAPDLOGGER.debug("Entered");
743  throw new UnsupportedOperationException("Not supported yet,"
744  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
745  + " class:" + new Throwable().getStackTrace()[0].getClassName()
746  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
747  }
748 
749  @Override
750  public int getMaxRows() throws SQLException {
751  MAPDLOGGER.debug("Entered");
752  return stmt.getMaxRows();
753  }
754 
755  @Override
756  public void setMaxRows(int max) throws SQLException {
757  MAPDLOGGER.debug("Entered");
758  MAPDLOGGER.debug("SetMaxRows to " + max);
759  stmt.setMaxRows(max);
760  }
761 
762  @Override
763  public void setEscapeProcessing(boolean enable) throws SQLException {
764  MAPDLOGGER.debug("Entered");
765  throw new UnsupportedOperationException("Not supported yet,"
766  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
767  + " class:" + new Throwable().getStackTrace()[0].getClassName()
768  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
769  }
770 
771  @Override
772  public int getQueryTimeout() throws SQLException {
773  MAPDLOGGER.debug("Entered");
774  return 0;
775  }
776 
777  @Override
778  public void setQueryTimeout(int seconds) throws SQLException {
779  MAPDLOGGER.debug("Entered");
780  SQLWarning warning = new SQLWarning(
781  "Query timeouts are not supported. Substituting a value of zero.");
782  if (rootWarning == null)
783  rootWarning = warning;
784  else
785  rootWarning.setNextWarning(warning);
786  }
787 
788  @Override
789  public void cancel() throws SQLException {
790  MAPDLOGGER.debug("Entered");
791  throw new UnsupportedOperationException("Not supported yet,"
792  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
793  + " class:" + new Throwable().getStackTrace()[0].getClassName()
794  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
795  }
796 
797  @Override
798  public SQLWarning getWarnings() throws SQLException {
799  MAPDLOGGER.debug("Entered");
800  return rootWarning;
801  }
802 
803  @Override
804  public void clearWarnings() throws SQLException {
805  MAPDLOGGER.debug("Entered");
806  rootWarning = null;
807  }
808 
809  @Override
810  public void setCursorName(String name) throws SQLException {
811  MAPDLOGGER.debug("Entered");
812  throw new UnsupportedOperationException("Not supported yet,"
813  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
814  + " class:" + new Throwable().getStackTrace()[0].getClassName()
815  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
816  }
817 
818  @Override
819  public boolean execute(String sql) throws SQLException {
820  MAPDLOGGER.debug("Entered");
821  throw new UnsupportedOperationException("Not supported yet,"
822  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
823  + " class:" + new Throwable().getStackTrace()[0].getClassName()
824  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
825  }
826 
827  @Override
828  public ResultSet getResultSet() throws SQLException {
829  MAPDLOGGER.debug("Entered");
830  return stmt.getResultSet();
831  }
832 
833  @Override
834  public int getUpdateCount() throws SQLException {
835  MAPDLOGGER.debug("Entered");
836  // TODO MAT this needs to change when updates are added
837  return 0;
838  }
839 
840  @Override
841  public boolean getMoreResults() throws SQLException {
842  MAPDLOGGER.debug("Entered");
843  return stmt.getMoreResults();
844  }
845 
846  @Override
847  public void setFetchDirection(int direction) throws SQLException {
848  MAPDLOGGER.debug("Entered");
849  throw new UnsupportedOperationException("Not supported yet,"
850  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
851  + " class:" + new Throwable().getStackTrace()[0].getClassName()
852  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
853  }
854 
855  @Override
856  public int getFetchDirection() throws SQLException {
857  MAPDLOGGER.debug("Entered");
858  throw new UnsupportedOperationException("Not supported yet,"
859  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
860  + " class:" + new Throwable().getStackTrace()[0].getClassName()
861  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
862  }
863 
864  @Override
865  public void setFetchSize(int rows) throws SQLException {
866  MAPDLOGGER.debug("Entered");
867  // TODO we need to chnage the model to allow smaller select chunks at the moment you
868  // get everything
869  }
870 
871  @Override
872  public int getFetchSize() throws SQLException {
873  MAPDLOGGER.debug("Entered");
874  throw new UnsupportedOperationException("Not supported yet,"
875  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
876  + " class:" + new Throwable().getStackTrace()[0].getClassName()
877  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
878  }
879 
880  @Override
881  public int getResultSetConcurrency() throws SQLException {
882  MAPDLOGGER.debug("Entered");
883  throw new UnsupportedOperationException("Not supported yet,"
884  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
885  + " class:" + new Throwable().getStackTrace()[0].getClassName()
886  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
887  }
888 
889  @Override
890  public int getResultSetType() throws SQLException {
891  MAPDLOGGER.debug("Entered");
892  throw new UnsupportedOperationException("Not supported yet,"
893  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
894  + " class:" + new Throwable().getStackTrace()[0].getClassName()
895  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
896  }
897 
898  @Override
899  public void addBatch(String sql) throws SQLException {
900  MAPDLOGGER.debug("Entered");
901  throw new UnsupportedOperationException("Not supported yet,"
902  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
903  + " class:" + new Throwable().getStackTrace()[0].getClassName()
904  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
905  }
906 
907  @Override
908  public void clearBatch() throws SQLException {
909  MAPDLOGGER.debug("Entered");
910  if (rows != null) {
911  rows.clear();
912  }
913  }
914 
915  @Override
916  public int[] executeBatch() throws SQLException {
917  int ret[] = null;
918  if (rows != null) {
919  MAPDLOGGER.debug("executeBatch, rows=" + rows.size());
920  try {
921  // send the batch
922  client.load_table(session, insertTableName, rows);
923  } catch (TMapDException ex) {
924  throw new SQLException("executeBatch failed: " + ex.getError_msg());
925  } catch (TException ex) {
926  throw new SQLException("executeBatch failed: " + ex.toString());
927  }
928  ret = new int[rows.size()];
929  for (int i = 0; i < rows.size(); i++) {
930  ret[i] = 1;
931  }
932  clearBatch();
933  }
934  return ret;
935  }
936 
937  @Override
938  public Connection getConnection() throws SQLException {
939  MAPDLOGGER.debug("Entered");
940  throw new UnsupportedOperationException("Not supported yet,"
941  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
942  + " class:" + new Throwable().getStackTrace()[0].getClassName()
943  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
944  }
945 
946  @Override
947  public boolean getMoreResults(int current) throws SQLException {
948  MAPDLOGGER.debug("Entered");
949  throw new UnsupportedOperationException("Not supported yet,"
950  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
951  + " class:" + new Throwable().getStackTrace()[0].getClassName()
952  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
953  }
954 
955  @Override
956  public ResultSet getGeneratedKeys() throws SQLException {
957  MAPDLOGGER.debug("Entered");
958  throw new UnsupportedOperationException("Not supported yet,"
959  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
960  + " class:" + new Throwable().getStackTrace()[0].getClassName()
961  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
962  }
963 
964  @Override
965  public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
966  MAPDLOGGER.debug("Entered");
967  throw new UnsupportedOperationException("Not supported yet,"
968  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
969  + " class:" + new Throwable().getStackTrace()[0].getClassName()
970  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
971  }
972 
973  @Override
974  public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
975  MAPDLOGGER.debug("Entered");
976  throw new UnsupportedOperationException("Not supported yet,"
977  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
978  + " class:" + new Throwable().getStackTrace()[0].getClassName()
979  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
980  }
981 
982  @Override
983  public int executeUpdate(String sql, String[] columnNames) throws SQLException {
984  MAPDLOGGER.debug("Entered");
985  throw new UnsupportedOperationException("Not supported yet,"
986  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
987  + " class:" + new Throwable().getStackTrace()[0].getClassName()
988  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
989  }
990 
991  @Override
992  public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
993  MAPDLOGGER.debug("Entered");
994  throw new UnsupportedOperationException("Not supported yet,"
995  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
996  + " class:" + new Throwable().getStackTrace()[0].getClassName()
997  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
998  }
999 
1000  @Override
1001  public boolean execute(String sql, int[] columnIndexes) throws SQLException {
1002  MAPDLOGGER.debug("Entered");
1003  throw new UnsupportedOperationException("Not supported yet,"
1004  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1005  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1006  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1007  }
1008 
1009  @Override
1010  public boolean execute(String sql, String[] columnNames) throws SQLException {
1011  MAPDLOGGER.debug("Entered");
1012  throw new UnsupportedOperationException("Not supported yet,"
1013  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1014  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1015  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1016  }
1017 
1018  @Override
1019  public int getResultSetHoldability() throws SQLException {
1020  MAPDLOGGER.debug("Entered");
1021  throw new UnsupportedOperationException("Not supported yet,"
1022  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1023  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1024  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1025  }
1026 
1027  @Override
1028  public boolean isClosed() throws SQLException {
1029  MAPDLOGGER.debug("Entered");
1030  throw new UnsupportedOperationException("Not supported yet,"
1031  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1032  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1033  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1034  }
1035 
1036  @Override
1037  public void setPoolable(boolean poolable) throws SQLException {
1038  MAPDLOGGER.debug("Entered");
1039  throw new UnsupportedOperationException("Not supported yet,"
1040  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1041  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1042  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1043  }
1044 
1045  @Override
1046  public boolean isPoolable() throws SQLException {
1047  MAPDLOGGER.debug("Entered");
1048  throw new UnsupportedOperationException("Not supported yet,"
1049  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1050  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1051  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1052  }
1053 
1054  @Override
1055  public void closeOnCompletion() throws SQLException {
1056  MAPDLOGGER.debug("Entered");
1057  throw new UnsupportedOperationException("Not supported yet,"
1058  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1059  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1060  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1061  }
1062 
1063  @Override
1064  public boolean isCloseOnCompletion() throws SQLException {
1065  MAPDLOGGER.debug("Entered");
1066  throw new UnsupportedOperationException("Not supported yet,"
1067  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1068  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1069  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1070  }
1071 
1072  @Override
1073  public <T> T unwrap(Class<T> iface) throws SQLException {
1074  MAPDLOGGER.debug("Entered");
1075  throw new UnsupportedOperationException("Not supported yet,"
1076  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1077  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1078  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1079  }
1080 
1081  @Override
1082  public boolean isWrapperFor(Class<?> iface) throws SQLException {
1083  MAPDLOGGER.debug("Entered");
1084  throw new UnsupportedOperationException("Not supported yet,"
1085  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
1086  + " class:" + new Throwable().getStackTrace()[0].getClassName()
1087  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
1088  }
1089 }
void setBlob(int parameterIndex, InputStream inputStream)
void setNString(int parameterIndex, String value)
void setObject(int parameterIndex, Object x, int targetSqlType)
void setClob(int parameterIndex, Reader reader)
void setNClob(int parameterIndex, NClob value)
void setNClob(int parameterIndex, Reader reader, long length)
int executeUpdate(String sql, int autoGeneratedKeys)
void setCharacterStream(int parameterIndex, Reader reader, int length)
void setAsciiStream(int parameterIndex, InputStream x)
auto sql(const std::string &sql_stmts)
boolean execute(String sql, int[] columnIndexes)
void setDouble(int parameterIndex, double x)
void setBinaryStream(int parameterIndex, InputStream x, long length)
boolean execute(String sql, int autoGeneratedKeys)
void setNClob(int parameterIndex, Reader reader)
int executeUpdate(String sql, String[] columnNames)
void setBinaryStream(int parameterIndex, InputStream x)
void setBinaryStream(int parameterIndex, InputStream x, int length)
void setBoolean(int parameterIndex, boolean x)
void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
void setCharacterStream(int parameterIndex, Reader reader, long length)
void setCharacterStream(int parameterIndex, Reader reader)
void setString(int parameterIndex, String x)
void setNull(int parameterIndex, int sqlType, String typeName)
void setNCharacterStream(int parameterIndex, Reader value, long length)
void setNull(int parameterIndex, int sqlType)
OmniSciPreparedStatement(String sql, String session, MapD.Client client)
void setBigDecimal(int parameterIndex, BigDecimal x)
void setTimestamp(int parameterIndex, Timestamp x)
void setSQLXML(int parameterIndex, SQLXML xmlObject)
void setDate(int parameterIndex, Date x, Calendar cal)
void setNCharacterStream(int parameterIndex, Reader value)
void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
int executeUpdate(String sql, int[] columnIndexes)
void setUnicodeStream(int parameterIndex, InputStream x, int length)
boolean execute(String sql, String[] columnNames)
void setAsciiStream(int parameterIndex, InputStream x, int length)
void setObject(int parameterIndex, Object x)
void setTime(int parameterIndex, Time x, Calendar cal)
void setAsciiStream(int parameterIndex, InputStream x, long length)
void setBlob(int parameterIndex, InputStream inputStream, long length)
void setClob(int parameterIndex, Reader reader, long length)