예제 #1
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);
   }
 }
예제 #2
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);
   }
 }
예제 #3
0
  @Override
  public String format(PreparedStatement stmt) {
    try {
      if (stmt instanceof JdbcPreparedStatement) {
        String sql = (String) ReflectUtil.getValue(SQL_FIELD, stmt);

        boolean insert = false;
        if (sql.toUpperCase().startsWith("INSERT INTO")) {
          int pos = sql.indexOf("(");
          sql = sql.substring(0, pos) + "SET " + sql.substring(pos + 1);
          sql = sql.substring(0, sql.indexOf(" VALUES"));
          insert = true;
        }

        CommandInterface command = (CommandInterface) ReflectUtil.getValue(COMMAND_FIELD, stmt);
        ObjectArray<? extends ParameterInterface> parameters = command.getParameters();

        int pos = 0;
        for (int i = 0; i < parameters.size(); i++) {
          ParameterInterface parameter = parameters.get(i);
          Value value = parameter.getParamValue();

          if (insert) {
            String string = "=" + value;

            pos = sql.indexOf(',', pos);
            if (pos == -1) {
              pos = sql.indexOf(')');
              sql = sql.substring(0, pos) + string;
              break;
            }

            sql = sql.substring(0, pos) + string + sql.substring(pos);
            pos += string.length() + 1;
          } else {
            pos = sql.indexOf('?');
            sql = sql.substring(0, pos) + value + sql.substring(pos + 1);
          }
        }

        return sql;
      }
    } catch (Throwable t) {
      // $FALL-THROUGH$
    }

    return super.format(stmt);
  }
예제 #4
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);
   }
 }
 JdbcParameterMetaData(Trace trace, JdbcPreparedStatement prep, CommandInterface command, int id) {
   setTrace(trace, TraceObject.PARAMETER_META_DATA, id);
   this.prep = prep;
   this.parameters = command.getParameters();
   this.paramCount = parameters.size();
 }