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:
BLOBStore, PersistenceManager
Direct Known Subclasses:
DerbyPersistenceManager

public class SimpleDbPersistenceManager
extends AbstractPersistenceManager
implements BLOBStore

SimpleDbPersistenceManager is a generic JDBC-based PersistenceManager for Jackrabbit that persists ItemState and NodeReferences objects using a simple custom serialization format 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}_"/>
  </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}_"/>
  </PersistenceManager>
 


Field Summary
protected  FileSystem blobFS
          file system where BLOB data is stored
protected  Connection con
           
protected  String driver
           
protected static int INITIAL_BUFFER_SIZE
           
protected  boolean initialized
           
protected  PreparedStatement nodeReferenceDelete
           
protected  PreparedStatement nodeReferenceInsert
           
protected  PreparedStatement nodeReferenceSelect
           
protected  PreparedStatement nodeReferenceUpdate
           
protected  PreparedStatement nodeStateDelete
           
protected  PreparedStatement nodeStateInsert
           
protected  PreparedStatement nodeStateSelect
           
protected  PreparedStatement nodeStateUpdate
           
protected  String password
           
protected  PreparedStatement propertyStateDelete
           
protected  PreparedStatement propertyStateInsert
           
protected  PreparedStatement propertyStateSelect
           
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 static String buildBlobFilePath(String parentUUID, QName propName, int index)
           
protected  void checkSchema()
          Checks if the required schema objects exist and creates them if they don't exist yet.
 void close()
          
protected  void closeResultSet(ResultSet rs)
           
protected  void closeStatement(Statement stmt)
           
protected  void closeStream(InputStream in)
           
 void destroy(NodeReferences refs)
          
 void destroy(NodeState state)
          
 void destroy(PropertyState state)
          
 boolean exists(NodeId id)
          
 boolean exists(NodeReferencesId targetId)
          
 boolean exists(PropertyId id)
          
 FileSystemResource get(String blobId)
          
 String getDriver()
           
 String getPassword()
           
 String getSchema()
           
 String getSchemaObjectPrefix()
           
 String getUrl()
           
 String getUser()
           
 void init(PMContext context)
          
 NodeState load(NodeId id)
          
 NodeReferences load(NodeReferencesId targetId)
          
 PropertyState load(PropertyId id)
          
protected  void logException(String message, SQLException se)
           
 String put(PropertyId id, int index, InputStream in, long size)
          
 boolean remove(String blobId)
          
protected  void resetStatement(PreparedStatement stmt)
          Resets the given PreparedStatement by clearing the parameters and warnings contained.
 void setDriver(String driver)
           
 void setPassword(String password)
           
 void setSchema(String schema)
           
 void setSchemaObjectPrefix(String schemaObjectPrefix)
           
 void setUrl(String url)
           
 void setUser(String user)
           
 void store(ChangeLog changeLog)
          
 void store(NodeReferences refs)
          

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

 void store(NodeState state)
          

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

 void store(PropertyState state)
          

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

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

nodeStateDelete

protected PreparedStatement nodeStateDelete

propertyStateInsert

protected PreparedStatement propertyStateInsert

propertyStateUpdate

protected PreparedStatement propertyStateUpdate

propertyStateSelect

protected PreparedStatement propertyStateSelect

propertyStateDelete

protected PreparedStatement propertyStateDelete

nodeReferenceInsert

protected PreparedStatement nodeReferenceInsert

nodeReferenceUpdate

protected PreparedStatement nodeReferenceUpdate

nodeReferenceSelect

protected PreparedStatement nodeReferenceSelect

nodeReferenceDelete

protected PreparedStatement nodeReferenceDelete

blobFS

protected FileSystem blobFS
file system where BLOB data is stored

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)

get

public FileSystemResource get(String blobId)
                       throws Exception

Specified by:
get in interface BLOBStore
Throws:
Exception

put

public String put(PropertyId id,
                  int index,
                  InputStream in,
                  long size)
           throws Exception

Specified by:
put in interface BLOBStore
Throws:
Exception

remove

public boolean remove(String blobId)
               throws Exception

Specified by:
remove in interface BLOBStore
Throws:
Exception

init

public void init(PMContext context)
          throws Exception

Specified by:
init in interface PersistenceManager
Throws:
Exception

close

public void close()
           throws Exception

Specified by:
close in interface PersistenceManager
Throws:
Exception

store

public void store(ChangeLog changeLog)
           throws ItemStateException

Specified by:
store in interface PersistenceManager
Throws:
ItemStateException

load

public NodeState load(NodeId id)
               throws NoSuchItemStateException,
                      ItemStateException

Specified by:
load in interface PersistenceManager
Throws:
NoSuchItemStateException
ItemStateException

load

public PropertyState load(PropertyId id)
                   throws NoSuchItemStateException,
                          ItemStateException

Specified by:
load in interface PersistenceManager
Throws:
NoSuchItemStateException
ItemStateException

store

public void store(NodeState state)
           throws ItemStateException

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.

Throws:
ItemStateException

store

public void store(PropertyState state)
           throws ItemStateException

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.

Throws:
ItemStateException

destroy

public void destroy(NodeState state)
             throws ItemStateException

Throws:
ItemStateException

destroy

public void destroy(PropertyState state)
             throws ItemStateException

Throws:
ItemStateException

load

public NodeReferences load(NodeReferencesId targetId)
                    throws NoSuchItemStateException,
                           ItemStateException

Specified by:
load in interface PersistenceManager
Throws:
NoSuchItemStateException
ItemStateException

store

public void store(NodeReferences refs)
           throws ItemStateException

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.

Throws:
ItemStateException

destroy

public void destroy(NodeReferences refs)
             throws ItemStateException

Throws:
ItemStateException

exists

public boolean exists(NodeId id)
               throws ItemStateException

Specified by:
exists in interface PersistenceManager
Throws:
ItemStateException

exists

public boolean exists(PropertyId id)
               throws ItemStateException

Specified by:
exists in interface PersistenceManager
Throws:
ItemStateException

exists

public boolean exists(NodeReferencesId targetId)
               throws ItemStateException

Specified by:
exists in interface PersistenceManager
Throws:
ItemStateException

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)

buildBlobFilePath

protected static String buildBlobFilePath(String parentUUID,
                                          QName propName,
                                          int index)

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 © -2005 . All Rights Reserved.