Ejemplo n.º 1
0
  /**
   * Convenience method to set the state for this connection.
   *
   * @param conn The Connection
   * @param state The state
   */
  protected void setConnectionStatementState(
      final ManagedConnection conn, ConnectionStatementState state) {
    connectionStatements.put(conn, state);
    conn.addListener(
        new ManagedConnectionResourceListener() {
          public void transactionFlushed() {
            try {
              processStatementsForConnection(conn);
            } catch (SQLException e) {
              // cleanup state
              ConnectionStatementState state = getConnectionStatementState(conn);
              if (state != null) {
                // Remove the current connection statement
                removeConnectionStatementState(conn);

                // Close the statement if it is registered for closing after processing
                if (state.closeStatementOnProcess) {
                  try {
                    state.stmt.close();
                  } catch (SQLException ex) {
                    // ignore
                  }
                }
              }

              throw new NucleusDataStoreException(LOCALISER.msg("052108"), e);
            }
          }

          public void transactionPreClose() {}

          public void managedConnectionPreClose() {}

          public void managedConnectionPostClose() {}

          public void resourcePostClose() {}
        });
  }