org.apache.jackrabbit.core.journal
Class DatabaseJournal

java.lang.Object
  extended by org.apache.jackrabbit.core.journal.AbstractJournal
      extended by 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 named 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:


Nested Class Summary
 class DatabaseJournal.DatabaseRevision
          This class manages the local revision of the cluster node.
 class DatabaseJournal.RevisionTableJanitor
          Class for maintaining the revision table.
 
Field Summary
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
DatabaseJournal()
           
 
Method Summary
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 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)
           
 
Methods inherited from class org.apache.jackrabbit.core.journal.AbstractJournal
createProducer, doSync, getConsumer, getId, getNamePathResolver, getProducer, getRepositoryHome, getResolver, getRevision, lockAndSync, register, setRepositoryHome, setRevision, sync, unlock, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Constructor Detail

DatabaseJournal

public DatabaseJournal()
Method Detail

setConnectionFactory

public void setConnectionFactory(ConnectionFactory connnectionFactory)

Specified by:
setConnectionFactory in interface DatabaseAware

init

public void init(String id,
                 NamespaceResolver resolver)
          throws JournalException
Initialize journal.

Specified by:
init in interface Journal
Overrides:
init in class AbstractJournal
Parameters:
id - id this journal should use to write its own records
resolver - 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 the 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.

Parameters:
dataSrc - the DataSource of this persistence manager
Returns:
a ConnectionHelper
Throws:
Exception - on error

createCheckSchemaOperation

protected CheckSchemaOperation createCheckSchemaOperation()
This method is called from init(String, NamespaceResolver) after the createConnectionHelper(DataSource) method, and returns a default CheckSchemaOperation. Subclasses can overrride 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 properties 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.

Throws:
JournalException - if initialization fails
See Also:
#getConnection()

initInstanceRevisionAndJanitor

protected void initInstanceRevisionAndJanitor()
                                       throws Exception
Initialize the instance revision manager and the janitor thread.

Throws:
JournalException - on error
Exception

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 interface Journal
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 interface Journal
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 interface Journal
Returns:
an iterator over all records.
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 class AbstractJournal
Throws:
JournalException - if an error occurs

doUnlock

protected void doUnlock(boolean successful)
Unlock the journal revision. Subclass responsibility.

Specified by:
doUnlock in class AbstractJournal
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 class AbstractJournal
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 class AbstractJournal
Parameters:
record - record to append
in - input stream
length - 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.

Specified by:
close in interface 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

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

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


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.