Example #1
0
 /**
  * Executes an arbitrary statement. If another result set exists for this statement, this will be
  * closed (even if this statement fails).
  *
  * <p>If the statement is a create or drop and does not throw an exception, the current
  * transaction (if any) is committed after executing the statement. If auto commit is on, and the
  * statement is not a select, this statement will be committed.
  *
  * @param sql the SQL statement to execute
  * @return true if a result set is available, false if not
  */
 public boolean execute(String sql) throws SQLException {
   try {
     int id = getNextId(TraceObject.RESULT_SET);
     if (isDebugEnabled()) {
       debugCodeCall("execute", sql);
     }
     checkClosedForWrite();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     boolean returnsResultSet;
     synchronized (session) {
       setExecutingStatement(command);
       try {
         if (command.isQuery()) {
           returnsResultSet = true;
           boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
           boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
           ResultInterface result = command.executeQuery(maxRows, scrollable);
           resultSet =
               new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
         } else {
           returnsResultSet = false;
           updateCount = command.executeUpdate();
         }
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return returnsResultSet;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
Example #2
0
 /**
  * Executes a query (select statement) and returns the result set. If another result set exists
  * for this statement, this will be closed (even if this statement fails).
  *
  * @param sql the SQL statement to execute
  * @return the result set
  */
 public ResultSet executeQuery(String sql) throws SQLException {
   try {
     int id = getNextId(TraceObject.RESULT_SET);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
     }
     checkClosed();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     synchronized (session) {
       CommandInterface command = conn.prepareCommand(sql, fetchSize);
       ResultInterface result;
       boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
       boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
       setExecutingStatement(command);
       try {
         result = command.executeQuery(maxRows, scrollable);
       } finally {
         setExecutingStatement(null);
       }
       command.close();
       resultSet =
           new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
     }
     return resultSet;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
Example #3
0
 /**
  * Gets the current catalog name.
  *
  * @return the catalog name
  * @throws SQLException if the connection is closed
  */
 public String getCatalog() throws SQLException {
   try {
     debugCodeCall("getCatalog");
     checkClosed();
     if (catalog == null) {
       CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
       ResultInterface result = cat.executeQuery(0, false);
       result.next();
       catalog = result.currentRow()[0].getString();
       cat.close();
     }
     return catalog;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
Example #4
0
 /**
  * Read the serializer name from the persistent database settings.
  *
  * @return the serializer
  */
 private String readSerializationSettings() {
   String javaObjectSerializerFQN = null;
   CommandInterface ci =
       prepareCommand(
           "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS "
               + " WHERE NAME='JAVA_OBJECT_SERIALIZER'",
           Integer.MAX_VALUE);
   try {
     ResultInterface result = ci.executeQuery(0, false);
     if (result.next()) {
       Value[] row = result.currentRow();
       javaObjectSerializerFQN = row[0].getString();
     }
   } finally {
     ci.close();
   }
   return javaObjectSerializerFQN;
 }
 private int executeUpdateInternal(String sql) throws SQLException {
   checkClosedForWrite();
   try {
     closeOldResultSet();
     sql = JdbcConnection.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     synchronized (session) {
       setExecutingStatement(command);
       try {
         updateCount = command.executeUpdate();
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return updateCount;
   } finally {
     afterWriting();
   }
 }
Example #6
0
 /**
  * Executes a statement (insert, update, delete, create, drop) and returns the update count. If
  * another result set exists for this statement, this will be closed (even if this statement
  * fails).
  *
  * <p>If the statement is a create or drop and does not throw an exception, the current
  * transaction (if any) is committed after executing the statement. If auto commit is on, this
  * statement will be committed.
  *
  * @param sql the SQL statement
  * @return the update count (number of row affected by an insert, update or delete, or 0 if no
  *     rows or the statement was a create, drop, commit or rollback)
  * @throws SQLException if a database error occurred or a select statement was executed
  */
 public int executeUpdate(String sql) throws SQLException {
   try {
     debugCodeCall("executeUpdate", sql);
     checkClosedForWrite();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     synchronized (session) {
       setExecutingStatement(command);
       try {
         updateCount = command.executeUpdate();
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return updateCount;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
Example #7
0
 private CommandInterface closeAndSetNull(CommandInterface command) {
   if (command != null) {
     command.close();
   }
   return null;
 }