Search in sources :

Example 31 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateStepExecutionWithMetrics.

protected void updateStepExecutionWithMetrics(StepContextImpl stepContext, long readCount, long writeCount, long commitCount, long rollbackCount, long readSkipCount, long processSkipCount, long filterCount, long writeSkipCount) {
    long stepExecutionId = stepContext.getInternalStepExecutionId();
    String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name();
    String exitStatus = stepContext.getExitStatus();
    String stepName = stepContext.getStepName();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("batchStatus: " + batchStatus + " | stepName: " + stepName + " | stepExecID: " + stepContext.getStepExecutionId());
    }
    Timestamp startTime = stepContext.getStartTimeTS();
    Timestamp endTime = stepContext.getEndTimeTS();
    Serializable persistentData = stepContext.getPersistentUserData();
    if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER, "About to update StepExecution with: ", new Object[] { stepExecutionId, 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;
    String query = queryStrings.get(UPDATE_STEP_EXECUTION_WITH_METRICS);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query);
        statement.setString(1, batchStatus);
        statement.setString(2, exitStatus);
        statement.setString(3, stepName);
        statement.setLong(4, readCount);
        statement.setLong(5, writeCount);
        statement.setLong(6, commitCount);
        statement.setLong(7, rollbackCount);
        statement.setLong(8, readSkipCount);
        statement.setLong(9, processSkipCount);
        statement.setLong(10, filterCount);
        statement.setLong(11, writeSkipCount);
        statement.setTimestamp(12, startTime);
        statement.setTimestamp(13, endTime);
        statement.setObject(14, serializeObject(persistentData));
        statement.setLong(15, stepExecutionId);
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
}
Also used : Serializable(java.io.Serializable) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) Timestamp(java.sql.Timestamp)

Example 32 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getMostRecentStepExecutionsForJobInstance.

public Map<String, StepExecution> getMostRecentStepExecutionsForJobInstance(long instanceId) {
    Map<String, StepExecution> data = new HashMap<String, StepExecution>();
    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(MOST_RECENT_STEPS_FOR_JOB));
        statement.setLong(1, instanceId);
        rs = statement.executeQuery();
        while (rs.next()) {
            stepname = rs.getString("stepname");
            if (data.containsKey(stepname)) {
                continue;
            } else {
                jobexecid = rs.getLong("jobexecid");
                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);
                data.put(stepname, stepEx);
            }
        }
    } 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 data;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) StepExecution(javax.batch.runtime.StepExecution) 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 33 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetRunningExecutions.

@Override
public Set<Long> jobOperatorGetRunningExecutions(String jobName) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    Set<Long> executionIds = new HashSet<Long>();
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_GET_RUNNING_EXECUTIONS));
        statement.setString(1, BatchStatus.STARTED.name());
        statement.setString(2, BatchStatus.STARTING.name());
        statement.setString(3, BatchStatus.STOPPING.name());
        statement.setString(4, jobName);
        rs = statement.executeQuery();
        while (rs.next()) {
            executionIds.add(rs.getLong("jobexecid"));
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return executionIds;
}
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) HashSet(java.util.HashSet)

Example 34 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetJobInstanceIds.

@Override
public List<Long> jobOperatorGetJobInstanceIds(String jobName, String appTag, int start, int count) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    List<Long> data = new ArrayList<Long>();
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOBOPERATOR_GET_JOB_INSTANCE_IDS));
        statement.setObject(1, jobName);
        statement.setObject(2, appTag);
        rs = statement.executeQuery();
        while (rs.next()) {
            long id = rs.getLong("jobinstanceid");
            data.add(id);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    if (data.size() > 0) {
        try {
            return data.subList(start, start + count);
        } catch (IndexOutOfBoundsException oobEx) {
            return data.subList(start, data.size());
        }
    } else {
        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)

Example 35 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getJobStatusFromExecution.

@Override
public JobStatus getJobStatusFromExecution(long executionId) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    JobStatus retVal = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(GET_JOB_STATUS_FROM_EXECUTIONS));
        statement.setLong(1, executionId);
        rs = statement.executeQuery();
        byte[] buf = null;
        if (rs.next()) {
            buf = rs.getBytes("obj");
        }
        retVal = (JobStatus) deserializeObject(buf);
    } catch (Exception e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    logger.exiting(CLASSNAME, "executeQuery");
    return retVal;
}
Also used : JobStatus(com.ibm.jbatch.container.status.JobStatus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) 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)

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