Search in sources :

Example 11 with PersistenceException

use of com.ibm.jbatch.container.exception.PersistenceException in project Payara by payara.

the class JBatchJDBCPersistenceManager method getStepStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#getStepStatus
	 * (long, java.lang.String)
	 */
@Override
public StepStatus getStepStatus(long instanceId, String stepName) {
    logger.entering(CLASSNAME, "getStepStatus", new Object[] { instanceId, stepName });
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    RuntimeJobExecution jobExecution = null;
    String query = queryStrings.get(GET_STEP_STATUS);
    StepStatus stepStatus = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query);
        statement.setLong(1, instanceId);
        statement.setString(2, stepName);
        rs = statement.executeQuery();
        if (rs.next()) {
            stepStatus = (StepStatus) deserializeObject(rs.getBytes(1));
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    logger.exiting(CLASSNAME, "getStepStatus", stepStatus == null ? "<null>" : stepStatus);
    return stepStatus;
}
Also used : RuntimeJobExecution(com.ibm.jbatch.container.jobinstance.RuntimeJobExecution) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) StepStatus(com.ibm.jbatch.container.status.StepStatus) IOException(java.io.IOException)

Example 12 with PersistenceException

use of com.ibm.jbatch.container.exception.PersistenceException in project Payara by payara.

the class JBatchJDBCPersistenceManager method cleanupConnection.

/**
 * closes connection and statement
 *
 * @param conn
 *            - connection object to close
 * @param statement
 *            - statement object to close
 */
protected void cleanupConnection(Connection conn, PreparedStatement statement) {
    logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Entering", new Object[] { conn, statement });
    if (statement != null) {
        try {
            statement.close();
        } catch (SQLException e) {
            throw new PersistenceException(e);
        }
    }
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) {
            throw new PersistenceException(e);
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new PersistenceException(e);
            }
        }
    }
    logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Exiting");
}
Also used : SQLException(java.sql.SQLException) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException)

Example 13 with PersistenceException

use of com.ibm.jbatch.container.exception.PersistenceException in project Payara by payara.

the class PostgresPersistenceManager method createStepExecution.

@Override
protected StepExecutionImpl createStepExecution(long rootJobExecId, String batchStatus, String exitStatus, String stepName, long readCount, long writeCount, long commitCount, long rollbackCount, long readSkipCount, long processSkipCount, long filterCount, long writeSkipCount, Timestamp startTime, Timestamp endTime, Serializable persistentData) {
    logger.entering(CLASSNAME, "createStepExecution", new Object[] { rootJobExecId, batchStatus, exitStatus == null ? "<null>" : exitStatus, stepName, readCount, writeCount, commitCount, rollbackCount, readSkipCount, processSkipCount, filterCount, writeSkipCount, startTime == null ? "<null>" : startTime, endTime == null ? "<null>" : endTime, persistentData == null ? "<null>" : persistentData });
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    StepExecutionImpl stepExecution = null;
    String query = queryStrings.get(CREATE_STEP_EXECUTION);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query, statement.RETURN_GENERATED_KEYS);
        statement.setLong(1, rootJobExecId);
        statement.setString(2, batchStatus);
        statement.setString(3, exitStatus);
        statement.setString(4, stepName);
        statement.setLong(5, readCount);
        statement.setLong(6, writeCount);
        statement.setLong(7, commitCount);
        statement.setLong(8, rollbackCount);
        statement.setLong(9, readSkipCount);
        statement.setLong(10, processSkipCount);
        statement.setLong(11, filterCount);
        statement.setLong(12, writeSkipCount);
        statement.setTimestamp(13, startTime);
        statement.setTimestamp(14, endTime);
        statement.setObject(15, serializeObject(persistentData));
        statement.executeUpdate();
        rs = statement.getGeneratedKeys();
        if (rs.next()) {
            long stepExecutionId = rs.getLong(1);
            stepExecution = new StepExecutionImpl(rootJobExecId, stepExecutionId);
            stepExecution.setStepName(stepName);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "createStepExecution");
    return stepExecution;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) StepExecutionImpl(com.ibm.jbatch.container.jobinstance.StepExecutionImpl) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 14 with PersistenceException

use of com.ibm.jbatch.container.exception.PersistenceException in project Payara by payara.

the class PostgresPersistenceManager method createJobInstance.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.ibm.jbatch.container.services.IPersistenceManagerService#
	 * createJobInstance(java.lang.String, java.lang.String, java.lang.String,
	 * java.util.Properties)
	 */
@Override
public JobInstance createJobInstance(String name, String apptag, String jobXml) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    JobInstanceImpl jobInstance = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_JOB_INSTANCE), statement.RETURN_GENERATED_KEYS);
        statement.setString(1, name);
        statement.setString(2, apptag);
        statement.executeUpdate();
        rs = statement.getGeneratedKeys();
        if (rs.next()) {
            long jobInstanceID = rs.getLong(1);
            jobInstance = new JobInstanceImpl(jobInstanceID, jobXml);
            jobInstance.setJobName(name);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return jobInstance;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) JobInstanceImpl(com.ibm.jbatch.container.jobinstance.JobInstanceImpl)

Example 15 with PersistenceException

use of com.ibm.jbatch.container.exception.PersistenceException in project Payara by payara.

the class PostgresPersistenceManager method markJobStarted.

@Override
public void markJobStarted(long key, Timestamp startTS) {
    logger.entering(CLASSNAME, "markJobStarted", new Object[] { key, startTS });
    final int retryMax = Integer.getInteger(P_MJS_RETRY_MAX, MJS_RETRY_MAX_DEFAULT);
    final int retryDelay = Integer.getInteger(P_MJS_RETRY_DELAY, MJS_RETRY_DELAY_DEFAULT);
    logger.log(Level.FINER, P_MJS_RETRY_MAX + " = {0}" + ", " + P_MJS_RETRY_DELAY + " = {1} ms", new Object[] { retryMax, retryDelay });
    Connection conn = null;
    PreparedStatement statement = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(MARK_JOB_STARTED));
        statement.setString(1, BatchStatus.STARTED.name());
        statement.setTimestamp(2, startTS);
        statement.setTimestamp(3, startTS);
        statement.setLong(4, key);
        // Postgres use of Multi Version Concurrency (MVCC) means that
        // blocking does not occur (particularly a problem in
        // createStepExecution()).
        // The below will check that the row has been commited by the
        // initiating thread by retrying the update until at least 1 row
        // is updated.
        int retryCount = 0;
        while ((statement.executeUpdate() < 1) && (retryCount++ <= retryMax)) {
            sleep(retryDelay);
        }
        logger.log(Level.FINER, "Marking job as started required {0} retries", retryCount);
        if (retryCount >= retryMax) {
            logger.log(Level.WARNING, "Failed to mark job as started after {0} attempts", retryCount);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "markJobStarted");
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PersistenceException (com.ibm.jbatch.container.exception.PersistenceException)46 SQLException (java.sql.SQLException)46 Connection (java.sql.Connection)44 PreparedStatement (java.sql.PreparedStatement)43 ResultSet (java.sql.ResultSet)31 IOException (java.io.IOException)24 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)7 TCCLObjectInputStream (com.ibm.jbatch.container.util.TCCLObjectInputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 StepExecutionImpl (com.ibm.jbatch.container.jobinstance.StepExecutionImpl)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 ObjectOutputStream (java.io.ObjectOutputStream)5 Timestamp (java.sql.Timestamp)5 BatchContainerServiceException (com.ibm.jbatch.container.exception.BatchContainerServiceException)4 JobInstanceImpl (com.ibm.jbatch.container.jobinstance.JobInstanceImpl)4 Serializable (java.io.Serializable)4 NamingException (javax.naming.NamingException)4 JobStatus (com.ibm.jbatch.container.status.JobStatus)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3