Search in sources :

Example 6 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getMostRecentExecutionId.

@Override
public long getMostRecentExecutionId(long jobInstanceId) {
    logger.entering(CLASSNAME, "getMostRecentExecutionId", jobInstanceId);
    long mostRecentId = -1;
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    String query = queryStrings.get(GET_MOST_RECENT_EXECUTION_ID);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query);
        statement.setLong(1, jobInstanceId);
        rs = statement.executeQuery();
        if (rs.next()) {
            mostRecentId = rs.getLong(1);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    logger.exiting(CLASSNAME, "getMostRecentExecutionId");
    return mostRecentId;
}
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)

Example 7 with PersistenceException

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

the class JBatchJDBCPersistenceManager method markJobStarted.

public void markJobStarted(long key, Timestamp startTS) {
    Connection conn = null;
    PreparedStatement statement = null;
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oout = 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);
        statement.executeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new PersistenceException(e);
    } finally {
        if (baos != null) {
            try {
                baos.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        if (oout != null) {
            try {
                oout.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, null, statement);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 8 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createStepStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#createStepStatus
	 * (long)
	 */
@Override
public StepStatus createStepStatus(long stepExecId) {
    logger.entering(CLASSNAME, "createStepStatus", stepExecId);
    Connection conn = null;
    PreparedStatement statement = null;
    StepStatus stepStatus = new StepStatus(stepExecId);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_STEP_STATUS));
        statement.setLong(1, stepExecId);
        statement.setBytes(2, serializeObject(stepStatus));
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "createStepStatus");
    return stepStatus;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) StepStatus(com.ibm.jbatch.container.status.StepStatus) IOException(java.io.IOException)

Example 9 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createJobStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#createJobStatus
	 * (long)
	 */
@Override
public JobStatus createJobStatus(long jobInstanceId) {
    logger.entering(CLASSNAME, "createJobStatus", jobInstanceId);
    Connection conn = null;
    PreparedStatement statement = null;
    JobStatus jobStatus = new JobStatus(jobInstanceId);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_JOBSTATUS));
        statement.setLong(1, jobInstanceId);
        statement.setBytes(2, serializeObject(jobStatus));
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "createJobStatus");
    return jobStatus;
}
Also used : JobStatus(com.ibm.jbatch.container.status.JobStatus) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 10 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateWithFinalExecutionStatusesAndTimestamps.

@Override
public void updateWithFinalExecutionStatusesAndTimestamps(long key, BatchStatus batchStatus, String exitStatus, Timestamp updatets) {
    // TODO Auto-generated methddod stub
    Connection conn = null;
    PreparedStatement statement = null;
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oout = null;
    byte[] b;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_FINAL_STATUS_AND_TIMESTAMP));
        statement.setString(1, batchStatus.name());
        statement.setString(2, exitStatus);
        statement.setTimestamp(3, updatets);
        statement.setTimestamp(4, updatets);
        statement.setLong(5, key);
        statement.executeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new PersistenceException(e);
    } finally {
        if (baos != null) {
            try {
                baos.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        if (oout != null) {
            try {
                oout.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, null, statement);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

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