Class DefaultDatabasePersistence
- All Implemented Interfaces:
JobPersistence
CREATE TABLE <table_name> ( UUID varchar(250) NOT NULL, TYPE varchar(20) NOT NULL, POSITION int NOT NULL, CONTENT blob NOT NULL, PRIMARY KEY (UUID, TYPE, POSITION) );
Where:
- the UUID column represents the job uuid
- the TYPE column represents the type of object, taken from the
PersistenceObjectTypeenum - the POSITION column represents the object's position in the job if
TYPEis 'task' or 'task_result', otherwise -1 - the CONTENT column represents the serialized object
The table name is specified in the JPPF configuration like this:
jppf.job.persistence = org.jppf.job.persistence.impl.DefaultDatabasePersistence <table_name>
If unspecified, it defaults to the default table name 'JOB_PERSISTENCE'.
If the table does not exist, JPPF will attempt to create it. If this fails for any reason, for instance if the user does not have sufficient privileges,
then persistence will be disabled.
This database persistence implementation uses a HikariCP connection pool and datasource.
The datasource is specified by name in the configuration:
jppf.job.persistence = org.jppf.job.persistence.impl.DefaultDatabasePersistence <table_name> <datasource_name>
If unspecified, it defaults to 'job_persistence'. The datasource properties must be defined in the JPPF configuration like so:
jppf.datasource.<configId>.name = <datasource_name> jppf.datasource.<configId>.<hikaricp_property> = <value>
Where:
configIdis used to distinguish the datasource properties when multiple datasources are defined- the datasource
nameis mandatory and is used to store and retrieve the datasource in a custom registry. It is also the datasource name used in the configuration of this job persistence implementation hikaricp_propertydesginates any valid HikariCP configuration property. Properties not supported by HikariCP are simply ignored
Here is a full example configuration:
# persistence definition jppf.job.persistence = org.jppf.job.persistence.impl.DefaultDatabasePersistence MY_TABLE jobDS # datasource definition jppf.datasource.jobs.name = jobDS jppf.datasource.jobs.driverClassName = com.mysql.jdbc.Driver jppf.datasource.jobs.jdbcUrl = jdbc:mysql://localhost:3306/testjppf jppf.datasource.jobs.username = testjppf jppf.datasource.jobs.password = testjppf jppf.datasource.jobs.minimumIdle = 5 jppf.datasource.jobs.maximumPoolSize = 10 jppf.datasource.jobs.connectionTimeout = 30000 jppf.datasource.jobs.idleTimeout = 600000
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jppf.persistence.AbstractDatabasePersistence
AbstractDatabasePersistence.ConnectionWrapper -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe default persistence table name.protected static final StringThe default persistence table name.Fields inherited from class org.jppf.persistence.AbstractDatabasePersistence
dataSource, dataSourceName, ddlProp, defaultDatasource, defaultTable, EMPTY_STRINGS, sqlStatements, TABLE_PROP, tableName -
Constructor Summary
ConstructorsConstructorDescriptionIntialize this persistence with the default table name.DefaultDatabasePersistence(String... params) Intialize this persistence with a table name specified in the first string parmater. -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete the persisted job with the psecified UUID.Get the UUIDs of all persisted job.int[]getTaskPositions(String jobUuid) Get the positions of all the tasks in the specified job.int[]getTaskResultPositions(String jobUuid) Get the positions of all the task results in the specified job.protected voidinsertElement(Connection connection, PersistenceInfo info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.booleanisJobPersisted(String jobUuid) Determine whether a job is persisted, that is, present in the persistence store.load(Collection<PersistenceInfo> infos) Load the specified job elements.protected booleanlockForUpdate(Connection connection, PersistenceInfo info) Lock the specified row for update, if it existsvoidstore(Collection<PersistenceInfo> infos) Store the specified job elements.protected voidupdateElement(Connection connection, PersistenceInfo info, byte[] bytes) Create a prepared statement which will insert or update an object in the database.Methods inherited from class org.jppf.persistence.AbstractDatabasePersistence
getConnection, getSQL, storeElement, toString
-
Field Details
-
DEFAULT_TABLE
The default persistence table name.- See Also:
-
DEFAULT_DATASOURCE
The default persistence table name.- See Also:
-
-
Constructor Details
-
DefaultDatabasePersistence
Intialize this persistence with the default table name.- Throws:
Exception- if any error occurs.
-
DefaultDatabasePersistence
Intialize this persistence with a table name specified in the first string parmater.- Parameters:
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
-
store
Description copied from interface:JobPersistenceStore the specified job elements. All elements are assumed to be part of the same job.- Specified by:
storein interfaceJobPersistence- Parameters:
infos- collection of information objects on the job elements to store.- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
load
Description copied from interface:JobPersistenceLoad the specified job elements. All elements are assumed to be part of the same job.- Specified by:
loadin interfaceJobPersistence- Parameters:
infos- information on the persisted job elements to load.- Returns:
- an input stream providing the serialized job header.
- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
getPersistedJobUuids
Description copied from interface:JobPersistenceGet the UUIDs of all persisted job.- Specified by:
getPersistedJobUuidsin interfaceJobPersistence- Returns:
- a list of strings reprensenting job UUIDs.
- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
getTaskPositions
Description copied from interface:JobPersistenceGet the positions of all the tasks in the specified job.- Specified by:
getTaskPositionsin interfaceJobPersistence- Parameters:
jobUuid- the uuid of the job for which to find the task positions.- Returns:
- an array of int representing the positions.
- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
getTaskResultPositions
Description copied from interface:JobPersistenceGet the positions of all the task results in the specified job.- Specified by:
getTaskResultPositionsin interfaceJobPersistence- Parameters:
jobUuid- the uuid of the job for which to find the task result positions.- Returns:
- an array of int representing the positions.
- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
deleteJob
Description copied from interface:JobPersistenceDelete the persisted job with the psecified UUID.- Specified by:
deleteJobin interfaceJobPersistence- Parameters:
jobUuid- the UUID of the job to load.- Throws:
JobPersistenceException- if any erorr occurs during the persistence operation.
-
isJobPersisted
Description copied from interface:JobPersistenceDetermine whether a job is persisted, that is, present in the persistence store.- Specified by:
isJobPersistedin interfaceJobPersistence- Parameters:
jobUuid- the UUID of the job to check.- Returns:
trueif the job is in the persistence store,falseotherwise.- Throws:
JobPersistenceException- if any error occurs while accessing the persistence store.
-
lockForUpdate
Description copied from class:AbstractDatabasePersistenceLock the specified row for update, if it exists- Specified by:
lockForUpdatein classAbstractDatabasePersistence<PersistenceInfo>- 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.
-
insertElement
protected void insertElement(Connection connection, PersistenceInfo info, byte[] bytes) throws Exception Description copied from class:AbstractDatabasePersistenceCreate a prepared statement which will insert or update an object in the database.- Specified by:
insertElementin classAbstractDatabasePersistence<PersistenceInfo>- 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 void updateElement(Connection connection, PersistenceInfo info, byte[] bytes) throws Exception Description copied from class:AbstractDatabasePersistenceCreate a prepared statement which will insert or update an object in the database.- Specified by:
updateElementin classAbstractDatabasePersistence<PersistenceInfo>- 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.
-