Search in sources :

Example 1 with StepExecutionImpl

use of com.ibm.jbatch.container.jobinstance.StepExecutionImpl in project Payara by payara.

the class JBatchJDBCPersistenceManager method createStepExecution.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.ibm.jbatch.container.services.IPersistenceManagerService#
	 * createStepExecution(long,
	 * com.ibm.jbatch.container.context.impl.StepContextImpl)
	 */
@Override
public StepExecutionImpl createStepExecution(long rootJobExecId, StepContextImpl stepContext) {
    StepExecutionImpl stepExecution = null;
    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);
    }
    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 startTime = stepContext.getStartTimeTS();
    Timestamp endTime = stepContext.getEndTimeTS();
    Metric[] metrics = stepContext.getMetrics();
    for (int i = 0; i < metrics.length; i++) {
        if (metrics[i].getType().equals(MetricImpl.MetricType.READ_COUNT)) {
            readCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.WRITE_COUNT)) {
            writeCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.PROCESS_SKIP_COUNT)) {
            processSkipCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.COMMIT_COUNT)) {
            commitCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.ROLLBACK_COUNT)) {
            rollbackCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.READ_SKIP_COUNT)) {
            readSkipCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.FILTER_COUNT)) {
            filterCount = metrics[i].getValue();
        } else if (metrics[i].getType().equals(MetricImpl.MetricType.WRITE_SKIP_COUNT)) {
            writeSkipCount = metrics[i].getValue();
        }
    }
    Serializable persistentData = stepContext.getPersistentUserData();
    stepExecution = createStepExecution(rootJobExecId, batchStatus, exitStatus, stepName, readCount, writeCount, commitCount, rollbackCount, readSkipCount, processSkipCount, filterCount, writeSkipCount, startTime, endTime, persistentData);
    return stepExecution;
}
Also used : Serializable(java.io.Serializable) StepExecutionImpl(com.ibm.jbatch.container.jobinstance.StepExecutionImpl) Metric(javax.batch.runtime.Metric) Timestamp(java.sql.Timestamp)

Example 2 with StepExecutionImpl

use of com.ibm.jbatch.container.jobinstance.StepExecutionImpl 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 3 with StepExecutionImpl

use of com.ibm.jbatch.container.jobinstance.StepExecutionImpl in project Payara by payara.

the class JBatchJDBCPersistenceManager method getStepExecutionsForJobExecution.

@Override
public List<StepExecution> getStepExecutionsForJobExecution(long execid) {
    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;
    List<StepExecution> data = new ArrayList<StepExecution>();
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(STEP_EXECUTIONS_FOR_JOB_EXECUTION));
        statement.setLong(1, execid);
        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("BatchStatus: " + batchstatus + " | StepName: " + stepname + " | JobExecID: " + jobexecid + " | StepExecID: " + stepexecid);
            data.add(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) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) StepExecution(javax.batch.runtime.StepExecution) 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 4 with StepExecutionImpl

use of com.ibm.jbatch.container.jobinstance.StepExecutionImpl 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 5 with StepExecutionImpl

use of com.ibm.jbatch.container.jobinstance.StepExecutionImpl 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)

Aggregations

StepExecutionImpl (com.ibm.jbatch.container.jobinstance.StepExecutionImpl)6 PersistenceException (com.ibm.jbatch.container.exception.PersistenceException)5 IOException (java.io.IOException)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 Serializable (java.io.Serializable)4 Timestamp (java.sql.Timestamp)4 BatchContainerServiceException (com.ibm.jbatch.container.exception.BatchContainerServiceException)3 TCCLObjectInputStream (com.ibm.jbatch.container.util.TCCLObjectInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)3 NamingException (javax.naming.NamingException)3 StepExecution (javax.batch.runtime.StepExecution)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Metric (javax.batch.runtime.Metric)1