org.apache.jackrabbit.core.version
Class VersionManagerImpl

java.lang.Object
  extended by org.apache.jackrabbit.core.version.VersionManagerImpl
All Implemented Interfaces:
UpdateEventListener, ItemStateListener, VersionManager

public class VersionManagerImpl
extends Object
implements ItemStateListener, UpdateEventListener

This Class implements a VersionManager.


Nested Class Summary
static class VersionManagerImpl.DynamicESCFactory
           
protected  class VersionManagerImpl.VersionItemStateManager
          Spezialized SharedItemStateManager that filters out NodeReferences to non-versioning states.
 
Field Summary
protected  NodeStateEx historyRoot
          Persistent root node of the version histories.
protected  LocalItemStateManager stateMgr
          State manager for the version storage.
 
Constructor Summary
VersionManagerImpl(PersistenceManager pMgr, FileSystem fs, NodeTypeRegistry ntReg, DelegatingObservationDispatcher obsMgr, NodeId rootId, NodeId rootParentId, ItemStateCacheFactory cacheFactory)
          Creates a new version manager
 
Method Summary
protected  void acquireReadLock()
          aquires the read lock on this version manager.
protected  void acquireWriteLock()
          aquires the write lock on this version manager.
protected  String calculateCheckinVersionName(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history, NodeImpl node)
          Calculates the name of the new version that will be created by a checkin call.
protected  InternalVersion checkin(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history, NodeImpl node)
          Checks in a node
 Version checkin(NodeImpl node)
          invokes the checkin() on the persistent version manager and remaps the newly created version objects.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

 void close()
          Close this version manager.
protected  SharedItemStateManager createSharedStateManager(PersistenceManager pMgr, NodeId rootId, NodeTypeRegistry ntReg, ItemStateCacheFactory cacheFactory)
          Creates a SharedItemStateManager or derivative.
 VersionHistory createVersionHistory(Session session, NodeState node)
          Creates a new version history.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

 void externalUpdate(ChangeLog changes, List events)
          Handle an external update.
 VersionManagerImpl.DynamicESCFactory getEscFactory()
          Returns the event state collection factory.
protected  InternalVersionItem getItem(NodeId id)
          Returns the item with the given persistent id.
protected  List getItemReferences(InternalVersionItem item)
          Returns the item references that reference the given version item.
protected  SharedItemStateManager getSharedStateMgr()
          Return the shared item state manager.
 InternalVersion getVersion(NodeId id)
          Returns the version with the given id
 InternalVersionHistory getVersionHistory(NodeId id)
          Returns the version history with the given id
 VersionHistory getVersionHistory(Session session, NodeState node)
          Returns the version history of the specified node or null if the given node doesn't (yet) have an associated version history.
 VirtualItemStateProvider getVirtualItemStateProvider()
          returns the virtual item state provider that exposes the internal versions as items.
 boolean hasItem(NodeId id)
          Return a flag indicating if the item specified exists.
 boolean hasVersion(NodeId id)
          Checks if the version with the given id exists
 boolean hasVersionHistory(NodeId id)
          Checks if the version history with the given id exists
protected  void itemDiscarded(InternalVersionItem item)
          Invoked by the internal version item itself, when it's underlying persistence state was discarded.
 void itemsUpdated(Collection items)
          Invoked by some external source to indicate that some items in the versions tree were updated.
protected  void releaseReadLock()
          releases the read lock on this version manager.
protected  void releaseWriteLock()
          releases the write lock on this version manager.
protected  void removeVersion(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history, QName name)
          Removes the specified version from the history
 void removeVersion(VersionHistory history, QName name)
          Removes the specified version from the given version history.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

 void setEventChannel(UpdateEventChannel eventChannel)
          Set an event channel to inform about updates.
 boolean setNodeReferences(NodeReferences references)
          Sets and stored the node references from external nodes.
protected  InternalVersion setVersionLabel(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history, QName version, QName label, boolean move)
          Set version label on the specified version.
 Version setVersionLabel(VersionHistory history, QName version, QName label, boolean move)
          Sets the version label to the given version.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

 void stateCreated(ItemState created)
          Called when an ItemState has successfully been created (i.e.

Not used.

 void stateDestroyed(ItemState destroyed)
          Called when an ItemState has successfully been removed (i.e.

Remove item from cache on removal.

 void stateDiscarded(ItemState discarded)
          Called when an ItemState has been discarded (i.e.

Not used.

 void stateModified(ItemState modified)
          Called when an ItemState has successfully been modified (i.e.

Not used.

protected  void versionCreated(InternalVersion version)
          Invoked when a new internal item has been created.
protected  void versionDestroyed(InternalVersion version)
          Invoked when a new internal item has been destroyed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateMgr

protected LocalItemStateManager stateMgr
State manager for the version storage.


historyRoot

protected NodeStateEx historyRoot
Persistent root node of the version histories.

Constructor Detail

VersionManagerImpl

public VersionManagerImpl(PersistenceManager pMgr,
                          FileSystem fs,
                          NodeTypeRegistry ntReg,
                          DelegatingObservationDispatcher obsMgr,
                          NodeId rootId,
                          NodeId rootParentId,
                          ItemStateCacheFactory cacheFactory)
                   throws RepositoryException
Creates a new version manager

Throws:
RepositoryException
Method Detail

getVirtualItemStateProvider

public VirtualItemStateProvider getVirtualItemStateProvider()
returns the virtual item state provider that exposes the internal versions as items.

Specified by:
getVirtualItemStateProvider in interface VersionManager
Returns:
the virtual item state provider.

close

public void close()
           throws Exception
Close this version manager. After having closed a persistence manager, further operations on this object are treated as illegal and throw

Specified by:
close in interface VersionManager
Throws:
Exception - if an error occurs

getEscFactory

public VersionManagerImpl.DynamicESCFactory getEscFactory()
Returns the event state collection factory.

Returns:
the event state collection factory.

createVersionHistory

public VersionHistory createVersionHistory(Session session,
                                           NodeState node)
                                    throws RepositoryException
Creates a new version history. This action is needed either when creating a new 'mix:versionable' node or when adding the 'mix:versionable' mixin to a node.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

Specified by:
createVersionHistory in interface VersionManager
Returns:
Throws:
RepositoryException
See Also:
VersionManager.getVersionHistory(Session, NodeState)

hasItem

public boolean hasItem(NodeId id)
Return a flag indicating if the item specified exists. Subclass responsibility.

Parameters:
id - the id of the item
Returns:
true if the item exists; false otherwise

getItem

protected InternalVersionItem getItem(NodeId id)
                               throws RepositoryException
Returns the item with the given persistent id. Subclass responsibility.

Please note, that the overridden method must aquire the readlock before reading the state manager.

Parameters:
id - the id of the item
Returns:
version item
Throws:
RepositoryException - if an error occurs

checkin

public Version checkin(NodeImpl node)
                throws RepositoryException
invokes the checkin() on the persistent version manager and remaps the newly created version objects.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

Specified by:
checkin in interface VersionManager
Returns:
Throws:
RepositoryException

removeVersion

public void removeVersion(VersionHistory history,
                          QName name)
                   throws VersionException,
                          RepositoryException
Removes the specified version from the given version history.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

Specified by:
removeVersion in interface VersionManager
Throws:
RepositoryException
VersionException

setVersionLabel

public Version setVersionLabel(VersionHistory history,
                               QName version,
                               QName label,
                               boolean move)
                        throws RepositoryException
Sets the version label to the given version. If the label is already assigned to another version, a VersionException is thrown unless move is true. If version is null, the label is removed from the respective version. In either case, the version the label was previously assigned is returned, or null of the label was not moved.

This method must not be synchronized since it could cause deadlocks with item-reading listeners in the observation thread.

Specified by:
setVersionLabel in interface VersionManager
Returns:
Throws:
RepositoryException

itemsUpdated

public void itemsUpdated(Collection items)
Invoked by some external source to indicate that some items in the versions tree were updated. Version histories are reloaded if possible. Matching items are removed from the cache.

Parameters:
items - items updated

setEventChannel

public void setEventChannel(UpdateEventChannel eventChannel)
Set an event channel to inform about updates.

Parameters:
eventChannel - event channel

itemDiscarded

protected void itemDiscarded(InternalVersionItem item)
Invoked by the internal version item itself, when it's underlying persistence state was discarded.


setNodeReferences

public boolean setNodeReferences(NodeReferences references)
Sets and stored the node references from external nodes.

Parameters:
references -
Returns:
true if the references could be set.

getItemReferences

protected List getItemReferences(InternalVersionItem item)
Returns the item references that reference the given version item. Subclass responsiblity.

Please note, that the overridden method must aquire the readlock before reading the state manager.

Parameters:
item - version item
Returns:
list of item references, may be empty.

getSharedStateMgr

protected SharedItemStateManager getSharedStateMgr()
Return the shared item state manager.


createSharedStateManager

protected SharedItemStateManager createSharedStateManager(PersistenceManager pMgr,
                                                          NodeId rootId,
                                                          NodeTypeRegistry ntReg,
                                                          ItemStateCacheFactory cacheFactory)
                                                   throws ItemStateException
Creates a SharedItemStateManager or derivative.

Parameters:
pMgr - persistence manager
rootId - root node id
ntReg - node type registry
cacheFactory - cache factory
Returns:
item state manager
Throws:
ItemStateException - if an error occurs

stateCreated

public void stateCreated(ItemState created)
Called when an ItemState has successfully been created (i.e. its underlying persistent state was created).

Not used.

Specified by:
stateCreated in interface ItemStateListener
Parameters:
created - the ItemState that has been 'created'

stateModified

public void stateModified(ItemState modified)
Called when an ItemState has successfully been modified (i.e. its underlying persistent state has changed).

Not used.

Specified by:
stateModified in interface ItemStateListener
Parameters:
modified - the ItemState that has been 'modified'

stateDestroyed

public void stateDestroyed(ItemState destroyed)
Called when an ItemState has successfully been removed (i.e. its underlying persistent state has been destroyed).

Remove item from cache on removal.

Specified by:
stateDestroyed in interface ItemStateListener
Parameters:
destroyed - the ItemState that has been 'destroyed'

stateDiscarded

public void stateDiscarded(ItemState discarded)
Called when an ItemState has been discarded (i.e. it has been rendered 'invalid').

Not used.

Specified by:
stateDiscarded in interface ItemStateListener
Parameters:
discarded - the ItemState that has been discarded
See Also:
ItemState.discard()

externalUpdate

public void externalUpdate(ChangeLog changes,
                           List events)
                    throws RepositoryException
Handle an external update.

Specified by:
externalUpdate in interface UpdateEventListener
Parameters:
changes - external changes containing only node and property ids.
events - events to deliver
Throws:
RepositoryException - if the update cannot be processed

getVersion

public InternalVersion getVersion(NodeId id)
                           throws RepositoryException
Returns the version with the given id

Specified by:
getVersion in interface VersionManager
Returns:
the version.
Throws:
RepositoryException

getVersionHistory

public InternalVersionHistory getVersionHistory(NodeId id)
                                         throws RepositoryException
Returns the version history with the given id

Specified by:
getVersionHistory in interface VersionManager
Returns:
the version history.
Throws:
RepositoryException

hasVersionHistory

public boolean hasVersionHistory(NodeId id)
Checks if the version history with the given id exists

Specified by:
hasVersionHistory in interface VersionManager
Returns:
true if the version history exists.

hasVersion

public boolean hasVersion(NodeId id)
Checks if the version with the given id exists

Specified by:
hasVersion in interface VersionManager
Returns:
true if the version exists.

acquireWriteLock

protected void acquireWriteLock()
aquires the write lock on this version manager.


releaseWriteLock

protected void releaseWriteLock()
releases the write lock on this version manager.


acquireReadLock

protected void acquireReadLock()
aquires the read lock on this version manager.


releaseReadLock

protected void releaseReadLock()
releases the read lock on this version manager.


getVersionHistory

public VersionHistory getVersionHistory(Session session,
                                        NodeState node)
                                 throws RepositoryException
Returns the version history of the specified node or null if the given node doesn't (yet) have an associated version history.

Specified by:
getVersionHistory in interface VersionManager
node - node whose version history should be returned
Returns:
the version history of the specified node or null if the given node doesn't (yet) have an associated version history.
Throws:
RepositoryException - if an error occurs
See Also:
VersionManager.createVersionHistory(Session, NodeState)

checkin

protected InternalVersion checkin(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history,
                                  NodeImpl node)
                           throws RepositoryException
Checks in a node

Parameters:
history - the version history
node - node to checkin
Returns:
internal version
Throws:
RepositoryException - if an error occurs
See Also:
Node.checkin()

calculateCheckinVersionName

protected String calculateCheckinVersionName(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history,
                                             NodeImpl node)
                                      throws RepositoryException
Calculates the name of the new version that will be created by a checkin call. The name is determined as follows:

removeVersion

protected void removeVersion(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history,
                             QName name)
                      throws VersionException,
                             RepositoryException
Removes the specified version from the history

Parameters:
history - the version history from where to remove the version.
name - the name of the version to remove.
Throws:
VersionException - if the version history does not have a version with name.
RepositoryException - if any other error occurs.

setVersionLabel

protected InternalVersion setVersionLabel(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history,
                                          QName version,
                                          QName label,
                                          boolean move)
                                   throws RepositoryException
Set version label on the specified version.

Parameters:
history - version history
version - version name
label - version label
move - true to move from existing version; false otherwise
Throws:
RepositoryException - if an error occurs

versionCreated

protected void versionCreated(InternalVersion version)
Invoked when a new internal item has been created.

Parameters:
version - internal version item

versionDestroyed

protected void versionDestroyed(InternalVersion version)
Invoked when a new internal item has been destroyed.

Parameters:
version - internal version item


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