Search in sources :

Example 1 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetJobInstanceCount.

@Override
public int jobOperatorGetJobInstanceCount(String jobName, String appTag) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    int count;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOBOPERATOR_GET_JOB_INSTANCE_COUNT));
        statement.setString(1, jobName);
        statement.setString(2, appTag);
        rs = statement.executeQuery();
        rs.next();
        count = rs.getInt("jobinstancecount");
    } catch (SQLException e) {
        logger.severe(e.getLocalizedMessage());
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    return count;
}
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 2 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorQueryJobExecutionTimestamp.

@Override
public Timestamp jobOperatorQueryJobExecutionTimestamp(long key, TimestampType timestampType) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    Timestamp createTimestamp = null;
    Timestamp endTimestamp = null;
    Timestamp updateTimestamp = null;
    Timestamp startTimestamp = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_QUERY_JOB_EXECUTION_TIMESTAMP));
        statement.setObject(1, key);
        rs = statement.executeQuery();
        while (rs.next()) {
            createTimestamp = rs.getTimestamp(1);
            endTimestamp = rs.getTimestamp(2);
            updateTimestamp = rs.getTimestamp(3);
            startTimestamp = rs.getTimestamp(4);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    if (timestampType.equals(TimestampType.CREATE)) {
        return createTimestamp;
    } else if (timestampType.equals(TimestampType.END)) {
        return endTimestamp;
    } else if (timestampType.equals(TimestampType.LAST_UPDATED)) {
        return updateTimestamp;
    } else if (timestampType.equals(TimestampType.STARTED)) {
        return startTimestamp;
    } else {
        throw new IllegalArgumentException("Unexpected enum value.");
    }
}
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) Timestamp(java.sql.Timestamp)

Example 3 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorGetJobExecution.

@Override
public IJobExecution jobOperatorGetJobExecution(long jobExecutionId) {
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    IJobExecution jobEx = null;
    ObjectInputStream objectIn = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_GET_JOB_EXECUTION));
        statement.setLong(1, jobExecutionId);
        rs = statement.executeQuery();
        jobEx = (rs.next()) ? readJobExecutionRecord(rs) : null;
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e);
    } finally {
        if (objectIn != null) {
            try {
                objectIn.close();
            } catch (IOException e) {
                throw new PersistenceException(e);
            }
        }
        cleanupConnection(conn, rs, statement);
    }
    return jobEx;
}
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) IOException(java.io.IOException) IJobExecution(com.ibm.jbatch.container.services.IJobExecution) ObjectInputStream(java.io.ObjectInputStream) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream)

Example 4 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getTagName.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#getTagName
	 * (long)
	 */
@Override
public String getTagName(long jobExecutionId) {
    logger.entering(CLASSNAME, "getTagName", jobExecutionId);
    String apptag = null;
    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    String query = queryStrings.get(GET_TAGNAME);
    try {
        conn = getConnection();
        statement = conn.prepareStatement(query);
        statement.setLong(1, jobExecutionId);
        rs = statement.executeQuery();
        if (rs.next()) {
            apptag = rs.getString(1);
        }
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, rs, statement);
    }
    logger.exiting(CLASSNAME, "getTagName");
    return apptag;
}
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 5 with PersistenceException

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

the class JBatchJDBCPersistenceManager method queryCheckpointData.

/**
 * select data from DB table
 *
 * @param key
 *            - the IPersistenceDataKey object
 * @return List of serializable objects store in the DB table
 *
 *         Ex. select id, obj from tablename where id = ?
 */
protected CheckpointData queryCheckpointData(Object key) {
    logger.entering(CLASSNAME, "queryCheckpointData", new Object[] { key, SELECT_CHECKPOINTDATA });
    CheckpointData data = null;
    try (Connection connection = getConnection()) {
        try (PreparedStatement statement = connection.prepareStatement(queryStrings.get(SELECT_CHECKPOINTDATA))) {
            statement.setObject(1, key);
            ResultSet resultSet = statement.executeQuery();
            if (resultSet.next()) {
                data = (CheckpointData) deserializeObject(resultSet.getBytes("obj"));
            }
        }
    } catch (SQLException | IOException | ClassNotFoundException e) {
        throw new PersistenceException(e);
    }
    logger.exiting(CLASSNAME, "queryCheckpointData");
    return data;
}
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) CheckpointData(com.ibm.jbatch.container.persistence.CheckpointData) 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