Search in sources :

Example 41 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateCheckpointData.

/**
 * update data in DB table
 *
 * @param value
 *            - serializable object to store
 * @param key
 *            - the IPersistenceDataKey object
 * @param query
 *            - SQL statement to execute.
 *
 *            Ex. update tablename set obj = ? where id = ?
 */
protected void updateCheckpointData(Object key, CheckpointData value) {
    logger.entering(CLASSNAME, "updateCheckpointData", new Object[] { key, value });
    Connection conn = null;
    PreparedStatement statement = null;
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oout = null;
    byte[] b;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_CHECKPOINTDATA));
        baos = new ByteArrayOutputStream();
        oout = new ObjectOutputStream(baos);
        oout.writeObject(value);
        b = baos.toByteArray();
        statement.setBytes(1, b);
        statement.setObject(2, key);
        statement.executeUpdate();
    } catch (SQLException e) {
        logger.severe(e.getLocalizedMessage());
        throw new PersistenceException(e);
    } catch (IOException e) {
        logger.severe(e.getLocalizedMessage());
        throw new PersistenceException(e);
    } finally {
        if (baos != null) {
            try {
                baos.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        if (oout != null) {
            try {
                oout.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "updateCheckpointData");
}
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 42 with PersistenceException

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

the class JBatchJDBCPersistenceManager method createSubJobInstance.

/*
	 * (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 createSubJobInstance(String name, String apptag) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    JobInstanceImpl jobInstance = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(CREATE_SUB_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);
            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 43 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorQueryJobExecutionBatchStatus.

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

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

the class JBatchJDBCPersistenceManager method updateBatchStatusOnly.

@Override
public void updateBatchStatusOnly(long key, BatchStatus batchStatus, Timestamp updatets) {
    Connection conn = null;
    PreparedStatement statement = null;
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oout = null;
    byte[] b;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_BATCH_STATUS_ONLY));
        statement.setString(1, batchStatus.name());
        statement.setTimestamp(2, updatets);
        statement.setLong(3, key);
        statement.executeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new PersistenceException(e);
    } finally {
        if (baos != null) {
            try {
                baos.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        if (oout != null) {
            try {
                oout.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, null, statement);
    }
}
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 45 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateJobStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#updateJobStatus
	 * (long, com.ibm.jbatch.container.status.JobStatus)
	 */
@Override
public void updateJobStatus(long instanceId, JobStatus jobStatus) {
    logger.entering(CLASSNAME, "updateJobStatus", new Object[] { instanceId, jobStatus });
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Updating Job Status to: " + jobStatus.getBatchStatus());
    }
    Connection conn = null;
    PreparedStatement statement = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_JOBSTATUS));
        statement.setBytes(1, serializeObject(jobStatus));
        statement.setLong(2, instanceId);
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "updateJobStatus");
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

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