16 package com.omnisci.jdbc;
18 import com.omnisci.thrift.server.OmniSci;
19 import com.omnisci.thrift.server.TOmniSciException;
20 import com.omnisci.thrift.server.TQueryResult;
22 import org.apache.thrift.TException;
23 import org.apache.thrift.transport.TTransportException;
24 import org.slf4j.LoggerFactory;
26 import java.sql.Connection;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.sql.SQLWarning;
30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern;
38 final static org.slf4j.Logger
logger = LoggerFactory.getLogger(OmniSciStatement.class);
53 client = connection.client;
58 Pattern.compile(
"select top\\s+([0-9]+)\\s+", Pattern.CASE_INSENSITIVE);
68 String[] tokens = sql.toLowerCase().
split(
" ", 3);
69 if (tokens[0].equals(
"select")) {
70 if (sql.toLowerCase().contains(
"limit")) {
76 Matcher matcher = top_pattern.matcher(sql);
80 maxRows = Integer.parseInt(matcher.group(1));
81 sql = top_pattern.matcher(sql).replaceAll(
"select ");
84 sql = sql +
" LIMIT " +
maxRows;
85 logger.debug(
"Added LIMIT of " +
maxRows);
90 logger.debug(
"Before OmniSciEscapeParser [" + sql +
"]");
93 String afterEscapeParseSQL = OmniSciEscapeParser.parse(sql);
95 logger.debug(
"After OmniSciEscapeParser [" + afterSimpleParse +
"]");
97 sqlResult = client.sql_execute(
session, afterSimpleParse +
";",
true, null, -1, -1);
98 }
catch (TOmniSciException ex) {
99 throw new SQLException(
101 }
catch (TException ex) {
102 throw new SQLException(
111 public void cancel() throws SQLException {
115 alternate_connection = connection.getAlternateConnection();
118 }
catch (TOmniSciException ttE) {
119 throw new SQLException(
"Thrift transport connection failed - "
122 }
catch (TException tE) {
123 throw new SQLException(
128 alternate_connection.closeConnection();
137 if (sql.trim().substring(0, 6).compareToIgnoreCase(
"CREATE") == 0) {
138 sql = sql.replace(
'"',
' ');
141 }
catch (TOmniSciException ex) {
142 throw new SQLException(
"Query failed : sql was '" + sql +
"' "
145 }
catch (TException ex) {
146 throw new SQLException(
156 public void close() throws SQLException {
165 throw new UnsupportedOperationException(
"Not supported yet,"
166 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
167 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
168 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
173 throw new UnsupportedOperationException(
"Not supported yet,"
174 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
175 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
176 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
191 throws SQLException {
202 throws SQLException {
203 return (
int) sqlResult.execution_time_ms;
208 throws SQLException {
209 SQLWarning warning =
new SQLWarning(
210 "Query timeouts are not supported. Substituting a value of zero.");
214 rootWarning.setNextWarning(warning);
230 throw new UnsupportedOperationException(
"Not supported yet,"
231 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
232 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
233 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
237 public boolean execute(String sql)
throws SQLException {
269 throws SQLException {
270 throw new UnsupportedOperationException(
"Not supported yet,"
271 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
272 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
273 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
278 return ResultSet.FETCH_FORWARD;
283 SQLWarning warning =
new SQLWarning(
284 "Query FetchSize are not supported. Substituting a value of zero.");
288 rootWarning.setNextWarning(warning);
294 throw new UnsupportedOperationException(
"Not supported yet,"
295 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
296 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
297 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
302 throw new UnsupportedOperationException(
"Not supported yet,"
303 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
304 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
305 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
310 throw new UnsupportedOperationException(
"Not supported yet,"
311 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
312 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
313 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
317 public void addBatch(String sql)
throws SQLException {
318 throw new UnsupportedOperationException(
"Not supported yet,"
319 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
320 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
321 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
326 throw new UnsupportedOperationException(
"Not supported yet,"
327 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
328 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
329 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
334 throw new UnsupportedOperationException(
"Not supported yet,"
335 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
336 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
337 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
347 throws SQLException {
348 throw new UnsupportedOperationException(
"Not supported yet,"
349 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
350 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
351 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
356 throw new UnsupportedOperationException(
"Not supported yet,"
357 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
358 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
359 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
364 throws SQLException {
365 throw new UnsupportedOperationException(
"Not supported yet,"
366 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
367 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
368 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
373 throws SQLException {
374 throw new UnsupportedOperationException(
"Not supported yet,"
375 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
376 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
377 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
382 throws SQLException {
383 throw new UnsupportedOperationException(
"Not supported yet,"
384 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
385 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
386 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
390 public boolean execute(String sql,
int autoGeneratedKeys)
391 throws SQLException {
392 throw new UnsupportedOperationException(
"Not supported yet,"
393 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
394 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
395 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
399 public boolean execute(String sql,
int[] columnIndexes)
400 throws SQLException {
401 throw new UnsupportedOperationException(
"Not supported yet,"
402 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
403 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
404 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
408 public boolean execute(String sql, String[] columnNames)
409 throws SQLException {
410 throw new UnsupportedOperationException(
"Not supported yet,"
411 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
412 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
413 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
418 throw new UnsupportedOperationException(
"Not supported yet,"
419 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
420 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
421 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
431 throws SQLException {
432 throw new UnsupportedOperationException(
"Not supported yet,"
433 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
434 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
435 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
440 throw new UnsupportedOperationException(
"Not supported yet,"
441 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
442 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
443 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
448 throw new UnsupportedOperationException(
"Not supported yet,"
449 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
450 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
451 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
456 throw new UnsupportedOperationException(
"Not supported yet,"
457 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
458 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
459 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
463 public <T>
T unwrap(Class<T> iface)
throws SQLException {
464 throw new UnsupportedOperationException(
"Not supported yet,"
465 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
466 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
467 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
472 throws SQLException {
473 throw new UnsupportedOperationException(
"Not supported yet,"
474 +
" line:" +
new Throwable().getStackTrace()[0].getLineNumber()
475 +
" class:" +
new Throwable().getStackTrace()[0].getClassName()
476 +
" method:" +
new Throwable().getStackTrace()[0].getMethodName());
479 private static final Pattern
QUARTER = Pattern.compile(
480 "\\sQUARTER\\(([^\\{]*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
481 private static final Pattern
DAYOFYEAR = Pattern.compile(
482 "\\sDAYOFYEAR\\(([^\\{]*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
483 private static final Pattern
DAYOFWEEK = Pattern.compile(
484 "\\sDAYOFWEEK\\(([^\\{]*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
485 private static final Pattern
WEEK = Pattern.compile(
486 "\\sWEEK\\(([^\\{]*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
506 Pattern.compile(
"(?<![\\w.])CURRENT_DATE(?:\\(\\))?(?![\\w.])",
507 Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
516 sql = QUARTER.matcher(sql).replaceAll(
" EXTRACT(QUARTER FROM $1");
517 }
while (!sql.equals(start));
521 sql = DAYOFYEAR.matcher(sql).replaceAll(
" EXTRACT(DOY FROM $1");
522 }
while (!sql.equals(start));
526 sql = DAYOFWEEK.matcher(sql).replaceAll(
" EXTRACT(ISODOW FROM $1");
527 }
while (!sql.equals(start));
531 sql = WEEK.matcher(sql).replaceAll(
" EXTRACT(WEEK FROM $1");
532 }
while (!sql.equals(start));
536 sql = CURRENTDATE.matcher(sql).replaceAll(
" cast(now() as date) ");
537 }
while (!sql.equals(start));
544 throw new SQLException(
"Statement is closed.");
int getResultSetHoldability()
static String simplisticDateTransform(String sql)
static Pattern top_pattern
static final Pattern DAYOFYEAR
Connection getConnection()
static final Pattern QUARTER
ResultSet getGeneratedKeys()
static String getExceptionDetail(Exception ex)
int getResultSetConcurrency()
void setMaxFieldSize(int max)
OmniSciConnection connection
boolean isWrapperFor(Class<?> iface)
public< T > T unwrap(Class< T > iface)
void addBatch(String sql)
void setFetchDirection(int direction)
OmniSciStatement(String tsession, OmniSciConnection tconnection)
static final Pattern CURRENTDATE
boolean execute(String sql)
static final org.slf4j.Logger logger
ResultSet executeQuery(String sql)
int getQueryInternalExecuteTime()
int executeUpdate(String sql, String[] columnNames)
boolean execute(String sql, int[] columnIndexes)
void setCursorName(String name)
void setFetchSize(int rows)
static final Pattern WEEK
void setQueryTimeout(int seconds)
int executeUpdate(String sql, int[] columnIndexes)
boolean execute(String sql, int autoGeneratedKeys)
static final Pattern DAYOFWEEK
void setEscapeProcessing(boolean enable)
void setPoolable(boolean poolable)
boolean execute(String sql, String[] columnNames)
boolean getMoreResults(int current)
int executeUpdate(String sql)
boolean isCloseOnCompletion()
int executeUpdate(String sql, int autoGeneratedKeys)