Exemple #1
0
  public void recycleConnection(boolean selectNewInstance) {
    this.payload = null;
    try {
      // close all open statements
      this.closeStatements();
    } catch (SQLException e) {
      logger.log(
          Level.WARNING,
          JDBCPlugin.Util.getString("MMXAConnection.rolling_back_error"),
          e); //$NON-NLS-1$
    }
    try {
      // rollback if still in a transaction
      if (!this.getAutoCommit()) {
        logger.warning(JDBCPlugin.Util.getString("MMXAConnection.rolling_back")); // $NON-NLS-1$

        if (this.getTransactionXid() == null) {
          this.rollback(false);
        } else {
          this.rollbackTransaction(getTransactionXid());
        }
      }
    } catch (SQLException e) {
      logger.log(
          Level.WARNING,
          JDBCPlugin.Util.getString("MMXAConnection.rolling_back_error"),
          e); //$NON-NLS-1$
    }

    if (selectNewInstance) {
      this.serverConn.cleanUp();
    }
  }
Exemple #2
0
  public void close() throws SQLException {
    Throwable firstException = null;

    if (closed) {
      return;
    }

    try {
      // close any statements that were created on this connection
      try {
        closeStatements();
      } catch (SQLException se) {
        firstException = se;
      } finally {
        this.serverConn.close();
        if (firstException != null) throw (SQLException) firstException;
      }
    } catch (SQLException se) {
      throw TeiidSQLException.create(
          se,
          JDBCPlugin.Util.getString(
              "MMConnection.Err_connection_close", se.getMessage())); // $NON-NLS-1$
    } finally {
      logger.fine(
          JDBCPlugin.Util.getString("MMConnection.Connection_close_success")); // $NON-NLS-1$
      // set the status of the connection to closed
      closed = true;
    }
  }
Exemple #3
0
 /**
  * This utility method checks if the jdbc connection is closed and throws an exception if it is
  * closed.
  *
  * @throws SQLException if the connection object is closed.
  */
 void checkConnection() throws SQLException {
   // Check to see the connection is closed and proceed if it is not
   if (closed) {
     throw new TeiidSQLException(
         JDBCPlugin.Util.getString("MMConnection.Cant_use_closed_connection")); // $NON-NLS-1$
   }
 }
Exemple #4
0
  /**
   * Rollback the current local transaction
   *
   * @param startTxn
   * @throws SQLException
   */
  public void rollback(boolean startTxn) throws SQLException {

    // Check to see the connection is open
    checkConnection();
    if (!autoCommitFlag) {
      try {
        if (this.inLocalTxn) {
          this.inLocalTxn = false;
          try {
            ResultsFuture<?> future = this.dqp.rollback();
            future.get();
          } catch (Exception e) {
            throw TeiidSQLException.create(e);
          }
          logger.fine(JDBCPlugin.Util.getString("MMConnection.Rollback_success")); // $NON-NLS-1$
        }
      } finally {
        if (startTxn) {
          this.inLocalTxn = false;
        } else {
          this.autoCommitFlag = true;
        }
      }
    }
  }
Exemple #5
0
 private void addStatement(StatementImpl newStatement) throws SQLException {
   if (statements.size() > MAX_OPEN_STATEMENTS) {
     this.close();
     throw new TeiidSQLException(
         JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20036, MAX_OPEN_STATEMENTS));
   }
   statements.add(newStatement);
 }
Exemple #6
0
 /**
  * @param resultSetConcurrency
  * @throws TeiidSQLException
  * @since 4.3
  */
 private void validateResultSetConcurrency(int resultSetConcurrency) throws TeiidSQLException {
   if (resultSetConcurrency == ResultSet.CONCUR_UPDATABLE) {
     String msg =
         JDBCPlugin.Util.getString(
             "MMConnection.Concurrency_type_not_supported",
             "ResultSet.CONCUR_UPDATABLE"); //$NON-NLS-1$ //$NON-NLS-2$
     throw new TeiidSQLException(msg);
   }
 }
Exemple #7
0
 /**
  * @param resultSetType
  * @throws TeiidSQLException
  * @since 4.3
  */
 private void validateResultSetType(int resultSetType) throws TeiidSQLException {
   if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
     String msg =
         JDBCPlugin.Util.getString(
             "MMConnection.Scrollable_type_not_supported",
             "ResultSet.TYPE_SCROLL_SENSITIVE"); //$NON-NLS-1$ //$NON-NLS-2$
     throw new TeiidSQLException(msg);
   }
 }
Exemple #8
0
 private void directCommit() throws SQLException {
   if (inLocalTxn) {
     try {
       ResultsFuture<?> future = this.dqp.commit();
       future.get();
     } catch (Exception e) {
       throw TeiidSQLException.create(e);
     }
     logger.fine(JDBCPlugin.Util.getString("MMConnection.Commit_success")); // $NON-NLS-1$
   }
 }
Exemple #9
0
  public ConnectionImpl(ServerConnection serverConn, Properties info, String url) {
    this.connectionProps = info;
    this.serverConn = serverConn;
    this.url = url;
    this.dqp = serverConn.getService(DQP.class);

    logger.fine(JDBCPlugin.Util.getString("MMConnection.Session_success")); // $NON-NLS-1$
    logConnectionProperties(url, info);

    setExecutionProperties(info);
  }
Exemple #10
0
 /**
  * @param A boolean value specifying whether the connection is readonly.
  * @throws throws SQLException.
  */
 public void setReadOnly(boolean readOnly) throws SQLException {
   if (this.readOnly == readOnly) {
     return;
   }
   // During transaction do not allow to change this flag
   if (!autoCommitFlag || this.transactionXid != null) {
     throw new TeiidSQLException(
         JDBCPlugin.Util.getString(
             "MMStatement.Invalid_During_Transaction",
             "setReadOnly(" + readOnly + ")")); // $NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
   }
   this.readOnly = readOnly;
 }
Exemple #11
0
  public ConnectionImpl(ServerConnection serverConn, Properties info, String url) {
    this.connectionProps = info;
    this.serverConn = serverConn;
    this.url = url;
    this.dqp = serverConn.getService(DQP.class);

    logger.fine(JDBCPlugin.Util.getString("MMConnection.Session_success")); // $NON-NLS-1$
    logConnectionProperties(url, info);

    setExecutionProperties(info);

    this.disableLocalTransactions =
        Boolean.valueOf(this.propInfo.getProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS))
            .booleanValue();
  }
Exemple #12
0
 /**
  * Close all the statements open on this connection
  *
  * @throws SQLException server statement object could not be closed.
  */
 void closeStatements() throws SQLException {
   // Closing the statement will cause the
   // MMConnection.closeStatement() method to be called,
   // which will modify this.statements.  So, we do this iteration
   // in a separate safe copy of the list
   List<StatementImpl> statementsSafe = new ArrayList<StatementImpl>(this.statements);
   SQLException ex = null;
   for (StatementImpl statement : statementsSafe) {
     try {
       statement.close();
     } catch (SQLException e) {
       ex = e;
     }
   }
   if (ex != null) {
     throw TeiidSQLException.create(
         ex, JDBCPlugin.Util.getString("MMConnection.Err_closing_stmts")); // $NON-NLS-1$
   }
 }
Exemple #13
0
 /**
  * @param sql
  * @throws TeiidSQLException
  * @since 4.3
  */
 private void validateSQL(String sql) throws TeiidSQLException {
   if (sql == null) {
     String msg = JDBCPlugin.Util.getString("MMConnection.SQL_cannot_be_null"); // $NON-NLS-1$
     throw new TeiidSQLException(msg);
   }
 }