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;
}
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);
}
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;
}
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");
}
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;
}
Aggregations