Search in sources :

Example 21 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createJobInstance.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.ibm.jbatch.container.services.IPersistenceManagerService#
	 * createJobInstance(java.lang.String, java.lang.String, java.lang.String,
	 * java.util.Properties)
	 */
@Override
public JobInstance createJobInstance(String name, String apptag, String jobXml) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    JobInstanceImpl jobInstance = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_JOB_INSTANCE), new String[] { "JOBINSTANCEID" });
        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, jobXml);
            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 22 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateWithFinalPartitionAggregateStepExecution.

@Override
public void updateWithFinalPartitionAggregateStepExecution(long rootJobExecutionId, StepContextImpl stepContext) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = 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;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_WITH_FINAL_PARTITION_STEP_EXECUTION));
        statement.setString(1, getPartitionLevelJobInstanceWildCard(rootJobExecutionId, stepContext.getStepName()));
        rs = statement.executeQuery();
        if (rs.next()) {
            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");
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    updateStepExecutionWithMetrics(stepContext, readCount, writeCount, commitCount, rollbackCount, readSkipCount, processSkipCount, filterCount, writeSkipCount);
}
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 23 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getJobStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#getJobStatus
	 * (long)
	 */
@Override
public JobStatus getJobStatus(long instanceId) {
    logger.entering(CLASSNAME, "getJobStatus", instanceId);
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    RuntimeJobExecution jobExecution = null;
    String query = queryStrings.get(GET_JOB_STATUS);
    JobStatus jobStatus = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query);
        statement.setLong(1, instanceId);
        rs = statement.executeQuery();
        if (rs.next()) {
            jobStatus = (JobStatus) deserializeObject(rs.getBytes(1));
        }
    } 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);
    }
    logger.exiting(CLASSNAME, "getJobStatus", jobStatus);
    return jobStatus;
}
Also used : JobStatus(com.ibm.jbatch.container.status.JobStatus) RuntimeJobExecution(com.ibm.jbatch.container.jobinstance.RuntimeJobExecution) 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 24 with PersistenceException

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

the class JBatchJDBCPersistenceManager method insertCheckpointData.

/**
 * Insert data to DB table
 *
 * @param key
 *            - the IPersistenceDataKey object
 * @param value
 *            - serializable object to store
 *
 *            Ex. insert into tablename values(?, ?)
 */
protected <T> void insertCheckpointData(Object key, T value) {
    logger.entering(CLASSNAME, "insertCheckpointData", new Object[] { key, value });
    try (Connection connection = getConnection()) {
        try (PreparedStatement statement = connection.prepareStatement(queryStrings.get(INSERT_CHECKPOINTDATA))) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ;
            try (ObjectOutputStream oout = new ObjectOutputStream(baos)) {
                oout.writeObject(value);
                statement.setObject(1, key);
                statement.setBytes(2, baos.toByteArray());
                statement.executeUpdate();
            }
        }
    } catch (SQLException | IOException e) {
        throw new PersistenceException(e);
    }
    logger.exiting(CLASSNAME, "insertCheckpointData");
}
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 25 with PersistenceException

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

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