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
Direct Known Subclasses:
JNDIDatabaseJournal, MSSqlDatabaseJournal, OracleDatabaseJournal

public class DatabaseJournal
extends AbstractJournal

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:


Field Summary
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 selectRevisionsStmtSQL
          SQL statement returning all revisions within a range.
protected  String updateGlobalStmtSQL
          SQL statement updating the global revision.
 
Constructor Summary
DatabaseJournal()
           
 
Method Summary
protected  void append(AppendRecord record, InputStream in, int length)
          Append a record backed by a file.

We have already saved away the revision for this record.

protected  void appending(AppendRecord record)
          Notification method called by an appended record at creation time.

Save away the locked revision inside the newly appended record.

protected  void buildSQLStatements()
          Builds the SQL statements.
 void close()
          Close this journal.
protected  String createSchemaSQL(String sql)
          Creates an SQL statement for schema creation by variable substitution.
protected  void doLock()
          Lock the journal revision.

This journal is locked by incrementing the current value in the table named GLOBAL_REVISION, which effectively write-locks this table.

protected  void doUnlock(boolean successful)
          Unlock the journal revision.
protected  Connection getConnection()
          Creates a new database connection.
 String getDriver()
          Bean getters
 String getPassword()
           
 long getReconnectDelayMs()
           
protected  RecordIterator getRecords(long startRevision)
          Return an iterator over all records after the specified revision.
 String getSchema()
           
 String getSchemaObjectPrefix()
           
 String getUrl()
           
 String getUser()
           
protected  void init()
          Completes initialization of this database journal.
 void init(String id, NamespaceResolver resolver)
          Initialize journal.
protected  boolean schemaExists(DatabaseMetaData metaData)
          Checks whether the required table(s) exist in the schema.
 void setDriver(String driver)
          Bean setters
 void setPassword(String password)
           
 void setReconnectDelayMs(long reconnectDelayMs)
           
 void setSchema(String schema)
           
 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, getResolver, lockAndSync, register, 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.


schemaObjectPrefix

protected String schemaObjectPrefix
Schema object prefix, bean property.

Constructor Detail

DatabaseJournal

public DatabaseJournal()
Method Detail

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

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 schema. 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()

getConnection

protected Connection getConnection()
                            throws SQLException
Creates a new database connection. This method is called inside #init(String, org.apache.jackrabbit.name.NamespaceResolver) or when a connection has been dropped and must be reacquired. Base implementation uses java.sql.DriverManager to get the connection. May be overridden by subclasses.

Returns:
new connection
Throws:
SQLException - if an error occurs
See Also:
init()

getRecords

protected RecordIterator getRecords(long startRevision)
                             throws JournalException
Return an iterator over all records after the specified revision. Subclass responsibility.

Specified by:
getRecords in class AbstractJournal
Parameters:
startRevision - start point (exlusive)
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.


schemaExists

protected boolean schemaExists(DatabaseMetaData metaData)
                        throws SQLException
Checks whether the required table(s) exist in the schema. May be overridden by subclasses to allow different table names.

Parameters:
metaData - database meta data
Returns:
true if the schema exists
Throws:
SQLException - if an SQL error occurs

createSchemaSQL

protected String createSchemaSQL(String sql)
Creates an SQL statement for schema creation by variable substitution.

Parameters:
sql - a SQL string which may contain variables to substitute
Returns:
a valid SQL string

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()

getSchema

public String getSchema()

getSchemaObjectPrefix

public String getSchemaObjectPrefix()

getUser

public String getUser()

getPassword

public String getPassword()

getReconnectDelayMs

public long getReconnectDelayMs()

setDriver

public void setDriver(String driver)
Bean setters


setUrl

public void setUrl(String url)

setSchema

public void setSchema(String schema)

setSchemaObjectPrefix

public void setSchemaObjectPrefix(String schemaObjectPrefix)

setUser

public void setUser(String user)

setPassword

public void setPassword(String password)

setReconnectDelayMs

public void setReconnectDelayMs(long reconnectDelayMs)


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