Exemplo n.º 1
0
 /**
  * Method to call to remove the current batched statement for this connection and close it due to
  * an error preventing continuation.
  *
  * @param conn The connection
  * @param ps The statement
  */
 public void abortStatementForConnection(ManagedConnection conn, PreparedStatement ps) {
   ConnectionStatementState state = getConnectionStatementState(conn);
   if (state != null && state.stmt == ps) {
     try {
       removeConnectionStatementState(conn);
       ps.close();
     } catch (SQLException sqe) {
       // Do nothing
     }
   }
 }
Exemplo n.º 2
0
  /**
   * Convenience method to process the currently waiting statement for the passed Connection. Only
   * processes the statement if it is in processable state.
   *
   * @param conn The connection
   * @return The return codes from the statement batch
   * @throws SQLException if an error occurs processing the batch
   */
  protected int[] processConnectionStatement(ManagedConnection conn) throws SQLException {
    ConnectionStatementState state = getConnectionStatementState(conn);
    if (state == null || !state.processable) {
      return null;
    }

    long startTime = System.currentTimeMillis();
    if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) {
      if (state.stmt instanceof ParamLoggingPreparedStatement) {
        NucleusLogger.DATASTORE_NATIVE.debug(
            ((ParamLoggingPreparedStatement) state.stmt).getStatementWithParamsReplaced());
      } else {
        NucleusLogger.DATASTORE_NATIVE.debug(state.stmtText);
      }
    }

    int[] ind = state.stmt.executeBatch();
    state.stmt.clearBatch();

    if (NucleusLogger.DATASTORE.isDebugEnabled()) {
      NucleusLogger.DATASTORE.debug(
          LOCALISER.msg(
              "045001",
              "" + (System.currentTimeMillis() - startTime),
              StringUtils.intArrayToString(ind),
              StringUtils.toJVMIDString(state.stmt)));
    }

    // Remove the current connection statement
    removeConnectionStatementState(conn);

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

    return ind;
  }