Exemple #1
0
 @Override
 public void changeUser(String userName, String newPassword) throws SQLException {
   // TODO: recycleConnection();
   Object oldName = null;
   Object oldPassword = null;
   if (userName != null) {
     oldName = this.connectionProps.put(TeiidURL.CONNECTION.USER_NAME, userName);
   } else {
     oldName = this.connectionProps.remove(TeiidURL.CONNECTION.USER_NAME);
   }
   oldPassword = setPassword(newPassword);
   boolean success = false;
   try {
     this.serverConn.authenticate();
     success = true;
   } catch (ConnectionException e) {
     throw TeiidSQLException.create(e);
   } catch (CommunicationException e) {
     throw TeiidSQLException.create(e);
   } finally {
     if (!success) {
       if (oldName != null) {
         this.connectionProps.put(TeiidURL.CONNECTION.USER_NAME, oldName);
       } else {
         this.connectionProps.remove(TeiidURL.CONNECTION.USER_NAME);
       }
       setPassword(oldPassword);
     }
   }
 }
Exemple #2
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 #3
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 #4
0
 protected Xid[] recoverTransaction(int arg0) throws SQLException {
   checkConnection();
   try {
     ResultsFuture<Xid[]> future = this.dqp.recover(arg0);
     return future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
 }
Exemple #5
0
 protected void forgetTransaction(XidImpl arg0) throws SQLException {
   checkConnection();
   try {
     ResultsFuture<?> future = this.dqp.forget(arg0);
     future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
 }
Exemple #6
0
 protected int prepareTransaction(XidImpl arg0) throws SQLException {
   checkConnection();
   transactionXid = null;
   try {
     ResultsFuture<Integer> future = this.dqp.prepare(arg0);
     return future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
 }
Exemple #7
0
 protected void endTransaction(XidImpl arg0, int arg1) throws SQLException {
   checkConnection();
   this.autoCommitFlag = true;
   try {
     ResultsFuture<?> future = this.dqp.end(arg0, arg1);
     future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
 }
Exemple #8
0
 protected void startTransaction(XidImpl arg0, int arg1, int timeout) throws SQLException {
   checkConnection();
   try {
     ResultsFuture<?> future = this.dqp.start(arg0, arg1, timeout);
     future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
   transactionXid = arg0;
   this.autoCommitFlag = false;
 }
Exemple #9
0
 protected void rollbackTransaction(XidImpl arg0) throws SQLException {
   checkConnection();
   transactionXid = null;
   this.autoCommitFlag = true;
   try {
     ResultsFuture<?> future = this.dqp.rollback(arg0);
     future.get();
   } catch (Exception e) {
     throw TeiidSQLException.create(e);
   }
 }
Exemple #10
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 #11
0
 void beginLocalTxnIfNeeded() throws SQLException {
   if (this.transactionXid != null || inLocalTxn || this.autoCommitFlag || isDisableLocalTxn()) {
     return;
   }
   try {
     try {
       this.dqp.begin();
     } catch (XATransactionException e) {
       throw TeiidSQLException.create(e);
     }
     inLocalTxn = true;
   } finally {
     if (!inLocalTxn) {
       autoCommitFlag = true;
     }
   }
 }
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
  public ResultsFuture<?> submitSetAutoCommitTrue(boolean commit) throws SQLException {
    // Check to see the connection is open
    checkConnection();

    if (this.autoCommitFlag) {
      return ResultsFuture.NULL_FUTURE;
    }

    this.autoCommitFlag = true;

    try {
      if (commit) {
        return dqp.commit();
      }
      return dqp.rollback();
    } catch (XATransactionException e) {
      throw TeiidSQLException.create(e);
    }
  }