Exemple #1
0
  /**
   * Transaction Constructor
   *
   * @param trxName unique name
   * @param con optional connection ( ignore for remote transaction )
   */
  private Trx(
      final ITrxManager trxManager,
      final String trxName,
      final Connection con,
      final boolean autocommit) {
    super(trxManager, trxName, autocommit);

    setConnection(con);
  } // Trx
Exemple #2
0
  /**
   * Get Connection
   *
   * @return connection
   */
  public Connection getConnection() {
    log.trace("Active={}, Connection={}", new Object[] {isActive(), m_connection});

    // metas: tsa: begin: Handle the case when the connection was already closed
    // Example: one case when we can get this is when we start a process with a transaction
    // and that process is commiting the transaction somewhere
    if (m_connection != null) {
      boolean isClosed = false;
      try {
        isClosed = m_connection.isClosed();
      } catch (SQLException e) {
        log.error(
            "Error checking if the connection is closed. Assume closed - "
                + e.getLocalizedMessage(),
            e);
        isClosed = true;
      }
      if (isClosed) {
        log.info("Connection is closed. Trying to create another connection.");
        m_connection = null;
      }
    }
    // metas: tsa: end:
    if (m_connection == null) // get new Connection
    {
      setConnection(DB.createConnection(isAutoCommit(), Connection.TRANSACTION_READ_COMMITTED));
    }
    if (!isActive()) {
      start();
    }

    try {
      m_connection.setAutoCommit(isAutoCommit());
    } catch (SQLException e) {
      throw DBException.wrapIfNeeded(e);
    }

    return m_connection;
  } // getConnection