Class DatabaseJournal
- java.lang.Object
-
- org.apache.jackrabbit.core.journal.AbstractJournal
-
- org.apache.jackrabbit.core.journal.DatabaseJournal
-
- All Implemented Interfaces:
Journal,DatabaseAware
- Direct Known Subclasses:
JNDIDatabaseJournal,MSSqlDatabaseJournal,OracleDatabaseJournal
public class DatabaseJournal extends AbstractJournal implements DatabaseAware
Database-based journal implementation. Stores records inside a database table namedJOURNAL, whereas the tableGLOBAL_REVISIONcontains the highest available revision number. These tables are located inside the schema specified inschemaObjectPrefix.It is configured through the following properties:
driver: the JDBC driver class name to use; this is a required property with no default valueurl: the JDBC connection url; this is a required property with no default valuedatabaseType: the database type to be used; if not specified, this is the second field inside the JDBC connection url, delimited by colonsschemaObjectPrefix: the schema object prefix to be used; defaults to an empty stringuser: username to specify when connectingpassword: password to specify when connectingreconnectDelayMs: number of milliseconds to wait before trying to reconnect to the database.janitorEnabled: specifies whether the clean-up thread for the journal table is enabled (default =false)janitorSleep: specifies the sleep time of the clean-up thread in seconds (only useful when the clean-up thread is enabled, default = 24 * 60 * 60, which equals 24 hours)janitorFirstRunHourOfDay: specifies the hour at which the clean-up thread initiates its first run (default =3which means 3:00 at night)schemaCheckEnabled: whether the schema check during initialization is enabled (default =true)
JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver, and the JNDI name as the URL. If the user and password are configured in the JNDI resource, they should not be configured here. Example JNDI settings:
<param name="driver" value="javax.naming.InitialContext" /> <param name="url" value="java:comp/env/jdbc/Test" />
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDatabaseJournal.DatabaseRevisionThis class manages the local revision of the cluster node.classDatabaseJournal.RevisionTableJanitorClass for maintaining the revision table.
-
Field Summary
Fields Modifier and Type Field Description protected StringcleanRevisionStmtSQLSQL statement removing a set of revisions with from the journal table.protected StringgetLocalRevisionStmtSQLSQL statement returning the local revision of this cluster node.protected StringinsertLocalRevisionStmtSQLSQL statement for inserting the local revision of this cluster node.protected StringinsertRevisionStmtSQLSQL statement appending a new record.protected StringschemaObjectPrefixSchema object prefix, bean property.protected StringselectGlobalStmtSQLSQL statement returning the global revision.protected StringselectMinLocalRevisionStmtSQLSQL statement returning the minimum of the local revisions.protected StringselectRevisionsStmtSQLSQL statement returning all revisions within a range.protected StringupdateGlobalStmtSQLSQL statement updating the global revision.protected StringupdateLocalRevisionStmtSQLSQL statement for updating the local revision of this cluster node.
-
Constructor Summary
Constructors Constructor Description DatabaseJournal()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidappend(AppendRecord record, InputStream in, int length)Append a record backed by a file.protected voidappending(AppendRecord record)Notification method called by an appended record at creation time.protected voidbuildSQLStatements()Builds the SQL statements.voidclose()Close this journal.protected CheckSchemaOperationcreateCheckSchemaOperation()This method is called frominit(String, NamespaceResolver)after thecreateConnectionHelper(DataSource)method, and returns a defaultCheckSchemaOperation.protected ConnectionHelpercreateConnectionHelper(DataSource dataSrc)This method is called from theinit(String, NamespaceResolver)method of this class and returns aConnectionHelperinstance which is assigned to theconHelperfield.protected voiddoLock()Lock the journal revision.protected voiddoSync(long startRevision, boolean startup)Synchronize contents from journal.protected voiddoUnlock(boolean successful)Unlock the journal revision.StringgetDatabaseType()Get the database type.StringgetDataSourceName()StringgetDriver()Bean gettersInstanceRevisiongetInstanceRevision()Gets the instance that manages the cluster node's local revision.booleangetJanitorEnabled()intgetJanitorFirstRunHourOfDay()intgetJanitorSleep()StringgetPassword()RecordIteratorgetRecords()Return an iterator over all available records in the journal.RecordIteratorgetRecords(long startRevision)Return an iterator over all records after the specified revision.StringgetSchema()Deprecated.This method is deprecated;getDatabaseType()should be used instead.StringgetSchemaObjectPrefix()StringgetUrl()StringgetUser()protected voidinit()Completes initialization of this database journal.voidinit(String id, NamespaceResolver resolver)Initialize journal.protected voidinitInstanceRevisionAndJanitor()Initialize the instance revision manager and the janitor thread.booleanisSchemaCheckEnabled()voidsetConnectionFactory(ConnectionFactory connnectionFactory)voidsetDatabaseType(String databaseType)Set the database type.voidsetDataSourceName(String dataSourceName)voidsetDriver(String driver)Bean settersvoidsetJanitorEnabled(boolean enabled)voidsetJanitorFirstRunHourOfDay(int hourOfDay)voidsetJanitorSleep(int sleep)voidsetPassword(String password)voidsetSchema(String databaseType)Deprecated.This method is deprecated;getDatabaseType()should be used instead.voidsetSchemaCheckEnabled(boolean enabled)voidsetSchemaObjectPrefix(String schemaObjectPrefix)voidsetUrl(String url)voidsetUser(String user)-
Methods inherited from class org.apache.jackrabbit.core.journal.AbstractJournal
createProducer, doSync, getConsumer, getId, getNamePathResolver, getProducer, getRepositoryHome, getResolver, getRevision, lockAndSync, register, setInternalVersionManager, setRepositoryHome, setRevision, sync, syncAgainOnNewRecords, unlock, unregister
-
-
-
-
Field Detail
-
selectRevisionsStmtSQL
protected String selectRevisionsStmtSQL
SQL statement returning all revisions within a range.
-
updateGlobalStmtSQL
protected String updateGlobalStmtSQL
SQL statement updating the global revision.
-
selectGlobalStmtSQL
protected String selectGlobalStmtSQL
SQL statement returning the global revision.
-
insertRevisionStmtSQL
protected String insertRevisionStmtSQL
SQL statement appending a new record.
-
selectMinLocalRevisionStmtSQL
protected String selectMinLocalRevisionStmtSQL
SQL statement returning the minimum of the local revisions.
-
cleanRevisionStmtSQL
protected String cleanRevisionStmtSQL
SQL statement removing a set of revisions with from the journal table.
-
getLocalRevisionStmtSQL
protected String getLocalRevisionStmtSQL
SQL statement returning the local revision of this cluster node.
-
insertLocalRevisionStmtSQL
protected String insertLocalRevisionStmtSQL
SQL statement for inserting the local revision of this cluster node.
-
updateLocalRevisionStmtSQL
protected String updateLocalRevisionStmtSQL
SQL statement for updating the local revision of this cluster node.
-
schemaObjectPrefix
protected String schemaObjectPrefix
Schema object prefix, bean property.
-
-
Method Detail
-
setConnectionFactory
public void setConnectionFactory(ConnectionFactory connnectionFactory)
- Specified by:
setConnectionFactoryin interfaceDatabaseAware
-
init
public void init(String id, NamespaceResolver resolver) throws JournalException
Initialize journal.- Specified by:
initin interfaceJournal- Overrides:
initin classAbstractJournal- Parameters:
id- id this journal should use to write its own recordsresolver- resolver used when reading/writing records- Throws:
JournalException- if an error occurs
-
createConnectionHelper
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
This method is called from theinit(String, NamespaceResolver)method of this class and returns aConnectionHelperinstance which is assigned to theconHelperfield. Subclasses may override it to return a specialized connection helper.- Parameters:
dataSrc- theDataSourceof this persistence manager- Returns:
- a
ConnectionHelper - Throws:
Exception- on error
-
createCheckSchemaOperation
protected CheckSchemaOperation createCheckSchemaOperation()
This method is called frominit(String, NamespaceResolver)after thecreateConnectionHelper(DataSource)method, and returns a defaultCheckSchemaOperation. Subclasses can override this implementation to get a customized implementation.- Returns:
- a new
CheckSchemaOperationinstance
-
init
protected void init() throws JournalExceptionCompletes initialization of this database journal. Base implementation checks whether the required bean propertiesdriverandurlhave been specified and optionally deduces a valid database type. Should be overridden by subclasses that use a different way to create a connection and therefore require other arguments.- Throws:
JournalException- if initialization fails
-
initInstanceRevisionAndJanitor
protected void initInstanceRevisionAndJanitor() throws ExceptionInitialize the instance revision manager and the janitor thread.- Throws:
JournalException- on errorException
-
getInstanceRevision
public InstanceRevision getInstanceRevision() throws JournalException
Description copied from interface:JournalGets the instance that manages the cluster node's local revision.- Specified by:
getInstanceRevisionin interfaceJournal- Returns:
- the InstanceRevision manager
- Throws:
JournalException- on error
-
getRecords
public RecordIterator getRecords(long startRevision) throws JournalException
Return an iterator over all records after the specified revision.- Specified by:
getRecordsin interfaceJournal- Parameters:
startRevision- start point (exlusive)- Returns:
- an iterator over all records after the specified revision.
- Throws:
JournalException- if an error occurs
-
getRecords
public RecordIterator getRecords() throws JournalException
Return an iterator over all available records in the journal.- Specified by:
getRecordsin interfaceJournal- Returns:
- an iterator over all records.
- Throws:
JournalException- if an error occurs
-
doSync
protected void doSync(long startRevision, boolean startup) throws JournalExceptionSynchronize contents from journal. May be overridden by subclasses. Do the initial sync in batchMode, since some databases (PSQL) when not in transactional mode, load all results in memory which causes out of memory. See JCR-2832- Overrides:
doSyncin classAbstractJournal- Parameters:
startRevision- start point (exclusive)startup- indicates if the cluster node is syncing on startup or does a normal sync.- Throws:
JournalException- if an error occurs
-
doLock
protected void doLock() throws JournalExceptionLock the journal revision. Subclass responsibility.This journal is locked by incrementing the current value in the table named
GLOBAL_REVISION, which effectively write-locks this table. The updated value is then saved away and remembered in the appended record, because a save may entail multiple appends (JCR-884).- Specified by:
doLockin classAbstractJournal- Throws:
JournalException- if an error occurs
-
doUnlock
protected void doUnlock(boolean successful)
Unlock the journal revision. Subclass responsibility.- Specified by:
doUnlockin classAbstractJournal- Parameters:
successful- flag indicating whether the update process was successful
-
appending
protected void appending(AppendRecord record)
Notification method called by an appended record at creation time. May be overridden by subclasses to save some context information inside the appended record.Save away the locked revision inside the newly appended record.
- Overrides:
appendingin classAbstractJournal- Parameters:
record- record that was appended
-
append
protected void append(AppendRecord record, InputStream in, int length) throws JournalException
Append a record backed by a file. On exit, the new revision must have been set inside the appended record. Subclass responsibility.We have already saved away the revision for this record.
- Specified by:
appendin classAbstractJournal- Parameters:
record- record to appendin- input streamlength- number of bytes in input stream- Throws:
JournalException- if an error occurs
-
close
public void close()
Close this journal. This should release any resources still held by this journal.
-
buildSQLStatements
protected void buildSQLStatements()
Builds the SQL statements. May be overridden by subclasses to allow different table and/or column names.
-
getDriver
public String getDriver()
Bean getters
-
getUrl
public String getUrl()
-
getDatabaseType
public String getDatabaseType()
Get the database type.- Returns:
- the database type
-
getSchema
@Deprecated public String getSchema()
Deprecated.This method is deprecated;getDatabaseType()should be used instead.Get the database type.- Returns:
- the database type
-
getSchemaObjectPrefix
public String getSchemaObjectPrefix()
-
getUser
public String getUser()
-
getPassword
public String getPassword()
-
getJanitorEnabled
public boolean getJanitorEnabled()
-
getJanitorSleep
public int getJanitorSleep()
-
getJanitorFirstRunHourOfDay
public int getJanitorFirstRunHourOfDay()
-
setDriver
public void setDriver(String driver)
Bean setters
-
setUrl
public void setUrl(String url)
-
setDatabaseType
public void setDatabaseType(String databaseType)
Set the database type.- Parameters:
databaseType- the database type
-
setSchema
@Deprecated public void setSchema(String databaseType)
Deprecated.This method is deprecated;getDatabaseType()should be used instead.Set the database type.- Parameters:
databaseType- the database type
-
setSchemaObjectPrefix
public void setSchemaObjectPrefix(String schemaObjectPrefix)
-
setUser
public void setUser(String user)
-
setPassword
public void setPassword(String password)
-
setJanitorEnabled
public void setJanitorEnabled(boolean enabled)
-
setJanitorSleep
public void setJanitorSleep(int sleep)
-
setJanitorFirstRunHourOfDay
public void setJanitorFirstRunHourOfDay(int hourOfDay)
-
getDataSourceName
public String getDataSourceName()
-
setDataSourceName
public void setDataSourceName(String dataSourceName)
-
isSchemaCheckEnabled
public final boolean isSchemaCheckEnabled()
- Returns:
- whether the schema check is enabled
-
setSchemaCheckEnabled
public final void setSchemaCheckEnabled(boolean enabled)
- Parameters:
enabled- set whether the schema check is enabled
-
-