public class DatabaseJournal extends AbstractJournal implements DatabaseAware
JOURNAL
, whereas the table GLOBAL_REVISION
contains the
highest available revision number. These tables are located inside the schema specified
in schemaObjectPrefix
.
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 value databaseType
: 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" />
Modifier and Type | Class and Description |
---|---|
class |
DatabaseJournal.DatabaseRevision
This class manages the local revision of the cluster node.
|
class |
DatabaseJournal.RevisionTableJanitor
Class for maintaining the revision table.
|
Modifier and Type | Field and 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 and Description |
---|
DatabaseJournal() |
Modifier and Type | Method and 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 from
init(String, NamespaceResolver) after the
createConnectionHelper(DataSource) method, and returns a default CheckSchemaOperation . |
protected ConnectionHelper |
createConnectionHelper(DataSource dataSrc)
This method is called from the
init(String, NamespaceResolver) method of this class and
returns a ConnectionHelper instance which is assigned to the conHelper 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 getters
|
InstanceRevision |
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 setters
|
void |
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) |
createProducer, doSync, getConsumer, getId, getNamePathResolver, getProducer, getRepositoryHome, getResolver, getRevision, lockAndSync, register, setInternalVersionManager, setRepositoryHome, setRevision, sync, syncAgainOnNewRecords, unlock, unregister
protected String selectRevisionsStmtSQL
protected String updateGlobalStmtSQL
protected String selectGlobalStmtSQL
protected String insertRevisionStmtSQL
protected String selectMinLocalRevisionStmtSQL
protected String cleanRevisionStmtSQL
protected String getLocalRevisionStmtSQL
protected String insertLocalRevisionStmtSQL
protected String updateLocalRevisionStmtSQL
protected String schemaObjectPrefix
public void setConnectionFactory(ConnectionFactory connnectionFactory)
setConnectionFactory
in interface DatabaseAware
public void init(String id, NamespaceResolver resolver) throws JournalException
init
in interface Journal
init
in class AbstractJournal
id
- id this journal should use to write its own recordsresolver
- resolver used when reading/writing recordsJournalException
- if an error occursprotected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
init(String, NamespaceResolver)
method of this class and
returns a ConnectionHelper
instance which is assigned to the conHelper
field.
Subclasses may override it to return a specialized connection helper.dataSrc
- the DataSource
of this persistence managerConnectionHelper
Exception
- on errorprotected CheckSchemaOperation createCheckSchemaOperation()
init(String, NamespaceResolver)
after the
createConnectionHelper(DataSource)
method, and returns a default CheckSchemaOperation
.
Subclasses can override this implementation to get a customized implementation.CheckSchemaOperation
instanceprotected void init() throws JournalException
driver
and
url
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.JournalException
- if initialization failsprotected void initInstanceRevisionAndJanitor() throws Exception
JournalException
- on errorException
public InstanceRevision getInstanceRevision() throws JournalException
Journal
getInstanceRevision
in interface Journal
JournalException
- on errorpublic RecordIterator getRecords(long startRevision) throws JournalException
getRecords
in interface Journal
startRevision
- start point (exlusive)JournalException
- if an error occurspublic RecordIterator getRecords() throws JournalException
getRecords
in interface Journal
JournalException
- if an error occursprotected void doSync(long startRevision, boolean startup) throws JournalException
doSync
in class AbstractJournal
startRevision
- start point (exclusive)startup
- indicates if the cluster node is syncing on startup
or does a normal sync.JournalException
- if an error occursprotected void doLock() throws JournalException
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).
doLock
in class AbstractJournal
JournalException
- if an error occursprotected void doUnlock(boolean successful)
doUnlock
in class AbstractJournal
successful
- flag indicating whether the update process was
successfulprotected void appending(AppendRecord record)
Save away the locked revision inside the newly appended record.
appending
in class AbstractJournal
record
- record that was appendedprotected void append(AppendRecord record, InputStream in, int length) throws JournalException
We have already saved away the revision for this record.
append
in class AbstractJournal
record
- record to appendin
- input streamlength
- number of bytes in input streamJournalException
- if an error occurspublic void close()
protected void buildSQLStatements()
public String getDriver()
public String getUrl()
public String getDatabaseType()
public String getSchema()
getDatabaseType()
should be used instead.public String getSchemaObjectPrefix()
public String getUser()
public String getPassword()
public boolean getJanitorEnabled()
public int getJanitorSleep()
public int getJanitorFirstRunHourOfDay()
public void setDriver(String driver)
public void setUrl(String url)
public void setDatabaseType(String databaseType)
databaseType
- the database typepublic void setSchema(String databaseType)
getDatabaseType()
should be used instead.databaseType
- the database typepublic void setSchemaObjectPrefix(String schemaObjectPrefix)
public void setUser(String user)
public void setPassword(String password)
public void setJanitorEnabled(boolean enabled)
public void setJanitorSleep(int sleep)
public void setJanitorFirstRunHourOfDay(int hourOfDay)
public String getDataSourceName()
public void setDataSourceName(String dataSourceName)
public final boolean isSchemaCheckEnabled()
public final void setSchemaCheckEnabled(boolean enabled)
enabled
- set whether the schema check is enabledCopyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.