org.apache.jackrabbit.core.version
Class XAVersionManager

java.lang.Object
  extended by org.apache.jackrabbit.core.version.XAVersionManager
All Implemented Interfaces:
InternalXAResource, EventStateCollectionFactory, ItemStateManager, VersionManager, VirtualItemStateProvider

public class XAVersionManager
extends Object
implements EventStateCollectionFactory, VirtualItemStateProvider, InternalXAResource

Implementation of a VersionManager that works in an XA environment. Works as a filter between a version manager client and the global version manager.


Field Summary
protected  NodeStateEx historyRoot
          Persistent root node of the version histories.
protected  LocalItemStateManager stateMgr
          State manager for the version storage.
 
Constructor Summary
XAVersionManager(VersionManagerImpl vMgr, NodeTypeRegistry ntReg, SessionImpl session, ItemStateCacheFactory cacheFactory)
          Creates a new instance of this class.
 
Method Summary
protected  void acquireReadLock()
          aquires the read lock on this version manager.
protected  void acquireWriteLock()
          aquires the write lock on this version manager.
 void addListener(ItemStateListener listener)
          Add an ItemStateListener

Not needed.

 void afterOperation(TransactionContext tx)
          Invoked after one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method has been called.

Delegate the call to our XA item state manager.

 void associate(TransactionContext tx)
          Associate this resource with a transaction.
 void beforeOperation(TransactionContext tx)
          Invoked before one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method is called.

Delegate the call to our XA item state 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

Before modifying version history given, make a local copy of it.

 Version checkin(NodeImpl node)
          invokes the checkin() on the persistent version manager and remaps the newly created version objects.
 void close()
          Close this version manager.
 void commit(TransactionContext tx)
          Commit transaction.

Delegate the call to our XA item state manager.

 EventStateCollection createEventStateCollection()
          Creates an EventStateCollection.
 VirtualNodeState createNodeState(VirtualNodeState parent, QName name, NodeId id, QName nodeTypeName)
          Creates a new virtual node state
 VirtualPropertyState createPropertyState(VirtualNodeState parent, QName name, int type, boolean multiValued)
          Creats a new virtual property state
 VersionHistory createVersionHistory(Session session, NodeState node)
          Creates a new version history.
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.
 ItemState getItemState(ItemId id)
          Return an item state, given its item id.

Return item states for changes only.

 NodeReferences getNodeReferences(NodeReferencesId id)
          Return a node references object, given its target id
 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.
 NodeId getVirtualRootId()
          Returns the id of the root node of the virtual tree.
protected  boolean hasItem(NodeId id)
          Return a flag indicating if the item specified exists.
 boolean hasItemState(ItemId id)
          Return a flag indicating whether an item state for a given item id exists.
 boolean hasNodeReferences(NodeReferencesId id)
          Return a flag indicating whether a node references object for a given target id 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
 boolean isVirtualRoot(ItemId id)
          Checks if the id refers to the root of a virtual tree.
protected  void itemDiscarded(InternalVersionItem item)
          Invoked by the internal version item itself, when it's underlying persistence state was discarded.
 void prepare(TransactionContext tx)
          Prepare transaction.

Delegate the call to our XA item state manager.

protected  void releaseReadLock()
          releases the read lock on this version manager.
protected  void releaseWriteLock()
          releases the write lock on this version manager.
 void removeListener(ItemStateListener listener)
          Remove an ItemStateListener

Not needed.

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

Before modifying version history given, make a local copy of it.

 void removeVersion(VersionHistory history, QName versionName)
          Removes the specified version from the given version history.
 void rollback(TransactionContext tx)
          Rollback transaction.

Delegate the call to our XA item state manager.

 boolean setNodeReferences(NodeReferences refs)
          Informs this provider that the node references to one of its states has changed.
protected  InternalVersion setVersionLabel(org.apache.jackrabbit.core.version.InternalVersionHistoryImpl history, QName version, QName label, boolean move)
          Set version label on the specified version.

Before modifying version history given, make a local copy of it.

 Version setVersionLabel(VersionHistory history, QName version, QName label, boolean move)
          Sets the version label to the given version.
protected  void versionCreated(InternalVersion version)
          Invoked when a new internal item has been created.

Put the version object into our cache.

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

Remove the version object from our cache.

 
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

XAVersionManager

public XAVersionManager(VersionManagerImpl vMgr,
                        NodeTypeRegistry ntReg,
                        SessionImpl session,
                        ItemStateCacheFactory cacheFactory)
                 throws RepositoryException
Creates a new instance of this class.

Throws:
RepositoryException
Method Detail

createEventStateCollection

public EventStateCollection createEventStateCollection()
                                                throws RepositoryException
Description copied from interface: EventStateCollectionFactory
Creates an EventStateCollection.

Specified by:
createEventStateCollection in interface EventStateCollectionFactory
Returns:
a new EventStateCollection
Throws:
RepositoryException - if creation fails for some reason

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.

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.

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

checkin

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

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

removeVersion

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

Specified by:
removeVersion in interface VersionManager
Throws:
RepositoryException

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.

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

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

isVirtualRoot

public boolean isVirtualRoot(ItemId id)
Checks if the id refers to the root of a virtual tree.

Specified by:
isVirtualRoot in interface VirtualItemStateProvider
Returns:
true if it is the root

getVirtualRootId

public NodeId getVirtualRootId()
Returns the id of the root node of the virtual tree.

Specified by:
getVirtualRootId in interface VirtualItemStateProvider
Returns:
the id of the root node of the virtual tree.

createPropertyState

public VirtualPropertyState createPropertyState(VirtualNodeState parent,
                                                QName name,
                                                int type,
                                                boolean multiValued)
                                         throws RepositoryException
Creats a new virtual property state

Specified by:
createPropertyState in interface VirtualItemStateProvider
Returns:
Throws:
RepositoryException

createNodeState

public VirtualNodeState createNodeState(VirtualNodeState parent,
                                        QName name,
                                        NodeId id,
                                        QName nodeTypeName)
                                 throws RepositoryException
Creates a new virtual node state

Specified by:
createNodeState in interface VirtualItemStateProvider
Returns:
Throws:
RepositoryException

setNodeReferences

public boolean setNodeReferences(NodeReferences refs)
Informs this provider that the node references to one of its states has changed.

Specified by:
setNodeReferences in interface VirtualItemStateProvider
Returns:
true if the reference target is one of its items.

getItemState

public ItemState getItemState(ItemId id)
                       throws NoSuchItemStateException,
                              ItemStateException
Return an item state, given its item id.

Return item states for changes only. Global version manager will return other items.

Specified by:
getItemState in interface ItemStateManager
Parameters:
id - item id
Returns:
item state
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - if an error occurs

hasItemState

public boolean hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.

Specified by:
hasItemState in interface ItemStateManager
Parameters:
id - item id
Returns:
true if an item state exists, otherwise false

getNodeReferences

public NodeReferences getNodeReferences(NodeReferencesId id)
                                 throws NoSuchItemStateException,
                                        ItemStateException
Return a node references object, given its target id

Specified by:
getNodeReferences in interface ItemStateManager
Parameters:
id - target id
Returns:
node references object
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - if an error occurs

hasNodeReferences

public boolean hasNodeReferences(NodeReferencesId id)
Return a flag indicating whether a node references object for a given target id exists.

Specified by:
hasNodeReferences in interface ItemStateManager
Parameters:
id - target id
Returns:
true if a node reference object exists for the given id, otherwise false.

addListener

public void addListener(ItemStateListener listener)
Add an ItemStateListener

Not needed.

Specified by:
addListener in interface VirtualItemStateProvider
Parameters:
listener - the new listener to be informed on modifications

removeListener

public void removeListener(ItemStateListener listener)
Remove an ItemStateListener

Not needed.

Specified by:
removeListener in interface VirtualItemStateProvider
Parameters:
listener - an existing listener

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

hasItem

protected 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

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.

checkin

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

Before modifying version history given, make a local copy of it.

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

removeVersion

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

Before modifying version history given, make a local copy of it.

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.

Before modifying version history given, make a local copy of it.

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.

Put the version object into our cache.

Parameters:
version - internal version item

versionDestroyed

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

Remove the version object from our cache.

Parameters:
version - internal version item

associate

public void associate(TransactionContext tx)
Associate this resource with a transaction. All further operations on the object should be interpreted as part of this transaction and changes recorded in some attribute of the transaction context.

Specified by:
associate in interface InternalXAResource
Parameters:
tx - transaction context, if null disassociate

beforeOperation

public void beforeOperation(TransactionContext tx)
Invoked before one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method is called.

Delegate the call to our XA item state manager.

Specified by:
beforeOperation in interface InternalXAResource
Parameters:
tx - transaction context

prepare

public void prepare(TransactionContext tx)
             throws TransactionException
Prepare transaction. The transaction is identified by a transaction context.

Delegate the call to our XA item state manager.

Specified by:
prepare in interface InternalXAResource
Parameters:
tx - transaction context
Throws:
TransactionException - if an error occurs

commit

public void commit(TransactionContext tx)
            throws TransactionException
Commit transaction. The transaction is identified by a transaction context. If the method throws, other resources get their changes rolled back.

Delegate the call to our XA item state manager. If successful, inform global repository manager to update its caches.

Specified by:
commit in interface InternalXAResource
Parameters:
tx - transaction context
Throws:
TransactionException - if an error occurs

rollback

public void rollback(TransactionContext tx)
Rollback transaction. The transaction is identified by a transaction context.

Delegate the call to our XA item state manager.

Specified by:
rollback in interface InternalXAResource
Parameters:
tx - transaction context.

afterOperation

public void afterOperation(TransactionContext tx)
Invoked after one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method has been called.

Delegate the call to our XA item state manager.

Specified by:
afterOperation in interface InternalXAResource
Parameters:
tx - transaction context

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)

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:

itemDiscarded

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

Parameters:
item -


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