示例#1
0
 /**
  * Returns the current transaction isolation level.
  *
  * @return the isolation level.
  * @throws SQLException if the connection is closed
  */
 public int getTransactionIsolation() throws SQLException {
   try {
     debugCodeCall("getTransactionIsolation");
     checkClosed();
     getLockMode = prepareCommand("CALL LOCK_MODE()", getLockMode);
     ResultInterface result = getLockMode.executeQuery(0, false);
     result.next();
     int lockMode = result.currentRow()[0].getInt();
     result.close();
     int transactionIsolationLevel;
     switch (lockMode) {
       case Constants.LOCK_MODE_OFF:
         transactionIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
         break;
       case Constants.LOCK_MODE_READ_COMMITTED:
         transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
         break;
       case Constants.LOCK_MODE_TABLE:
       case Constants.LOCK_MODE_TABLE_GC:
         transactionIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
         break;
       default:
         throw DbException.throwInternalError("lockMode:" + lockMode);
     }
     return transactionIsolationLevel;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#2
0
 /**
  * Changes the current transaction isolation level. Calling this method will commit an open
  * transaction, even if the new level is the same as the old one, except if the level is not
  * supported. Internally, this method calls SET LOCK_MODE. The following isolation levels are
  * supported:
  *
  * <ul>
  *   <li>Connection.TRANSACTION_READ_UNCOMMITTED = SET LOCK_MODE 0: no locking (should only be
  *       used for testing).
  *   <li>Connection.TRANSACTION_SERIALIZABLE = SET LOCK_MODE 1: table level locking.
  *   <li>Connection.TRANSACTION_READ_COMMITTED = SET LOCK_MODE 3: table level locking, but read
  *       locks are released immediately (default).
  * </ul>
  *
  * This setting is not persistent. Please note that using TRANSACTION_READ_UNCOMMITTED while at
  * the same time using multiple connections may result in inconsistent transactions.
  *
  * @param level the new transaction isolation level: Connection.TRANSACTION_READ_UNCOMMITTED,
  *     Connection.TRANSACTION_READ_COMMITTED, or Connection.TRANSACTION_SERIALIZABLE
  * @throws SQLException if the connection is closed or the isolation level is not supported
  */
 public void setTransactionIsolation(int level) throws SQLException {
   try {
     debugCodeCall("setTransactionIsolation", level);
     checkClosed();
     int lockMode;
     switch (level) {
       case Connection.TRANSACTION_READ_UNCOMMITTED:
         lockMode = Constants.LOCK_MODE_OFF;
         break;
       case Connection.TRANSACTION_READ_COMMITTED:
         lockMode = Constants.LOCK_MODE_READ_COMMITTED;
         break;
       case Connection.TRANSACTION_REPEATABLE_READ:
       case Connection.TRANSACTION_SERIALIZABLE:
         lockMode = Constants.LOCK_MODE_TABLE;
         break;
       default:
         throw DbException.getInvalidValueException("" + level, "level");
     }
     commit();
     setLockMode = prepareCommand("SET LOCK_MODE ?", setLockMode);
     setLockMode.getParameters().get(0).setValue(ValueInt.get(lockMode), false);
     setLockMode.executeUpdate();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#3
0
 /**
  * Creates a prepared statement with the specified result set type, concurrency, and holdability.
  *
  * @return the prepared statement
  * @throws SQLException if the connection is closed or the result set type, concurrency, or
  *     holdability are not supported
  */
 public PreparedStatement prepareStatement(
     String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
     throws SQLException {
   try {
     int id = getNextId(TraceObject.PREPARED_STATEMENT);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "PreparedStatement",
           TraceObject.PREPARED_STATEMENT,
           id,
           "prepareStatement("
               + quote(sql)
               + ", "
               + resultSetType
               + ", "
               + resultSetConcurrency
               + ", "
               + resultSetHoldability
               + ")");
     }
     checkTypeConcurrency(resultSetType, resultSetConcurrency);
     checkHoldability(resultSetHoldability);
     checkClosed();
     sql = translateSQL(sql);
     return new JdbcPreparedStatement(this, sql, id, resultSetType, resultSetConcurrency, false);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#4
0
 /**
  * Creates a statement with the specified result set type, concurrency, and holdability.
  *
  * @return the statement
  * @throws SQLException if the connection is closed or the result set type, concurrency, or
  *     holdability are not supported
  */
 public Statement createStatement(
     int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
   try {
     int id = getNextId(TraceObject.STATEMENT);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "Statement",
           TraceObject.STATEMENT,
           id,
           "createStatement("
               + resultSetType
               + ", "
               + resultSetConcurrency
               + ", "
               + resultSetHoldability
               + ")");
     }
     checkTypeConcurrency(resultSetType, resultSetConcurrency);
     checkHoldability(resultSetHoldability);
     checkClosed();
     return new JdbcStatement(this, id, resultSetType, resultSetConcurrency, false);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#5
0
 /**
  * Set the default catalog name. This call is ignored.
  *
  * @throws SQLException if the connection is closed
  */
 public void setCatalog(String catalog) throws SQLException {
   try {
     debugCodeCall("setCatalog", catalog);
     checkClosed();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#6
0
 /** Clears all warnings. */
 public void clearWarnings() throws SQLException {
   try {
     debugCodeCall("clearWarnings");
     checkClosed();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#7
0
 /**
  * Translates a SQL statement into the database grammar.
  *
  * @return the translated statement
  * @throws SQLException if the connection is closed
  */
 public String nativeSQL(String sql) throws SQLException {
   try {
     debugCodeCall("nativeSQL", sql);
     checkClosed();
     return translateSQL(sql);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#8
0
 /**
  * Gets the current setting for auto commit.
  *
  * @return true for on, false for off
  * @throws SQLException if the connection is closed
  */
 public synchronized boolean getAutoCommit() throws SQLException {
   try {
     checkClosed();
     debugCodeCall("getAutoCommit");
     return getInternalAutoCommit();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#9
0
 /**
  * Returns the current result set holdability.
  *
  * @return the holdability
  * @throws SQLException if the connection is closed
  */
 public int getHoldability() throws SQLException {
   try {
     debugCodeCall("getHoldability");
     checkClosed();
     return holdability;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#10
0
 /**
  * Gets the type map.
  *
  * @return null
  * @throws SQLException if the connection is closed
  */
 public Map<String, Class<?>> getTypeMap() throws SQLException {
   try {
     debugCodeCall("getTypeMap");
     checkClosed();
     return null;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#11
0
 // ## Java 1.4 begin ##
 public void releaseSavepoint(Savepoint savepoint) throws SQLException {
   try {
     debugCode("releaseSavepoint(savepoint);");
     checkClosed();
     convertSavepoint(savepoint).release();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#12
0
 /**
  * Gets the first warning reported by calls on this object.
  *
  * @return null
  */
 public SQLWarning getWarnings() throws SQLException {
   try {
     debugCodeCall("getWarnings");
     checkClosed();
     return null;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#13
0
 /**
  * Changes the current result set holdability.
  *
  * @param holdability ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT;
  * @throws SQLException if the connection is closed or the holdability is not supported
  */
 public void setHoldability(int holdability) throws SQLException {
   try {
     debugCodeCall("setHoldability", holdability);
     checkClosed();
     checkHoldability(holdability);
     this.holdability = holdability;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#14
0
 /**
  * According to the JDBC specs, this setting is only a hint to the database to enable
  * optimizations - it does not cause writes to be prohibited.
  *
  * @throws SQLException if the connection is closed
  */
 public void setReadOnly(boolean readOnly) throws SQLException {
   try {
     if (isDebugEnabled()) {
       debugCode("setReadOnly(" + readOnly + ");");
     }
     checkClosed();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#15
0
 /** INTERNAL */
 public void setQueryTimeout(int seconds) throws SQLException {
   try {
     debugCodeCall("setQueryTimeout", seconds);
     checkClosed();
     setQueryTimeout = prepareCommand("SET QUERY_TIMEOUT ?", setQueryTimeout);
     setQueryTimeout.getParameters().get(0).setValue(ValueInt.get(seconds * 1000), false);
     setQueryTimeout.executeUpdate();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#16
0
 /**
  * Gets the database meta data for this database.
  *
  * @return the database meta data
  * @throws SQLException if the connection is closed
  */
 public DatabaseMetaData getMetaData() throws SQLException {
   try {
     int id = getNextId(TraceObject.DATABASE_META_DATA);
     if (isDebugEnabled()) {
       debugCodeAssign("DatabaseMetaData", TraceObject.DATABASE_META_DATA, id, "getMetaData()");
     }
     checkClosed();
     return new JdbcDatabaseMetaData(this, trace, id);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#17
0
 /**
  * Returns true if the database is read-only.
  *
  * @return if the database is read-only
  * @throws SQLException if the connection is closed
  */
 public boolean isReadOnly() throws SQLException {
   try {
     debugCodeCall("isReadOnly");
     checkClosed();
     getReadOnly = prepareCommand("CALL READONLY()", getReadOnly);
     ResultInterface result = getReadOnly.executeQuery(0, false);
     result.next();
     boolean readOnly = result.currentRow()[0].getBoolean().booleanValue();
     return readOnly;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#18
0
 /**
  * INTERNAL. Check if the statement is closed.
  *
  * @param write if the next operation is possibly writing
  * @return true if a reconnect was required
  * @throws SQLException if it is closed
  */
 protected boolean checkClosed(boolean write) throws SQLException {
   if (conn == null) {
     throw Message.getSQLException(ErrorCode.OBJECT_CLOSED);
   }
   conn.checkClosed(write);
   SessionInterface s = conn.getSession();
   if (s != session) {
     session = s;
     setTrace(session.getTrace());
     return true;
   }
   return false;
 }
示例#19
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);
   }
 }
示例#20
0
 // ## Java 1.4 begin ##
 public Savepoint setSavepoint(String name) throws SQLException {
   try {
     int id = getNextId(TraceObject.SAVEPOINT);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
     }
     checkClosed();
     CommandInterface set =
         prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(name, 0), Integer.MAX_VALUE);
     set.executeUpdate();
     JdbcSavepoint savepoint = new JdbcSavepoint(this, 0, name, trace, id);
     return savepoint;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#21
0
 /**
  * Creates a new statement.
  *
  * @return the new statement
  * @throws SQLException if the connection is closed
  */
 public Statement createStatement() throws SQLException {
   try {
     int id = getNextId(TraceObject.STATEMENT);
     if (isDebugEnabled()) {
       debugCodeAssign("Statement", TraceObject.STATEMENT, id, "createStatement()");
     }
     checkClosed();
     return new JdbcStatement(
         this,
         id,
         ResultSet.TYPE_FORWARD_ONLY,
         SysProperties.DEFAULT_RESULT_SET_CONCURRENCY,
         false);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#22
0
 /**
  * Switches auto commit on or off. Calling this function does not commit the current transaction.
  *
  * @param autoCommit true for auto commit on, false for off
  * @throws SQLException if the connection is closed
  */
 public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
   try {
     if (isDebugEnabled()) {
       debugCode("setAutoCommit(" + autoCommit + ");");
     }
     checkClosed();
     if (autoCommit) {
       setAutoCommitTrue = prepareCommand("SET AUTOCOMMIT TRUE", setAutoCommitTrue);
       setAutoCommitTrue.executeUpdate();
     } else {
       setAutoCommitFalse = prepareCommand("SET AUTOCOMMIT FALSE", setAutoCommitFalse);
       setAutoCommitFalse.executeUpdate();
     }
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#23
0
 /**
  * Creates a new callable statement.
  *
  * @return the callable statement
  * @throws SQLException if the connection is closed or the statement is not valid
  */
 public CallableStatement prepareCall(String sql) throws SQLException {
   try {
     int id = getNextId(TraceObject.CALLABLE_STATEMENT);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "CallableStatement",
           TraceObject.CALLABLE_STATEMENT,
           id,
           "prepareCall(" + quote(sql) + ")");
     }
     checkClosed();
     sql = translateSQL(sql);
     return new JdbcCallableStatement(
         this, sql, id, ResultSet.TYPE_FORWARD_ONLY, SysProperties.DEFAULT_RESULT_SET_CONCURRENCY);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#24
0
 /**
  * Creates a callable statement with the specified result set type and concurrency.
  *
  * @return the callable statement
  * @throws SQLException if the connection is closed or the result set type or concurrency are not
  *     supported
  */
 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
     throws SQLException {
   try {
     int id = getNextId(TraceObject.CALLABLE_STATEMENT);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "CallableStatement",
           TraceObject.CALLABLE_STATEMENT,
           id,
           "prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
     }
     checkTypeConcurrency(resultSetType, resultSetConcurrency);
     checkClosed();
     sql = translateSQL(sql);
     return new JdbcCallableStatement(this, sql, id, resultSetType, resultSetConcurrency);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#25
0
 /** INTERNAL */
 public int getQueryTimeout() throws SQLException {
   try {
     debugCodeCall("getQueryTimeout");
     checkClosed();
     getQueryTimeout =
         prepareCommand(
             "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?", getQueryTimeout);
     getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
     ResultInterface result = getQueryTimeout.executeQuery(0, false);
     result.next();
     int queryTimeout = result.currentRow()[0].getInt();
     result.close();
     if (queryTimeout == 0) {
       return 0;
     }
     // round to the next second, otherwise 999 millis would return 0 seconds
     return (queryTimeout + 999) / 1000;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
示例#26
0
 private void checkClosed() {
   conn.checkClosed();
   if (value == null) {
     throw DbException.get(ErrorCode.OBJECT_CLOSED);
   }
 }
示例#27
0
 /**
  * Check if this connection is closed. The next operation may be a write request.
  *
  * @throws SQLException if the connection or session is closed
  */
 private void checkClosedForWrite() throws SQLException {
   checkClosed(true);
 }
示例#28
0
 String getURL() throws SQLException {
   checkClosed();
   return url;
 }
示例#29
0
 String getUser() throws SQLException {
   checkClosed();
   return user;
 }
示例#30
0
 /**
  * INTERNAL. Check if this connection is closed. The next operation is a read request.
  *
  * @throws SQLException if the connection or session is closed
  */
 protected void checkClosed() throws SQLException {
   checkClosed(false);
 }