Пример #1
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;
    }
  }
Пример #2
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();
    }
  }
Пример #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$
   }
 }
Пример #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;
        }
      }
    }
  }
Пример #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);
 }
Пример #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);
   }
 }
Пример #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);
   }
 }
Пример #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$
   }
 }
Пример #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);
  }
Пример #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;
 }
Пример #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();
  }
Пример #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$
   }
 }
Пример #13
0
  @Override
  public List<?> next() throws TranslatorException, DataNotAvailableException {
    try {
      ArrayList<Object[]> row = new ArrayList<Object[]>(1);

      if (this.results != null) {
        if (this.results.next()) {
          // New row for result set
          List<Object> vals = new ArrayList<Object>(this.columnCount);

          for (int i = 0; i < this.columnCount; i++) {
            // Convert from 0-based to 1-based
            Object value =
                this.executionFactory.retrieveValue(
                    this.results, i + 1, TypeFacility.RUNTIME_TYPES.OBJECT);
            vals.add(value);
          }
          row.add(vals.toArray(new Object[vals.size()]));
          return row;
        }
      } else if (this.updateCount != -1) {
        List<Object> vals = new ArrayList<Object>(1);
        vals.add(new Integer(this.updateCount));
        this.updateCount = -1;
        row.add(vals.toArray(new Object[vals.size()]));
        return row;
      }
    } catch (SQLException e) {
      throw new TranslatorException(
          e,
          JDBCPlugin.Util.getString(
              "JDBCTranslator.Unexpected_exception_translating_results___8",
              e.getMessage())); // $NON-NLS-1$
    }
    return null;
  }
Пример #14
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);
   }
 }
Пример #15
0
  @Override
  public String getSourceComment(ExecutionContext context, Command command) {
    String comment = super.getSourceComment(context, command);

    boolean usingPayloadComment = false;
    if (context != null) {
      // Check for db hints
      Object payload = context.getCommandPayload();
      if (payload instanceof String) {
        String payloadString = (String) payload;
        if (payloadString.startsWith(HINT_PREFIX)) {
          int i = payloadString.indexOf(HINT_SUFFIX);
          if (i > 0 && payloadString.substring(i + 2).trim().length() == 0) {
            comment += payloadString + " "; // $NON-NLS-1$
            usingPayloadComment = true;
          } else {
            String msg =
                JDBCPlugin.Util.gs(
                    JDBCPlugin.Event.TEIID11003, "Execution Payload", payloadString); // $NON-NLS-1$
            context.addWarning(new TranslatorException(msg));
            LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
          }
        }
      }
    }

    if (!usingPayloadComment && context != null) {
      String hint = context.getSourceHint();
      if (context.getGeneralHint() != null) {
        if (hint != null) {
          hint += (" " + context.getGeneralHint()); // $NON-NLS-1$
        } else {
          hint = context.getGeneralHint();
        }
      }
      if (hint != null) {
        // append a source hint
        if (!hint.contains(HINT_PREFIX)) {
          comment += HINT_PREFIX + ' ' + hint + ' ' + HINT_SUFFIX + ' ';
        } else {
          String msg =
              JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11003, "Source Hint", hint); // $NON-NLS-1$
          context.addWarning(new TranslatorException(msg));
          LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
        }
      }
    }

    if (command instanceof Select) {
      //
      // This simple algorithm determines the hint which will be added to the
      // query.
      // Right now, we look through all functions passed in the query
      // (returned as a collection)
      // Then we check if any of those functions are sdo_relate
      // If so, the ORDERED hint is added, if not, it isn't
      Collection<Function> col = CollectorVisitor.collectObjects(Function.class, command);
      for (Function func : col) {
        if (func.getName().equalsIgnoreCase(OracleExecutionFactory.RELATE)) {
          return comment + "/*+ ORDERED */ "; // $NON-NLS-1$
        }
      }
    }
    return comment;
  }
Пример #16
0
  public void handleInsertSequences(Insert insert) throws TranslatorException {
    /*
     * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence
     * then pull the Sequence name out of the name in source of the column.
     */
    if (!(insert.getValueSource() instanceof ExpressionValueSource)) {
      return;
    }
    ExpressionValueSource values = (ExpressionValueSource) insert.getValueSource();
    if (insert.getTable().getMetadataObject() == null) {
      return;
    }
    List<Column> allElements = insert.getTable().getMetadataObject().getColumns();
    if (allElements.size() == values.getValues().size()) {
      return;
    }

    int index = 0;
    List<ColumnReference> elements = insert.getColumns();

    for (Column element : allElements) {
      if (!element.isAutoIncremented()) {
        continue;
      }
      String name = element.getNameInSource();
      int seqIndex = name.indexOf(SEQUENCE);
      if (seqIndex == -1) {
        continue;
      }
      boolean found = false;
      while (index < elements.size()) {
        if (element.equals(elements.get(index).getMetadataObject())) {
          found = true;
          break;
        }
        index++;
      }
      if (found) {
        continue;
      }

      String sequence = name.substring(seqIndex + SEQUENCE.length());

      int delimiterIndex = sequence.indexOf(Tokens.DOT);
      if (delimiterIndex == -1) {
        throw new TranslatorException(
            JDBCPlugin.Event.TEIID11017,
            JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11017, SEQUENCE, name));
      }
      String sequenceGroupName = sequence.substring(0, delimiterIndex);
      String sequenceElementName = sequence.substring(delimiterIndex + 1);

      NamedTable sequenceGroup =
          this.getLanguageFactory().createNamedTable(sequenceGroupName, null, null);
      ColumnReference sequenceElement =
          this.getLanguageFactory()
              .createColumnReference(
                  sequenceElementName, sequenceGroup, null, element.getJavaType());
      insert
          .getColumns()
          .add(
              index,
              this.getLanguageFactory()
                  .createColumnReference(
                      element.getName(), insert.getTable(), element, element.getJavaType()));
      values.getValues().add(index, sequenceElement);
    }
  }