org.apache.jackrabbit.core.version
Class VersionManagerImplBase

java.lang.Object
  extended by org.apache.jackrabbit.core.version.VersionManagerImplBase
Direct Known Subclasses:
VersionManagerImplRestore

public abstract class VersionManagerImplBase
extends Object

The JCR Version Manager impementation is split in several classes in order to group related methods together.

this class provides basic routines for all operations and the methods related to checkin and checkout.


Nested Class Summary
 class VersionManagerImplBase.WriteOperation
          Helper for managing write operations.
 
Field Summary
protected  SessionContext context
          Component context of the current session
protected  NodeId currentActivity
          the node id of the current activity
protected  HierarchyManager hierMgr
          hierarch manager that operates on the localte state manager
protected  NodeTypeRegistry ntReg
          node type registry
protected  SessionImpl session
          workspace session
protected  UpdatableItemStateManager stateMgr
          item state manager for all workspace operations
protected  InternalVersionManager vMgr
          the session version manager.
 
Constructor Summary
protected VersionManagerImplBase(SessionContext context, UpdatableItemStateManager stateMgr, HierarchyManager hierMgr)
          Creates a new version manager base for the given session
 
Method Summary
protected  ISMLocking.ReadLock acquireReadLock()
          acquires the read lock on this version manager.
protected  ISMLocking.WriteLock acquireWriteLock()
          Acquires the write lock on this version manager.
protected  void checkModify(NodeImpl node, int options, int permissions)
          Checks modify and permissions
protected  void checkModify(NodeStateEx state, int options, int permissions)
          Checks modify and permissions
protected  NodeId checkoutCheckin(NodeStateEx state, boolean checkin, boolean checkout, Calendar created)
          Performs a checkin or checkout operation. if checkin is true the node is checked in. if checkout is true the node is checked out. if both flags are true the checkin is performed prior to the checkout and the operation is equivalent to a checkpoint operation.
protected  boolean checkVersionable(NodeStateEx state)
          Checks if the underlying node is versionable, i.e. has 'mix:versionable' or a 'mix:simpleVersionable'.
protected  InternalVersion getBaseVersion(NodeStateEx state)
          Returns the internal base version for the underlying node.
protected  NodeId getBaseVersionId(NodeStateEx state)
          Returns the node id of the base version, retrieved from the node state
protected  NodeStateEx getNodeStateEx(NodeId nodeId)
          returns the node state for the given node id
protected  InternalVersion getVersion(Version v)
          helper class that returns the internal version for a JCR one.
protected  InternalVersionHistory getVersionHistory(NodeStateEx state)
          Returns the internal version history for the underlying node.
protected  boolean isCheckedOut(NodeStateEx state)
          Determines the checked-out status of the given node state.
protected  String safeGetJCRPath(NodeStateEx state)
          Returns the JCR path for the given node state without throwing an exception.
 VersionManagerImplBase.WriteOperation startWriteOperation()
          Starts a write operation by acquiring the write lock and setting the item state manager to the "edit" state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected final SessionContext context
Component context of the current session


session

protected final SessionImpl session
workspace session


stateMgr

protected final UpdatableItemStateManager stateMgr
item state manager for all workspace operations


hierMgr

protected final HierarchyManager hierMgr
hierarch manager that operates on the localte state manager


ntReg

protected final NodeTypeRegistry ntReg
node type registry


vMgr

protected final InternalVersionManager vMgr
the session version manager.


currentActivity

protected NodeId currentActivity
the node id of the current activity

Constructor Detail

VersionManagerImplBase

protected VersionManagerImplBase(SessionContext context,
                                 UpdatableItemStateManager stateMgr,
                                 HierarchyManager hierMgr)
Creates a new version manager base for the given session

Parameters:
context - component context of the current session
stateMgr - the underlying state manager
hierMgr - local hierarchy manager
Method Detail

checkoutCheckin

protected NodeId checkoutCheckin(NodeStateEx state,
                                 boolean checkin,
                                 boolean checkout,
                                 Calendar created)
                          throws RepositoryException
Performs a checkin or checkout operation. if checkin is true the node is checked in. if checkout is true the node is checked out. if both flags are true the checkin is performed prior to the checkout and the operation is equivalent to a checkpoint operation.

Parameters:
state - node state
checkin - if true the node is checked in.
checkout - if true the node is checked out.
created - create time of the new version (if any), or null for the current time
Returns:
the node id of the base version or null for a pure checkout.
Throws:
RepositoryException - if an error occurs

checkVersionable

protected boolean checkVersionable(NodeStateEx state)
                            throws UnsupportedRepositoryOperationException,
                                   RepositoryException
Checks if the underlying node is versionable, i.e. has 'mix:versionable' or a 'mix:simpleVersionable'.

Parameters:
state - node state
Returns:
true if this node is full versionable, i.e. is of nodetype mix:versionable
Throws:
UnsupportedRepositoryOperationException - if this node is not versionable at all
RepositoryException

safeGetJCRPath

protected String safeGetJCRPath(NodeStateEx state)
Returns the JCR path for the given node state without throwing an exception.

Parameters:
state - node state
Returns:
a JCR path string

isCheckedOut

protected boolean isCheckedOut(NodeStateEx state)
                        throws RepositoryException
Determines the checked-out status of the given node state.

A node is considered checked-out if it is versionable and checked-out, or is non-versionable but its nearest versionable ancestor is checked-out, or is non-versionable and there are no versionable ancestors.

Parameters:
state - node state
Returns:
a boolean
Throws:
RepositoryException - if an error occurs
See Also:
VersionManager.isCheckedOut(String), Node.isCheckedOut()

getBaseVersionId

protected NodeId getBaseVersionId(NodeStateEx state)
Returns the node id of the base version, retrieved from the node state

Parameters:
state - node state
Returns:
the node id of the base version or null if not defined

getVersionHistory

protected InternalVersionHistory getVersionHistory(NodeStateEx state)
                                            throws RepositoryException
Returns the internal version history for the underlying node.

Parameters:
state - node state
Returns:
internal version history
Throws:
RepositoryException - if an error occurs

getVersion

protected InternalVersion getVersion(Version v)
                              throws RepositoryException
helper class that returns the internal version for a JCR one.

Parameters:
v - the jcr version
Returns:
the internal version
Throws:
RepositoryException - if an error occurs

getBaseVersion

protected InternalVersion getBaseVersion(NodeStateEx state)
                                  throws RepositoryException
Returns the internal base version for the underlying node.

Parameters:
state - node state
Returns:
internal base version
Throws:
RepositoryException - if an error occurs

getNodeStateEx

protected NodeStateEx getNodeStateEx(NodeId nodeId)
                              throws RepositoryException
returns the node state for the given node id

Parameters:
nodeId - the node id
Returns:
the node state or null if not found
Throws:
RepositoryException - if an error occurs

checkModify

protected void checkModify(NodeStateEx state,
                           int options,
                           int permissions)
                    throws RepositoryException
Checks modify and permissions

Parameters:
state - state to check
options - options to check
permissions - permissions to check
Throws:
RepositoryException - if an error occurs

checkModify

protected void checkModify(NodeImpl node,
                           int options,
                           int permissions)
                    throws RepositoryException
Checks modify and permissions

Parameters:
node - node to check
options - options to check
permissions - permissions to check
Throws:
RepositoryException - if an error occurs

acquireWriteLock

protected ISMLocking.WriteLock acquireWriteLock()
Acquires the write lock on this version manager.

Returns:
returns the write lock

acquireReadLock

protected ISMLocking.ReadLock acquireReadLock()
acquires the read lock on this version manager.

Returns:
returns the read lock

startWriteOperation

public VersionManagerImplBase.WriteOperation startWriteOperation()
                                                          throws RepositoryException
Starts a write operation by acquiring the write lock and setting the item state manager to the "edit" state. If something goes wrong, the write lock is released and an exception is thrown.

The pattern for using this method and the returned helper instance is:

     WriteOperation operation = startWriteOperation();
     try {
         ...
         operation.save(); // if everything is OK
         ...
     } catch (...) {
         ...
     } finally {
         operation.close();
     }
 

Returns:
write operation helper
Throws:
RepositoryException - if the write operation could not be started


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