Package org.jppf.persistence
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
A persistence implementation which stores data in a single database table.
- Since:
- 6.0
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA wrapper for a connection and some of its characteristics. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DataSourceThe JDBC datasource.protected StringThe name of the datasource to use.protected final JPPFProperty<String>The property from which to get the location of the DDL file.protected final StringThe default persistence table name.protected final StringThe default persistence table name.protected static final String[]Constant for an empty array of strings.protected TypedPropertiesThe SQL statements used by this persistence implementation, loaded from a properties file in the classpath.protected static final StringThe porperty for the persistence table name.protected StringThe name of the DB table to use. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDatabasePersistence(String defaultTable, String defaultDatasource, JPPFProperty<String> ddlProp, String... params) Intialize this persistence with a table name specified in the first string parameter. -
Method Summary
Modifier and TypeMethodDescriptiongetConnection(boolean autocommit, int isolation) Get a connection and set its characteristics, which will be restored to their original values upon close.protected StringGet the SQL statement or query for the specified key.protected abstract voidinsertElement(Connection connection, I info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.protected abstract booleanlockForUpdate(Connection connection, I info) Lock the specified row for update, if it existsprotected voidstoreElement(Connection connection, I info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.toString()protected abstract voidupdateElement(Connection connection, I info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.
-
Field Details
-
EMPTY_STRINGS
Constant for an empty array of strings. -
defaultTable
The default persistence table name. -
defaultDatasource
The default persistence table name. -
TABLE_PROP
The porperty for the persistence table name.- See Also:
-
dataSource
The JDBC datasource. -
sqlStatements
The SQL statements used by this persistence implementation, loaded from a properties file in the classpath. -
tableName
The name of the DB table to use. -
dataSourceName
The name of the datasource to use. -
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
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:
trueif the row already exists (and therefore a lock is acquired),falseotherwise.- Throws:
Exception- if any error occurs.
-
storeElement
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
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
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
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
nullif the key could not be found.
-
toString
-
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.ConnectionWrapperwrapping the actual JDBC connection. - Throws:
Exception- if any error occurs.
-