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_REVISION
contains 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 =3
which 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 class
DatabaseJournal.DatabaseRevision
This class manages the local revision of the cluster node.class
DatabaseJournal.RevisionTableJanitor
Class for maintaining the revision table.
-
Field Summary
Fields Modifier and Type Field Description protected String
cleanRevisionStmtSQL
SQL statement removing a set of revisions with from the journal table.protected String
getLocalRevisionStmtSQL
SQL statement returning the local revision of this cluster node.protected String
insertLocalRevisionStmtSQL
SQL statement for inserting the local revision of this cluster node.protected String
insertRevisionStmtSQL
SQL statement appending a new record.protected String
schemaObjectPrefix
Schema object prefix, bean property.protected String
selectGlobalStmtSQL
SQL statement returning the global revision.protected String
selectMinLocalRevisionStmtSQL
SQL statement returning the minimum of the local revisions.protected String
selectRevisionsStmtSQL
SQL statement returning all revisions within a range.protected String
updateGlobalStmtSQL
SQL statement updating the global revision.protected String
updateLocalRevisionStmtSQL
SQL 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 void
append(AppendRecord record, InputStream in, int length)
Append a record backed by a file.protected void
appending(AppendRecord record)
Notification method called by an appended record at creation time.protected void
buildSQLStatements()
Builds the SQL statements.void
close()
Close this journal.protected CheckSchemaOperation
createCheckSchemaOperation()
This method is called frominit(String, NamespaceResolver)
after thecreateConnectionHelper(DataSource)
method, and returns a defaultCheckSchemaOperation
.protected ConnectionHelper
createConnectionHelper(DataSource dataSrc)
This method is called from theinit(String, NamespaceResolver)
method of this class and returns aConnectionHelper
instance which is assigned to theconHelper
field.protected void
doLock()
Lock the journal revision.protected void
doSync(long startRevision, boolean startup)
Synchronize contents from journal.protected void
doUnlock(boolean successful)
Unlock the journal revision.String
getDatabaseType()
Get the database type.String
getDataSourceName()
String
getDriver()
Bean gettersInstanceRevision
getInstanceRevision()
Gets the instance that manages the cluster node's local revision.boolean
getJanitorEnabled()
int
getJanitorFirstRunHourOfDay()
int
getJanitorSleep()
String
getPassword()
RecordIterator
getRecords()
Return an iterator over all available records in the journal.RecordIterator
getRecords(long startRevision)
Return an iterator over all records after the specified revision.String
getSchema()
Deprecated.This method is deprecated;getDatabaseType()
should be used instead.String
getSchemaObjectPrefix()
String
getUrl()
String
getUser()
protected void
init()
Completes initialization of this database journal.void
init(String id, NamespaceResolver resolver)
Initialize journal.protected void
initInstanceRevisionAndJanitor()
Initialize the instance revision manager and the janitor thread.boolean
isSchemaCheckEnabled()
void
setConnectionFactory(ConnectionFactory connnectionFactory)
void
setDatabaseType(String databaseType)
Set the database type.void
setDataSourceName(String dataSourceName)
void
setDriver(String driver)
Bean settersvoid
setJanitorEnabled(boolean enabled)
void
setJanitorFirstRunHourOfDay(int hourOfDay)
void
setJanitorSleep(int sleep)
void
setPassword(String password)
void
setSchema(String databaseType)
Deprecated.This method is deprecated;getDatabaseType()
should be used instead.void
setSchemaCheckEnabled(boolean enabled)
void
setSchemaObjectPrefix(String schemaObjectPrefix)
void
setUrl(String url)
void
setUser(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:
setConnectionFactory
in interfaceDatabaseAware
-
init
public void init(String id, NamespaceResolver resolver) throws JournalException
Initialize journal.- Specified by:
init
in interfaceJournal
- Overrides:
init
in 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 aConnectionHelper
instance which is assigned to theconHelper
field. Subclasses may override it to return a specialized connection helper.- Parameters:
dataSrc
- theDataSource
of 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
CheckSchemaOperation
instance
-
init
protected void init() throws JournalException
Completes initialization of this database journal. Base implementation checks whether the required bean propertiesdriver
andurl
have 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 Exception
Initialize the instance revision manager and the janitor thread.- Throws:
JournalException
- on errorException
-
getInstanceRevision
public InstanceRevision getInstanceRevision() throws JournalException
Description copied from interface:Journal
Gets the instance that manages the cluster node's local revision.- Specified by:
getInstanceRevision
in 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:
getRecords
in 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:
getRecords
in interfaceJournal
- Returns:
- an iterator over all records.
- Throws:
JournalException
- if an error occurs
-
doSync
protected void doSync(long startRevision, boolean startup) throws JournalException
Synchronize 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:
doSync
in 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 JournalException
Lock 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:
doLock
in classAbstractJournal
- Throws:
JournalException
- if an error occurs
-
doUnlock
protected void doUnlock(boolean successful)
Unlock the journal revision. Subclass responsibility.- Specified by:
doUnlock
in 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:
appending
in 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:
append
in 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
-
-