Search in sources :

Example 26 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetExternalJobInstanceData.

@Override
public Map<Long, String> jobOperatorGetExternalJobInstanceData() {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    HashMap<Long, String> data = new HashMap<Long, String>();
    try {
        conn = getConnection();
        // Filter out 'subjob' parallel execution entries which start with
        // the special character
        final String filter = "not like '" + PartitionedStepBuilder.JOB_ID_SEPARATOR + "%'";
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_GET_EXTERNAL_JOB_INSTANCE_DATA) + filter);
        rs = statement.executeQuery();
        while (rs.next()) {
            long id = rs.getLong("jobinstanceid");
            String name = rs.getString("name");
            data.put(id, name);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return data;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Example 27 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetJobExecutions.

@Override
public List<IJobExecution> jobOperatorGetJobExecutions(long jobInstanceId) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    List<IJobExecution> data = new ArrayList<IJobExecution>();
    ObjectInputStream objectIn = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_GET_JOB_EXECUTIONS));
        statement.setLong(1, jobInstanceId);
        rs = statement.executeQuery();
        while (rs.next()) {
            data.add(readJobExecutionRecord(rs));
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e);
    } finally {
        if (objectIn != null) {
            try {
                objectIn.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, rs, statement);
    }
    return data;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) IJobExecution(com.ibm.jbatch.container.services.IJobExecution) ObjectInputStream(java.io.ObjectInputStream) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream)

Example 28 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getParameters.

@Override
public Properties getParameters(long executionId) throws NoSuchJobExecutionException {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    Properties props = null;
    ObjectInputStream objectIn = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(GET_PARAMETERS));
        statement.setLong(1, executionId);
        rs = statement.executeQuery();
        if (rs.next()) {
            // get the object based data
            byte[] buf = rs.getBytes("parameters");
            props = (Properties) deserializeObject(buf);
        } else {
            String msg = "Did not find table entry for executionID =" + executionId;
            logger.fine(msg);
            throw new NoSuchJobExecutionException(msg);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e);
    } finally {
        if (objectIn != null) {
            try {
                objectIn.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, rs, statement);
    }
    return props;
}
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) IOException(java.io.IOException) Properties(java.util.Properties) ObjectInputStream(java.io.ObjectInputStream) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream)

Example 29 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createStepExecution.

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, new String[] { "STEPEXECID" });
        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 30 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getJobCurrentTag.

@Override
public String getJobCurrentTag(long jobInstanceId) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    String apptag = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(SELECT_JOBINSTANCEDATA_APPTAG));
        statement.setLong(1, jobInstanceId);
        rs = statement.executeQuery();
        while (rs.next()) {
            apptag = rs.getString(APPTAG);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return apptag;
}
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)

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