Search in sources :

Example 16 with PersistenceException

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

the class JBatchJDBCPersistenceManager method updateStepStatus.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.jbatch.container.services.IPersistenceManagerService#updateStepStatus
	 * (long, com.ibm.jbatch.container.status.StepStatus)
	 */
@Override
public void updateStepStatus(long stepExecutionId, StepStatus stepStatus) {
    logger.entering(CLASSNAME, "updateStepStatus", new Object[] { stepExecutionId, stepStatus });
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Updating StepStatus to: " + stepStatus.getBatchStatus());
    }
    Connection conn = null;
    PreparedStatement statement = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(queryStrings.get(UPDATE_STEP_STATUS));
        statement.setBytes(1, serializeObject(stepStatus));
        statement.setLong(2, stepExecutionId);
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } catch (IOException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "updateStepStatus");
}
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)

Example 17 with PersistenceException

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

the class JBatchJDBCPersistenceManager method jobOperatorQueryJobExecutionExitStatus.

@Override
public String jobOperatorQueryJobExecutionExitStatus(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_EXIT_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 18 with PersistenceException

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

the class JBatchJDBCPersistenceManager method purge.

@Override
public void purge(String apptag) {
    logger.entering(CLASSNAME, "purge", apptag);
    String deleteJobs = queryStrings.get(DELETE_JOBS);
    String deleteJobExecutions = queryStrings.get(DELETE_JOB_EXECUTIONS);
    String deleteStepExecutions = queryStrings.get(DELETE_STEP_EXECUTIONS);
    Connection conn = null;
    PreparedStatement statement = null;
    try {
        conn = getConnection();
        statement = conn.prepareStatement(deleteStepExecutions);
        statement.setString(1, apptag);
        statement.executeUpdate();
        statement = conn.prepareStatement(deleteJobExecutions);
        statement.setString(1, apptag);
        statement.executeUpdate();
        statement = conn.prepareStatement(deleteJobs);
        statement.setString(1, apptag);
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    } finally {
        cleanupConnection(conn, null, statement);
    }
    logger.exiting(CLASSNAME, "purge");
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Example 19 with PersistenceException

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

the class JBatchJDBCPersistenceManager method getConnectionToDefaultSchema.

/**
 * @return the database connection. The schema is set to whatever default is
 *         used by the datasource.
 * @throws SQLException
 */
protected Connection getConnectionToDefaultSchema() throws SQLException {
    logger.finest("Entering getConnectionToDefaultSchema");
    Connection connection = null;
    logger.finest("Java EE mode, getting connection from data source");
    try {
        connection = dataSource.getConnection();
    } catch (SQLException e) {
        logException("FAILED GETTING DATABASE CONNECTION", e);
        throw new PersistenceException(e);
    }
    logger.finest("autocommit=" + connection.getAutoCommit());
    logger.finest("Exiting from getConnectionToDefaultSchema, conn= " + connection);
    return connection;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException)

Example 20 with PersistenceException

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

the class JBatchJDBCPersistenceManager method cleanupConnection.

/**
 * closes connection, result set and statement
 *
 * @param conn
 *            - connection object to close
 * @param rs
 *            - result set object to close
 * @param statement
 *            - statement object to close
 */
protected void cleanupConnection(Connection conn, ResultSet rs, PreparedStatement statement) {
    logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Entering", new Object[] { conn, rs == null ? "<null>" : rs, statement == null ? "<null>" : statement });
    if (statement != null) {
        try {
            statement.close();
        } catch (SQLException e) {
            throw new PersistenceException(e);
        }
    }
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException e) {
            throw new PersistenceException(e);
        }
    }
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) {
            throw new PersistenceException(e);
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new PersistenceException(e);
            }
        }
    }
    logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Exiting");
}
Also used : SQLException(java.sql.SQLException) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException)

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