Class AbstractDatabasePersistence<I>

java.lang.Object
org.jppf.persistence.AbstractDatabasePersistence<I>
Type Parameters:
I - the type of data to persist.
Direct Known Subclasses:
DatabaseLoadBalancerPersistence, DefaultDatabasePersistence

public abstract class AbstractDatabasePersistence<I> extends Object
A persistence implementation which stores data in a single database table.
Since:
6.0
Author:
Laurent Cohen
  • Field Details

    • EMPTY_STRINGS

      protected static final String[] EMPTY_STRINGS
      Constant for an empty array of strings.
    • defaultTable

      protected final String defaultTable
      The default persistence table name.
    • defaultDatasource

      protected final String defaultDatasource
      The default persistence table name.
    • TABLE_PROP

      protected static final String TABLE_PROP
      The porperty for the persistence table name.
      See Also:
    • dataSource

      protected final DataSource dataSource
      The JDBC datasource.
    • sqlStatements

      protected TypedProperties sqlStatements
      The SQL statements used by this persistence implementation, loaded from a properties file in the classpath.
    • tableName

      protected String tableName
      The name of the DB table to use.
    • dataSourceName

      protected String dataSourceName
      The name of the datasource to use.
    • ddlProp

      protected final JPPFProperty<String> ddlProp
      The property from which to get the location of the DDL file.
  • Constructor Details

    • AbstractDatabasePersistence

      public AbstractDatabasePersistence(String defaultTable, String defaultDatasource, JPPFProperty<String> ddlProp, String... params) throws Exception
      Intialize this persistence with a table name specified in the first string parameter.
      Parameters:
      defaultTable - the default table name.
      defaultDatasource - the default datasource name.
      ddlProp - the property from which to get the location of the DDL file.
      params - if parameters are provided, they have this meaning:
      • params[0] is the table name, which defaults to 'JOB_PERSISTENCE'
      • params[1] is the name of a datasource defined in the configuration, and defaults to 'job_persistence'
      Throws:
      Exception - if any error occurs.
  • Method Details

    • lockForUpdate

      protected abstract boolean lockForUpdate(Connection connection, I info) throws Exception
      Lock the specified row for update, if it exists
      Parameters:
      connection - the JDBC connection with which to create an dexecute the query.
      info - the job element corresponding to the SQL row to lock.
      Returns:
      true if the row already exists (and therefore a lock is acquired), false otherwise.
      Throws:
      Exception - if any error occurs.
    • storeElement

      protected void storeElement(Connection connection, I info, byte[] bytes) throws Exception
      Create a prepared statement which will insert or update an object in the database.
      Parameters:
      connection - the JDBC connection with which to create an dexecute the statement.
      info - the information on the object to persist.
      bytes - the serialized data, may be null.
      Throws:
      Exception - if any error occurs.
    • insertElement

      protected abstract void insertElement(Connection connection, I info, byte[] bytes) throws Exception
      Create a prepared statement which will insert or update an object in the database.
      Parameters:
      connection - the JDBC connection with which to create an dexecute the statement.
      info - the information on the object to persist.
      bytes - the serialized object to persist.
      Throws:
      Exception - if any error occurs.
    • updateElement

      protected abstract void updateElement(Connection connection, I info, byte[] bytes) throws Exception
      Create a prepared statement which will insert or update an object in the database.
      Parameters:
      connection - the JDBC connection with which to create an dexecute the statement.
      info - the information on the object to persist.
      bytes - the serialized object to persist.
      Throws:
      Exception - if any error occurs.
    • getSQL

      protected String getSQL(String key)
      Get the SQL statement or query for the specified key.
      Parameters:
      key - the key for the sqkl to retrieve.
      Returns:
      a string containing an SQL statement or query, opr null if the key could not be found.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getConnection

      protected AbstractDatabasePersistence.ConnectionWrapper getConnection(boolean autocommit, int isolation) throws Exception
      Get a connection and set its characteristics, which will be restored to their original values upon close.
      Parameters:
      autocommit - the connection's autocommit flag to set.
      isolation - the connection's transaction isolation level to set.
      Returns:
      a AbstractDatabasePersistence.ConnectionWrapper wrapping the actual JDBC connection.
      Throws:
      Exception - if any error occurs.