Search in sources :

Example 36 with PersistenceException

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

the class PostgresPersistenceManager method createSubJobInstance.

@Override
public JobInstance createSubJobInstance(String name, String apptag) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    JobInstanceImpl jobInstance = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_SUB_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);
            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 37 with PersistenceException

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

the class PostgresPersistenceManager method createRuntimeJobExecutionEntry.

@Override
protected long createRuntimeJobExecutionEntry(JobInstance jobInstance, Properties jobParameters, BatchStatus batchStatus, Timestamp timestamp) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    long newJobExecutionId = 0L;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_JOB_EXECUTION_ENTRY), statement.RETURN_GENERATED_KEYS);
        statement.setLong(1, jobInstance.getInstanceId());
        statement.setTimestamp(2, timestamp);
        statement.setTimestamp(3, timestamp);
        statement.setString(4, batchStatus.name());
        statement.setObject(5, serializeObject(jobParameters));
        statement.executeUpdate();
        rs = statement.getGeneratedKeys();
        if (rs.next()) {
            newJobExecutionId = rs.getLong(1);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return newJobExecutionId;
}
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) IOException(java.io.IOException)

Example 38 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorQueryJobExecutionJobInstanceId.

@Override
public long jobOperatorQueryJobExecutionJobInstanceId(long executionID) throws NoSuchJobExecutionException {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    long jobinstanceID = 0;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_QUERY_JOB_EXECUTION_JOB_ID));
        statement.setLong(1, executionID);
        rs = statement.executeQuery();
        if (rs.next()) {
            jobinstanceID = rs.getLong("jobinstanceid");
        } else {
            String msg = "Did not find job instance associated with executionID =" + executionID;
            logger.fine(msg);
            throw new NoSuchJobExecutionException(msg);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return jobinstanceID;
}
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) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException)

Example 39 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getStepExecutionByStepExecutionId.

@Override
public StepExecution getStepExecutionByStepExecutionId(long stepExecId) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    long jobexecid = 0;
    long stepexecid = 0;
    String stepname = null;
    String batchstatus = null;
    String exitstatus = null;
    Exception ex = null;
    long readCount = 0;
    long writeCount = 0;
    long commitCount = 0;
    long rollbackCount = 0;
    long readSkipCount = 0;
    long processSkipCount = 0;
    long filterCount = 0;
    long writeSkipCount = 0;
    Timestamp startTS = null;
    Timestamp endTS = null;
    StepExecutionImpl stepEx = null;
    ObjectInputStream objectIn = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(STEP_EXECUTIONS_BY_STEP_ID));
        statement.setLong(1, stepExecId);
        rs = statement.executeQuery();
        while (rs.next()) {
            jobexecid = rs.getLong("jobexecid");
            stepexecid = rs.getLong("stepexecid");
            stepname = rs.getString("stepname");
            batchstatus = rs.getString("batchstatus");
            exitstatus = rs.getString("exitstatus");
            readCount = rs.getLong("readcount");
            writeCount = rs.getLong("writecount");
            commitCount = rs.getLong("commitcount");
            rollbackCount = rs.getLong("rollbackcount");
            readSkipCount = rs.getLong("readskipcount");
            processSkipCount = rs.getLong("processskipcount");
            filterCount = rs.getLong("filtercount");
            writeSkipCount = rs.getLong("writeSkipCount");
            startTS = rs.getTimestamp("startTime");
            endTS = rs.getTimestamp("endTime");
            // get the object based data
            Serializable persistentData = null;
            byte[] pDataBytes = rs.getBytes("persistentData");
            if (pDataBytes != null) {
                objectIn = new TCCLObjectInputStream(new ByteArrayInputStream(pDataBytes));
                persistentData = (Serializable) objectIn.readObject();
            }
            stepEx = new StepExecutionImpl(jobexecid, stepexecid);
            stepEx.setBatchStatus(BatchStatus.valueOf(batchstatus));
            stepEx.setExitStatus(exitstatus);
            stepEx.setStepName(stepname);
            stepEx.setReadCount(readCount);
            stepEx.setWriteCount(writeCount);
            stepEx.setCommitCount(commitCount);
            stepEx.setRollbackCount(rollbackCount);
            stepEx.setReadSkipCount(readSkipCount);
            stepEx.setProcessSkipCount(processSkipCount);
            stepEx.setFilterCount(filterCount);
            stepEx.setWriteSkipCount(writeSkipCount);
            stepEx.setStartTime(startTS);
            stepEx.setEndTime(endTS);
            stepEx.setPersistentUserData(persistentData);
            logger.fine("stepExecution BatchStatus: " + batchstatus + " StepName: " + stepname);
        }
    } 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);
    }
    return stepEx;
}
Also used : Serializable(java.io.Serializable) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) NamingException(javax.naming.NamingException) BatchContainerServiceException(com.ibm.jbatch.container.exception.BatchContainerServiceException) SQLException(java.sql.SQLException) IOException(java.io.IOException) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) StepExecutionImpl(com.ibm.jbatch.container.jobinstance.StepExecutionImpl) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) ObjectInputStream(java.io.ObjectInputStream) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream)

Example 40 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createRuntimeJobExecutionEntry.

protected long createRuntimeJobExecutionEntry(JobInstance jobInstance, Properties jobParameters, BatchStatus batchStatus, Timestamp timestamp) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    long newJobExecutionId = 0L;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_JOB_EXECUTION_ENTRY), new String[] { "JOBEXECID" });
        statement.setLong(1, jobInstance.getInstanceId());
        statement.setTimestamp(2, timestamp);
        statement.setTimestamp(3, timestamp);
        statement.setString(4, batchStatus.name());
        statement.setObject(5, serializeObject(jobParameters));
        statement.executeUpdate();
        rs = statement.getGeneratedKeys();
        if (rs.next()) {
            newJobExecutionId = rs.getLong(1);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return newJobExecutionId;
}
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) IOException(java.io.IOException)

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