org.apache.jackrabbit.core.persistence.bundle
Class AbstractBundlePersistenceManager

java.lang.Object
  extended by org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager
All Implemented Interfaces:
CachingPersistenceManager, IterablePersistenceManager, PersistenceManager
Direct Known Subclasses:
BundleDbPersistenceManager, BundleFsPersistenceManager

public abstract class AbstractBundlePersistenceManager
extends Object
implements PersistenceManager, CachingPersistenceManager, IterablePersistenceManager

The AbstractBundlePersistenceManager acts as base for all persistence managers that store the state in a NodePropBundle.

The state and all property states of one node are stored together in one record. Property values of a certain size can be store outside of the bundle. This currently only works for binary properties. NodeReferences are not included in the bundle since they are addressed by the target id.

Some strings like namespaces and local names are additionally managed by separate indexes. only the index number is serialized to the records which reduces the amount of memory used.

Special treatment is performed for the properties "jcr:uuid", "jcr:primaryType" and "jcr:mixinTypes". As they are also stored in the node state they are not included in the bundle but generated when required.

In order to increase performance, there are 2 caches maintained. One is the BundleCache that caches already loaded bundles. The other is the LRUNodeIdCache that caches non-existent bundles. This is useful because a lot of exists(NodeId) calls are issued that would result in a useless SQL execution if the desired bundle does not exist.

Configuration:


Field Summary
protected  PMContext context
          the persistence manager context
protected static String NODEFILENAME
          the prefix of a node file
protected static String NODEREFSFILENAME
          the prefix of a node references file
protected static String RES_NAME_INDEX
          the name of the names-index resource
protected static String RES_NS_INDEX
          the name of the namespace-index resource
 
Constructor Summary
AbstractBundlePersistenceManager()
           
 
Method Summary
protected  StringBuffer buildBlobFilePath(StringBuffer buf, PropertyId id, int i)
          Creates the file path for the given property id and value index that is suitable for storing property values in a filesystem.
protected  StringBuffer buildNodeFilePath(StringBuffer buf, NodeId id)
          Creates the file path for the given node id that is suitable for storing node states in a filesystem.
protected  StringBuffer buildNodeFolderPath(StringBuffer buf, NodeId id)
          Creates the folder path for the given node id that is suitable for storing states in a filesystem.
protected  StringBuffer buildNodeReferencesFilePath(StringBuffer buf, NodeReferencesId id)
          Creates the file path for the given references id that is suitable for storing reference states in a filesystem.
protected  StringBuffer buildPropFilePath(StringBuffer buf, PropertyId id)
          Creates the folder path for the given property id that is suitable for storing states in a filesystem.
 NodeState createNew(NodeId id)
          Creates a new node state instance with the given id.
 PropertyState createNew(PropertyId id)
          Creates a new property state instance with the given id.
protected abstract  void destroy(NodeReferences refs)
          Deletes the node references from the underlying system.
protected abstract  void destroyBundle(NodePropBundle bundle)
          Deletes the bundle from the underlying system.
 boolean exists(NodeId id)
          Checks whether the identified node exists. Checks the existence via the appropriate NodePropBundle.
 boolean exists(PropertyId id)
          Checks whether the identified property exists. Loads the state via the appropriate NodePropBundle.
protected abstract  boolean existsBundle(NodeId id)
          Checks if a bundle exists in the underlying system.
protected abstract  BundleBinding getBinding()
          Returns the bundle binding that is used for serializing the bundles.
 String getBundleCacheSize()
          Returns the size of the bundlecache in megabytes.
 StringIndex getNameIndex()
          Returns the local name index
 StringIndex getNsIndex()
          Returns the namespace index
 void init(PMContext context)
          Initializes the persistence manager. Initializes the internal structures of this abstract persistence manager.
 NodeState load(NodeId id)
          Load the persistent members of a node state. Loads the state via the appropriate NodePropBundle.
abstract  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. Loads the state via the appropriate NodePropBundle.
protected abstract  NodePropBundle loadBundle(NodeId id)
          Loads a bundle from the underlying system.
 void onExternalUpdate(ChangeLog changes)
          Notifies the persistence manager that an external (cluster) modification occured.
 void setBundleCacheSize(String bundleCacheSize)
          Sets the size of the bundle cache in megabytes.
 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.
protected abstract  void store(NodeReferences refs)
          Stores a node references to the underlying system.
protected abstract  void storeBundle(NodePropBundle bundle)
          Stores a bundle to the underlying system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jackrabbit.core.persistence.IterablePersistenceManager
getAllNodeIds
 

Field Detail

NODEFILENAME

protected static final String NODEFILENAME
the prefix of a node file

See Also:
Constant Field Values

NODEREFSFILENAME

protected static final String NODEREFSFILENAME
the prefix of a node references file

See Also:
Constant Field Values

RES_NAME_INDEX

protected static final String RES_NAME_INDEX
the name of the names-index resource

See Also:
Constant Field Values

RES_NS_INDEX

protected static final String RES_NS_INDEX
the name of the namespace-index resource

See Also:
Constant Field Values

context

protected PMContext context
the persistence manager context

Constructor Detail

AbstractBundlePersistenceManager

public AbstractBundlePersistenceManager()
Method Detail

getBundleCacheSize

public String getBundleCacheSize()
Returns the size of the bundlecache in megabytes.

Returns:
the size of the bundlecache in megabytes.

setBundleCacheSize

public void setBundleCacheSize(String bundleCacheSize)
Sets the size of the bundle cache in megabytes. the default is 8.

Parameters:
bundleCacheSize - the bundle cache size in megabytes.

buildNodeFolderPath

protected StringBuffer buildNodeFolderPath(StringBuffer buf,
                                           NodeId id)
Creates the folder path for the given node id that is suitable for storing states in a filesystem.

Parameters:
buf - buffer to append to or null
id - the id of the node
Returns:
the buffer with the appended data.

buildPropFilePath

protected StringBuffer buildPropFilePath(StringBuffer buf,
                                         PropertyId id)
Creates the folder path for the given property id that is suitable for storing states in a filesystem.

Parameters:
buf - buffer to append to or null
id - the id of the property
Returns:
the buffer with the appended data.

buildBlobFilePath

protected StringBuffer buildBlobFilePath(StringBuffer buf,
                                         PropertyId id,
                                         int i)
Creates the file path for the given property id and value index that is suitable for storing property values in a filesystem.

Parameters:
buf - buffer to append to or null
id - the id of the property
i - the index of the property value
Returns:
the buffer with the appended data.

buildNodeFilePath

protected StringBuffer buildNodeFilePath(StringBuffer buf,
                                         NodeId id)
Creates the file path for the given node id that is suitable for storing node states in a filesystem.

Parameters:
buf - buffer to append to or null
id - the id of the node
Returns:
the buffer with the appended data.

buildNodeReferencesFilePath

protected StringBuffer buildNodeReferencesFilePath(StringBuffer buf,
                                                   NodeReferencesId id)
Creates the file path for the given references id that is suitable for storing reference states in a filesystem.

Parameters:
buf - buffer to append to or null
id - the id of the node
Returns:
the buffer with the appended data.

getNsIndex

public StringIndex getNsIndex()
Returns the namespace index

Returns:
the namespace index
Throws:
IllegalStateException - if an error occurs.

getNameIndex

public StringIndex getNameIndex()
Returns the local name index

Returns:
the local name index
Throws:
IllegalStateException - if an error occurs.

onExternalUpdate

public void onExternalUpdate(ChangeLog changes)
Notifies the persistence manager that an external (cluster) modification occured.

Specified by:
onExternalUpdate in interface CachingPersistenceManager
Parameters:
changes - the set of changes of the external modification.

loadBundle

protected abstract NodePropBundle loadBundle(NodeId id)
                                      throws ItemStateException
Loads a bundle from the underlying system.

Parameters:
id - the node id of the bundle
Returns:
the loaded bundle or null if the bundle does not exist.
Throws:
ItemStateException - if an error while loading occurs.

existsBundle

protected abstract boolean existsBundle(NodeId id)
                                 throws ItemStateException
Checks if a bundle exists in the underlying system.

Parameters:
id - the node id of the bundle
Returns:
true if the bundle exists; false otherwise.
Throws:
ItemStateException - if an error while checking occurs.

storeBundle

protected abstract void storeBundle(NodePropBundle bundle)
                             throws ItemStateException
Stores a bundle to the underlying system.

Parameters:
bundle - the bundle to store
Throws:
ItemStateException - if an error while storing occurs.

destroyBundle

protected abstract void destroyBundle(NodePropBundle bundle)
                               throws ItemStateException
Deletes the bundle from the underlying system.

Parameters:
bundle - the bundle to destroy
Throws:
ItemStateException - if an error while destroying occurs.

load

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

Specified by:
load in interface PersistenceManager
Parameters:
targetId - reference target node id
Throws:
NoSuchItemStateException - if the target node does not exist
ItemStateException - if another error occurs

destroy

protected abstract void destroy(NodeReferences refs)
                         throws ItemStateException
Deletes the node references from the underlying system.

Parameters:
refs - the node references to destroy.
Throws:
ItemStateException - if an error while destroying occurs.

store

protected abstract void store(NodeReferences refs)
                       throws ItemStateException
Stores a node references to the underlying system.

Parameters:
refs - the node references to store.
Throws:
ItemStateException - if an error while storing occurs.

getBinding

protected abstract BundleBinding getBinding()
Returns the bundle binding that is used for serializing the bundles.

Returns:
the bundle binding

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. Initializes the internal structures of this abstract persistence manager.

Specified by:
init in interface PersistenceManager
Parameters:
context - persistence manager context
Throws:
Exception - if the persistence manager initialization failed

load

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

Specified by:
load in interface PersistenceManager
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. Loads the state via the appropriate NodePropBundle.

Specified by:
load in interface PersistenceManager
Parameters:
id - property id
Returns:
loaded property state
Throws:
NoSuchItemStateException - if the property state does not exist
ItemStateException - if another error occurs

exists

public boolean exists(PropertyId id)
               throws ItemStateException
Checks whether the identified property exists. Loads the state via the appropriate NodePropBundle.

Specified by:
exists in interface PersistenceManager
Parameters:
id - property id
Returns:
true if the property exists, false otherwise
Throws:
ItemStateException - on persistence manager errors

exists

public boolean exists(NodeId id)
               throws ItemStateException
Checks whether the identified node exists. Checks the existence via the appropriate NodePropBundle.

Specified by:
exists in interface PersistenceManager
Parameters:
id - node id
Returns:
true if the node exists, false otherwise
Throws:
ItemStateException - on persistence manager errors

createNew

public NodeState createNew(NodeId id)
Creates a new node state instance with the given id.

Specified by:
createNew in interface PersistenceManager
Parameters:
id - node id
Returns:
node state instance

createNew

public PropertyState createNew(PropertyId id)
Creates a new property state instance with the given id.

Specified by:
createNew in interface PersistenceManager
Parameters:
id - property id
Returns:
property state instance

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
Parameters:
changeLog - change log containing states that were changed
Throws:
ItemStateException - if the changes could not be saved


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