org.apache.jackrabbit.core.state.db
Class SimpleDbPersistenceManager

java.lang.Object
  extended byorg.apache.jackrabbit.core.state.AbstractPersistenceManager
      extended byorg.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager
All Implemented Interfaces:
PersistenceManager
Direct Known Subclasses:
DerbyPersistenceManager

public class SimpleDbPersistenceManager
extends AbstractPersistenceManager

SimpleDbPersistenceManager is a generic JDBC-based PersistenceManager for Jackrabbit that persists ItemState and NodeReferences objects using a simple custom binary serialization format (see Serializer) and a very basic non-normalized database schema (in essence tables with one 'key' and one 'data' column).

It is configured through the following properties:

The required schema objects are automatically created by executing the DDL statements read from the [schema].ddl file. The .ddl file is read from the resources by calling getClass().getResourceAsStream(schema + ".ddl"). Every line in the specified .ddl file is executed separatly by calling java.sql.Statement.execute(String) where every occurence of the the string "${schemaObjectPrefix}" has been replaced with the value of the property schemaObjectPrefix.

The following is a fragment from a sample configuration using MySQL:

   <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">
       <param name="driver" value="com.mysql.jdbc.Driver"/>
       <param name="url" value="jdbc:mysql:///test"/>
       <param name="schema" value="mysql"/>
       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
       <param name="externalBLOBs" value="false"/>
   </PersistenceManager>
 
The following is a fragment from a sample configuration using Daffodil One$DB Embedded:
   <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">
       <param name="driver" value="in.co.daffodil.db.jdbc.DaffodilDBDriver"/>
       <param name="url" value="jdbc:daffodilDB_embedded:${wsp.name};path=${wsp.home}/../../databases;create=true"/>
       <param name="user" value="daffodil"/>
       <param name="password" value="daffodil"/>
       <param name="schema" value="daffodil"/>
       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
       <param name="externalBLOBs" value="false"/>
   </PersistenceManager>
 
The following is a fragment from a sample configuration using DB2:
   <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">
       <param name="driver" value="com.ibm.db2.jcc.DB2Driver"/>
       <param name="url" value="jdbc:db2:test"/>
       <param name="schema" value="db2"/>
       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
       <param name="externalBLOBs" value="false"/>
   </PersistenceManager>
 
The following is a fragment from a sample configuration using MSSQL:
   <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">
       <param name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
       <param name="url" value="jdbc:microsoft:sqlserver://localhost:1433;;DatabaseName=test;SelectMethod=Cursor;"/>
       <param name="schema" value="mssql"/>
       <param name="user" value="sa"/>
       <param name="password" value=""/>
       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
       <param name="externalBLOBs" value="false"/>
   </PersistenceManager>
 
The following is a fragment from a sample configuration using PostgreSQL:
   <PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">
       <param name="driver" value="org.postgresql.Driver"/>
       <param name="url" value="jdbc:postgresql://localhost/test"/>
       <param name="schema" value="postgresql"/>
       <param name="user" value="postgres"/>
       <param name="password" value="postgres"/>
       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
       <param name="externalBLOBs" value="false"/>
   </PersistenceManager>
 
See also DerbyPersistenceManager.


Field Summary
protected  PreparedStatement blobDelete
           
protected  FileSystem blobFS
          file system where BLOB data is stored (if externalBLOBs==true)
protected  PreparedStatement blobInsert
           
protected  PreparedStatement blobSelect
           
protected  PreparedStatement blobSelectExist
           
protected  BLOBStore blobStore
          BLOBStore that manages BLOB data in the file system (if externalBLOBs==true)
protected  PreparedStatement blobUpdate
           
protected  Connection con
           
protected  String driver
           
protected  boolean externalBLOBs
           
protected static int INITIAL_BUFFER_SIZE
           
protected  boolean initialized
           
protected  PreparedStatement nodeReferenceDelete
           
protected  PreparedStatement nodeReferenceInsert
           
protected  PreparedStatement nodeReferenceSelect
           
protected  PreparedStatement nodeReferenceSelectExist
           
protected  PreparedStatement nodeReferenceUpdate
           
protected  PreparedStatement nodeStateDelete
           
protected  PreparedStatement nodeStateInsert
           
protected  PreparedStatement nodeStateSelect
           
protected  PreparedStatement nodeStateSelectExist
           
protected  PreparedStatement nodeStateUpdate
           
protected  String password
           
protected  PreparedStatement propertyStateDelete
           
protected  PreparedStatement propertyStateInsert
           
protected  PreparedStatement propertyStateSelect
           
protected  PreparedStatement propertyStateSelectExist
           
protected  PreparedStatement propertyStateUpdate
           
protected  String schema
           
protected static String SCHEMA_OBJECT_PREFIX_VARIABLE
           
protected  String schemaObjectPrefix
           
protected  String url
           
protected  String user
           
 
Constructor Summary
SimpleDbPersistenceManager()
          Creates a new SimpleDbPersistenceManager instance.
 
Method Summary
protected  void checkSchema()
          Checks if the required schema objects exist and creates them if they don't exist yet.
 void close()
          Closes the persistence manager. The consistency of the persistent storage is guaranteed and all acquired resources are released. It is an error to invoke any methods on a closed persistence manager, and implementations are free to enforce this constraint by throwing IllegalStateExceptions in such cases.

An appropriate exception is thrown if the persistence manager could not be closed properly. In this case the state of the persistence manager is undefined and the instance should be discarded.

protected  void closeResultSet(ResultSet rs)
           
protected  void closeStatement(Statement stmt)
           
protected  void closeStream(InputStream in)
           
 void destroy(NodeReferences refs)
          Destroy a node references object. Subclass responsibility.
 void destroy(NodeState state)
          Destroy a node state. Subclass responsibility.
 void destroy(PropertyState state)
          Destroy a property state. Subclass responsibility.
 boolean exists(NodeId id)
          Checks whether the identified node exists.
 boolean exists(NodeReferencesId targetId)
          Checks whether references of the identified target node exist.
 boolean exists(PropertyId id)
          Checks whether the identified property exists.
 String getDriver()
           
 String getPassword()
           
 String getSchema()
           
 String getSchemaObjectPrefix()
           
 String getUrl()
           
 String getUser()
           
 void init(PMContext context)
          Initializes the persistence manager. The persistence manager is permanently bound to the given context, and any required external resources are acquired.

An appropriate exception is thrown if the persistence manager initialization fails for whatever reason. In this case the state of the persistence manager is undefined and the instance should be discarded.

 boolean isExternalBLOBs()
           
 NodeState load(NodeId id)
          Load the persistent members of a node state.
 NodeReferences load(NodeReferencesId targetId)
          Load the persistent members of a node references object.
 PropertyState load(PropertyId id)
          Load the persistent members of a property state.
protected  void logException(String message, SQLException se)
           
protected  void prepareSchemaObjectPrefix()
          Makes sure that schemaObjectPrefix does only consist of characters that are allowed in names on the target database.
protected  void resetStatement(PreparedStatement stmt)
          Resets the given PreparedStatement by clearing the parameters and warnings contained.
 void setDriver(String driver)
           
 void setExternalBLOBs(boolean externalBLOBs)
           
 void setExternalBLOBs(String externalBLOBs)
           
 void setPassword(String password)
           
 void setSchema(String schema)
           
 void setSchemaObjectPrefix(String schemaObjectPrefix)
           
 void setUrl(String url)
           
 void setUser(String user)
           
 void store(ChangeLog changeLog)
          Right now, this iterates over all items in the changelog and calls the individual methods that handle single item states or node references objects. Properly implemented, this method should ensure that changes are either written completely to the underlying persistence layer, or not at all. Atomically saves the given set of changes.
 void store(NodeReferences refs)
          Store a references object. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially.

 void store(NodeState state)
          Store a node state. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially.

 void store(PropertyState state)
          Store a property state. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially.

 
Methods inherited from class org.apache.jackrabbit.core.state.AbstractPersistenceManager
createNew, createNew
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEMA_OBJECT_PREFIX_VARIABLE

protected static final String SCHEMA_OBJECT_PREFIX_VARIABLE
See Also:
Constant Field Values

initialized

protected boolean initialized

driver

protected String driver

url

protected String url

user

protected String user

password

protected String password

schema

protected String schema

schemaObjectPrefix

protected String schemaObjectPrefix

externalBLOBs

protected boolean externalBLOBs

INITIAL_BUFFER_SIZE

protected static final int INITIAL_BUFFER_SIZE
See Also:
Constant Field Values

con

protected Connection con

nodeStateInsert

protected PreparedStatement nodeStateInsert

nodeStateUpdate

protected PreparedStatement nodeStateUpdate

nodeStateSelect

protected PreparedStatement nodeStateSelect

nodeStateSelectExist

protected PreparedStatement nodeStateSelectExist

nodeStateDelete

protected PreparedStatement nodeStateDelete

propertyStateInsert

protected PreparedStatement propertyStateInsert

propertyStateUpdate

protected PreparedStatement propertyStateUpdate

propertyStateSelect

protected PreparedStatement propertyStateSelect

propertyStateSelectExist

protected PreparedStatement propertyStateSelectExist

propertyStateDelete

protected PreparedStatement propertyStateDelete

nodeReferenceInsert

protected PreparedStatement nodeReferenceInsert

nodeReferenceUpdate

protected PreparedStatement nodeReferenceUpdate

nodeReferenceSelect

protected PreparedStatement nodeReferenceSelect

nodeReferenceSelectExist

protected PreparedStatement nodeReferenceSelectExist

nodeReferenceDelete

protected PreparedStatement nodeReferenceDelete

blobInsert

protected PreparedStatement blobInsert

blobUpdate

protected PreparedStatement blobUpdate

blobSelect

protected PreparedStatement blobSelect

blobSelectExist

protected PreparedStatement blobSelectExist

blobDelete

protected PreparedStatement blobDelete

blobFS

protected FileSystem blobFS
file system where BLOB data is stored (if externalBLOBs==true)


blobStore

protected BLOBStore blobStore
BLOBStore that manages BLOB data in the file system (if externalBLOBs==true)

Constructor Detail

SimpleDbPersistenceManager

public SimpleDbPersistenceManager()
Creates a new SimpleDbPersistenceManager instance.

Method Detail

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getUser

public String getUser()

setUser

public void setUser(String user)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

getDriver

public String getDriver()

setDriver

public void setDriver(String driver)

getSchemaObjectPrefix

public String getSchemaObjectPrefix()

setSchemaObjectPrefix

public void setSchemaObjectPrefix(String schemaObjectPrefix)

getSchema

public String getSchema()

setSchema

public void setSchema(String schema)

isExternalBLOBs

public boolean isExternalBLOBs()

setExternalBLOBs

public void setExternalBLOBs(boolean externalBLOBs)

setExternalBLOBs

public void setExternalBLOBs(String externalBLOBs)

init

public void init(PMContext context)
          throws Exception
Initializes the persistence manager. The persistence manager is permanently bound to the given context, and any required external resources are acquired.

An appropriate exception is thrown if the persistence manager initialization fails for whatever reason. In this case the state of the persistence manager is undefined and the instance should be discarded.

Parameters:
context - persistence manager context
Throws:
Exception - if the persistence manager intialization failed

close

public void close()
           throws Exception
Closes the persistence manager. The consistency of the persistent storage is guaranteed and all acquired resources are released. It is an error to invoke any methods on a closed persistence manager, and implementations are free to enforce this constraint by throwing IllegalStateExceptions in such cases.

An appropriate exception is thrown if the persistence manager could not be closed properly. In this case the state of the persistence manager is undefined and the instance should be discarded.

Throws:
Exception - if the persistence manager failed to close properly

store

public void store(ChangeLog changeLog)
           throws ItemStateException
Right now, this iterates over all items in the changelog and calls the individual methods that handle single item states or node references objects. Properly implemented, this method should ensure that changes are either written completely to the underlying persistence layer, or not at all. Atomically saves the given set of changes.

Specified by:
store in interface PersistenceManager
Overrides:
store in class AbstractPersistenceManager
Throws:
ItemStateException

load

public NodeState load(NodeId id)
               throws NoSuchItemStateException,
                      ItemStateException
Load the persistent members of a node state.

Parameters:
id - node id
Returns:
loaded node state
Throws:
NoSuchItemStateException - if the node state does not exist
ItemStateException - if another error occurs

load

public PropertyState load(PropertyId id)
                   throws NoSuchItemStateException,
                          ItemStateException
Load the persistent members of a property state.

Parameters:
id - property id
Returns:
loaded property state
Throws:
NoSuchItemStateException - if the property state does not exist
ItemStateException - if another error occurs

store

public void store(NodeState state)
           throws ItemStateException
Store a node state. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially. Because this method synchronizes on the persistence manager instance there is no need to synchronize on the shared statement. If the method would not be sychronized the shared statements would have to be synchronized.

Specified by:
store in class AbstractPersistenceManager
Parameters:
state - node state to store
Throws:
ItemStateException - if an error occurs

store

public void store(PropertyState state)
           throws ItemStateException
Store a property state. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially. Because this method synchronizes on the persistence manager instance there is no need to synchronize on the shared statement. If the method would not be sychronized the shared statements would have to be synchronized.

Specified by:
store in class AbstractPersistenceManager
Parameters:
state - property state to store
Throws:
ItemStateException - if an error occurs

destroy

public void destroy(NodeState state)
             throws ItemStateException
Destroy a node state. Subclass responsibility.

Specified by:
destroy in class AbstractPersistenceManager
Parameters:
state - node state to destroy
Throws:
ItemStateException - if an error occurs

destroy

public void destroy(PropertyState state)
             throws ItemStateException
Destroy a property state. Subclass responsibility.

Specified by:
destroy in class AbstractPersistenceManager
Parameters:
state - property state to destroy
Throws:
ItemStateException - if an error occurs

load

public NodeReferences load(NodeReferencesId targetId)
                    throws NoSuchItemStateException,
                           ItemStateException
Load the persistent members of a node references object.

Parameters:
targetId - reference target node id
Throws:
ItemStateException - if another error occurs
NoSuchItemStateException - if the target node does not exist

store

public void store(NodeReferences refs)
           throws ItemStateException
Store a references object. Subclass responsibility.

This method uses shared PreparedStatements which must be executed strictly sequentially. Because this method synchronizes on the persistence manager instance there is no need to synchronize on the shared statement. If the method would not be sychronized the shared statements would have to be synchronized.

Specified by:
store in class AbstractPersistenceManager
Parameters:
refs - references object to store
Throws:
ItemStateException - if an error occurs

destroy

public void destroy(NodeReferences refs)
             throws ItemStateException
Destroy a node references object. Subclass responsibility.

Specified by:
destroy in class AbstractPersistenceManager
Parameters:
refs - node references object to destroy
Throws:
ItemStateException - if an error occurs

exists

public boolean exists(NodeId id)
               throws ItemStateException
Checks whether the identified node exists.

Parameters:
id - node id
Returns:
true if the node exists, false otherwise
Throws:
ItemStateException - on persistence manager errors

exists

public boolean exists(PropertyId id)
               throws ItemStateException
Checks whether the identified property exists.

Parameters:
id - property id
Returns:
true if the property exists, false otherwise
Throws:
ItemStateException - on persistence manager errors

exists

public boolean exists(NodeReferencesId targetId)
               throws ItemStateException
Checks whether references of the identified target node exist.

Parameters:
targetId - target node id
Returns:
true if the references exist, false otherwise
Throws:
ItemStateException - on persistence manager errors

resetStatement

protected void resetStatement(PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters and warnings contained.

NOTE: This method MUST be called in a synchronized context as neither this method nor the PreparedStatement instance on which it operates are thread safe.

Parameters:
stmt - The PreparedStatement to reset. If null this method does nothing.

closeResultSet

protected void closeResultSet(ResultSet rs)

closeStream

protected void closeStream(InputStream in)

closeStatement

protected void closeStatement(Statement stmt)

logException

protected void logException(String message,
                            SQLException se)

prepareSchemaObjectPrefix

protected void prepareSchemaObjectPrefix()
                                  throws Exception
Makes sure that schemaObjectPrefix does only consist of characters that are allowed in names on the target database. Illegal characters will be escaped as necessary.

Throws:
Exception - if an error occurs

checkSchema

protected void checkSchema()
                    throws Exception
Checks if the required schema objects exist and creates them if they don't exist yet.

Throws:
Exception - if an error occurs


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