org.apache.jackrabbit.core
Class BatchedItemOperations

java.lang.Object
  extended byorg.apache.jackrabbit.core.ItemValidator
      extended byorg.apache.jackrabbit.core.BatchedItemOperations

public class BatchedItemOperations
extends ItemValidator

BatchedItemOperations is an internal helper class that provides both high- and low-level operations directly on the ItemState level.


Field Summary
static int CHECK_ACCESS
          option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check access rights

static int CHECK_CONSTRAINTS
          option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check constraints defined in node type

static int CHECK_LOCK
          option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check lock status

static int CHECK_REFERENCES
          option for checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) method:

check that target node is not being referenced

static int CHECK_VERSIONING
          option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check checked-out status

protected static int CLONE
           
protected static int CLONE_REMOVE_EXISTING
           
protected static int COPY
           
protected  LockManager lockMgr
          lock manager used for checking locking status
protected  SessionImpl session
          current session used for checking access rights and locking status
protected  UpdatableItemStateManager stateMgr
          wrapped item state manager
 
Fields inherited from class org.apache.jackrabbit.core.ItemValidator
hierMgr, nsResolver, ntReg
 
Constructor Summary
BatchedItemOperations(UpdatableItemStateManager stateMgr, NodeTypeRegistry ntReg, LockManager lockMgr, SessionImpl session, HierarchyManager hierMgr, NamespaceResolver nsResolver)
          Creates a new BatchedItemOperations instance.
 
Method Summary
 void cancel()
          Cancel an update operation.
 void checkAddNode(NodeState parentState, QName nodeName, QName nodeTypeName, int options)
          Checks if adding a child node called nodeName of node type nodeTypeName to the given parent node is allowed in the current context.
 void checkRemoveNode(NodeState targetState, int options)
          Checks if removing the given target node is allowed in the current context.
 void checkRemoveNode(NodeState targetState, NodeId parentId, int options)
          Checks if removing the given target node from the specifed parent is allowed in the current context.
 void copy(Path srcPath, ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, AccessManager srcAccessMgr, Path destPath, int flag)
          Copies the tree at srcPath retrieved using the specified srcStateMgr to the new location at destPath.
 void copy(Path srcPath, Path destPath, int flag)
          Copies the tree at srcPath to the new location at destPath.
 NodeState createNodeState(NodeState parent, QName nodeName, QName nodeTypeName, QName[] mixinNames, NodeId id)
          Creates a new node.
 NodeState createNodeState(NodeState parent, QName nodeName, QName nodeTypeName, QName[] mixinNames, NodeId id, NodeDef def)
          Creates a new node based on the given definition.
 PropertyState createPropertyState(NodeState parent, QName propName, int type, int numValues)
          Creates a new property.
 PropertyState createPropertyState(NodeState parent, QName propName, int type, PropDef def)
          Creates a new property based on the given definition.
 void destroy(ItemState state)
          Destroy an item state.
 void edit()
          Starts an edit operation on the wrapped state manager.
 NodeDef findApplicableNodeDefinition(QName name, QName nodeTypeName, NodeState parentState)
          Helper method that finds the applicable definition for a child node with the given name and node type in the parent node's node type and mixin types.
 PropDef findApplicablePropertyDefinition(QName name, int type, boolean multiValued, NodeState parentState)
          Helper method that finds the applicable definition for a property with the given name, type and multiValued characteristic in the parent node's node type and mixin types.
 PropDef findApplicablePropertyDefinition(QName name, int type, NodeState parentState)
          Helper method that finds the applicable definition for a property with the given name, type in the parent node's node type and mixin types.
 ItemState getItemState(ItemId id)
          Retrieves the state of the item with the given id.
protected  ItemState getItemState(ItemStateManager srcStateMgr, ItemId id)
          Retrieves the state of the item with the specified id using the given item state manager.
protected  NodeState getNodeState(ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, Path nodePath)
          Retrieves the state of the node at nodePath using the given item state manager.
 NodeState getNodeState(NodeId id)
          Retrieves the state of the node with the given id.
 NodeState getNodeState(Path nodePath)
          Retrieves the state of the node at the given path.
 PropertyState getPropertyState(PropertyId id)
          Retrieves the state of the property with the given id.
 void move(Path srcPath, Path destPath)
          Moves the tree at srcPath to the new location at destPath.
 void removeNode(Path nodePath)
          Removes the specified node, recursively removing its properties and child nodes.
 void removeNodeState(NodeState target)
          Unlinks the specified node state from its parent and recursively removes it including its properties and child nodes.
 void store(ItemState state)
          Store an item state.
 void update()
          End an update operation.
 void verifyCanRead(Path nodePath)
          Verifies that the node at nodePath can be read.
 void verifyCanWrite(Path nodePath)
          Verifies that the node at nodePath is writable.
protected  void verifyCheckedOut(Path nodePath)
          Verifies that the node at nodePath is checked-out; throws a VersionException if that's not the case.
protected  void verifyNotProtected(Path nodePath)
          Verifies that the node at nodePath is not protected.
protected  void verifyUnlocked(Path nodePath)
          Verifies that the node at nodePath is not locked by somebody else than the current session.
 
Methods inherited from class org.apache.jackrabbit.core.ItemValidator
getEffectiveNodeType, safeGetJCRPath, safeGetJCRPath, validate, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPY

protected static final int COPY
See Also:
Constant Field Values

CLONE

protected static final int CLONE
See Also:
Constant Field Values

CLONE_REMOVE_EXISTING

protected static final int CLONE_REMOVE_EXISTING
See Also:
Constant Field Values

CHECK_ACCESS

public static final int CHECK_ACCESS
option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check access rights

See Also:
Constant Field Values

CHECK_LOCK

public static final int CHECK_LOCK
option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check lock status

See Also:
Constant Field Values

CHECK_VERSIONING

public static final int CHECK_VERSIONING
option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check checked-out status

See Also:
Constant Field Values

CHECK_CONSTRAINTS

public static final int CHECK_CONSTRAINTS
option for checkAddNode(org.apache.jackrabbit.core.state.NodeState, org.apache.jackrabbit.name.QName, org.apache.jackrabbit.name.QName, int) and checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) methods:

check constraints defined in node type

See Also:
Constant Field Values

CHECK_REFERENCES

public static final int CHECK_REFERENCES
option for checkRemoveNode(org.apache.jackrabbit.core.state.NodeState, int) method:

check that target node is not being referenced

See Also:
Constant Field Values

stateMgr

protected final UpdatableItemStateManager stateMgr
wrapped item state manager


lockMgr

protected final LockManager lockMgr
lock manager used for checking locking status


session

protected final SessionImpl session
current session used for checking access rights and locking status

Constructor Detail

BatchedItemOperations

public BatchedItemOperations(UpdatableItemStateManager stateMgr,
                             NodeTypeRegistry ntReg,
                             LockManager lockMgr,
                             SessionImpl session,
                             HierarchyManager hierMgr,
                             NamespaceResolver nsResolver)
Creates a new BatchedItemOperations instance.

Parameters:
stateMgr - item state manager
ntReg - node type registry
lockMgr - lock manager
session - current session
hierMgr - hierarchy manager
nsResolver - namespace resolver
Method Detail

edit

public void edit()
          throws IllegalStateException
Starts an edit operation on the wrapped state manager. At the end of this operation, either update() or cancel() must be invoked.

Throws:
IllegalStateException - if the state mananger is already in edit mode

store

public void store(ItemState state)
           throws IllegalStateException
Store an item state.

Parameters:
state - item state that should be stored
Throws:
IllegalStateException - if the manager is not in edit mode.

destroy

public void destroy(ItemState state)
             throws IllegalStateException
Destroy an item state.

Parameters:
state - item state that should be destroyed
Throws:
IllegalStateException - if the manager is not in edit mode.

update

public void update()
            throws RepositoryException,
                   IllegalStateException
End an update operation. This will save all changes made since the last invokation of edit(). If this operation fails, no item will have been saved.

Throws:
RepositoryException - if the update operation failed
IllegalStateException - if the state mananger is not in edit mode

cancel

public void cancel()
            throws IllegalStateException
Cancel an update operation. This will undo all changes made since the last invokation of edit().

Throws:
IllegalStateException - if the state mananger is not in edit mode

copy

public void copy(Path srcPath,
                 Path destPath,
                 int flag)
          throws ConstraintViolationException,
                 AccessDeniedException,
                 VersionException,
                 PathNotFoundException,
                 ItemExistsException,
                 LockException,
                 RepositoryException
Copies the tree at srcPath to the new location at destPath.

Precondition: the state manager needs to be in edit mode.

Parameters:
srcPath -
destPath -
flag - one of
  • COPY
  • CLONE
  • CLONE_REMOVE_EXISTING
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
PathNotFoundException
ItemExistsException
LockException
RepositoryException

copy

public void copy(Path srcPath,
                 ItemStateManager srcStateMgr,
                 HierarchyManager srcHierMgr,
                 AccessManager srcAccessMgr,
                 Path destPath,
                 int flag)
          throws ConstraintViolationException,
                 AccessDeniedException,
                 VersionException,
                 PathNotFoundException,
                 ItemExistsException,
                 LockException,
                 RepositoryException,
                 IllegalStateException
Copies the tree at srcPath retrieved using the specified srcStateMgr to the new location at destPath.

Precondition: the state manager needs to be in edit mode.

Parameters:
srcPath -
srcStateMgr -
srcHierMgr -
srcAccessMgr -
destPath -
flag - one of
  • COPY
  • CLONE
  • CLONE_REMOVE_EXISTING
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
PathNotFoundException
ItemExistsException
LockException
RepositoryException
IllegalStateException - if the state mananger is not in edit mode

move

public void move(Path srcPath,
                 Path destPath)
          throws ConstraintViolationException,
                 VersionException,
                 AccessDeniedException,
                 PathNotFoundException,
                 ItemExistsException,
                 LockException,
                 RepositoryException,
                 IllegalStateException
Moves the tree at srcPath to the new location at destPath.

Precondition: the state manager needs to be in edit mode.

Parameters:
srcPath -
destPath -
Throws:
ConstraintViolationException
VersionException
AccessDeniedException
PathNotFoundException
ItemExistsException
LockException
RepositoryException
IllegalStateException - if the state mananger is not in edit mode

removeNode

public void removeNode(Path nodePath)
                throws ConstraintViolationException,
                       AccessDeniedException,
                       VersionException,
                       LockException,
                       ItemNotFoundException,
                       ReferentialIntegrityException,
                       RepositoryException,
                       IllegalStateException
Removes the specified node, recursively removing its properties and child nodes.

Precondition: the state manager needs to be in edit mode.

Parameters:
nodePath -
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
LockException
ItemNotFoundException
ReferentialIntegrityException
RepositoryException
IllegalStateException

checkAddNode

public void checkAddNode(NodeState parentState,
                         QName nodeName,
                         QName nodeTypeName,
                         int options)
                  throws ConstraintViolationException,
                         AccessDeniedException,
                         VersionException,
                         LockException,
                         ItemNotFoundException,
                         ItemExistsException,
                         RepositoryException
Checks if adding a child node called nodeName of node type nodeTypeName to the given parent node is allowed in the current context.

Parameters:
parentState -
nodeName -
nodeTypeName -
options - bit-wise OR'ed flags specifying the checks that should be performed; any combination of the following constants:
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
LockException
ItemNotFoundException
ItemExistsException
RepositoryException

checkRemoveNode

public void checkRemoveNode(NodeState targetState,
                            int options)
                     throws ConstraintViolationException,
                            AccessDeniedException,
                            VersionException,
                            LockException,
                            ItemNotFoundException,
                            ReferentialIntegrityException,
                            RepositoryException
Checks if removing the given target node is allowed in the current context.

Parameters:
targetState -
options - bit-wise OR'ed flags specifying the checks that should be performed; any combination of the following constants:
  • CHECK_ACCESS: make sure current session is granted read access on parent and remove privilege on target node
  • CHECK_LOCK: make sure there's no foreign lock on parent node
  • CHECK_VERSIONING: make sure parent node is checked-out
  • CHECK_CONSTRAINTS: make sure no node type constraints would be violated
  • CHECK_REFERENCES: make sure no references exist on target node
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
LockException
ItemNotFoundException
ReferentialIntegrityException
RepositoryException

checkRemoveNode

public void checkRemoveNode(NodeState targetState,
                            NodeId parentId,
                            int options)
                     throws ConstraintViolationException,
                            AccessDeniedException,
                            VersionException,
                            LockException,
                            ItemNotFoundException,
                            ReferentialIntegrityException,
                            RepositoryException
Checks if removing the given target node from the specifed parent is allowed in the current context.

Parameters:
targetState -
parentId -
options - bit-wise OR'ed flags specifying the checks that should be performed; any combination of the following constants:
  • CHECK_ACCESS: make sure current session is granted read access on parent and remove privilege on target node
  • CHECK_LOCK: make sure there's no foreign lock on parent node
  • CHECK_VERSIONING: make sure parent node is checked-out
  • CHECK_CONSTRAINTS: make sure no node type constraints would be violated
  • CHECK_REFERENCES: make sure no references exist on target node
Throws:
ConstraintViolationException
AccessDeniedException
VersionException
LockException
ItemNotFoundException
ReferentialIntegrityException
RepositoryException

verifyCanWrite

public void verifyCanWrite(Path nodePath)
                    throws PathNotFoundException,
                           AccessDeniedException,
                           ConstraintViolationException,
                           VersionException,
                           LockException,
                           RepositoryException
Verifies that the node at nodePath is writable. The following conditions must hold true:

Parameters:
nodePath - path of node to check
Throws:
PathNotFoundException - if no node exists at nodePath of the current session is not granted read access to the specified path
AccessDeniedException - if write access to the specified path is not allowed
ConstraintViolationException - if the node at nodePath is protected
VersionException - if the node at nodePath is checked-in
LockException - if the node at nodePath is locked by another session
RepositoryException - if another error occurs

verifyCanRead

public void verifyCanRead(Path nodePath)
                   throws PathNotFoundException,
                          RepositoryException
Verifies that the node at nodePath can be read. The following conditions must hold true:

Parameters:
nodePath - path of node to check
Throws:
PathNotFoundException - if no node exists at nodePath of the current session is not granted read access to the specified path
RepositoryException - if another error occurs

findApplicableNodeDefinition

public NodeDef findApplicableNodeDefinition(QName name,
                                            QName nodeTypeName,
                                            NodeState parentState)
                                     throws RepositoryException,
                                            ConstraintViolationException
Helper method that finds the applicable definition for a child node with the given name and node type in the parent node's node type and mixin types.

Parameters:
name -
nodeTypeName -
parentState -
Returns:
a NodeDef
Throws:
ConstraintViolationException - if no applicable child node definition could be found
RepositoryException - if another error occurs

findApplicablePropertyDefinition

public PropDef findApplicablePropertyDefinition(QName name,
                                                int type,
                                                boolean multiValued,
                                                NodeState parentState)
                                         throws RepositoryException,
                                                ConstraintViolationException
Helper method that finds the applicable definition for a property with the given name, type and multiValued characteristic in the parent node's node type and mixin types. If there more than one applicable definitions then the following rules are applied:

Parameters:
name -
type -
multiValued -
parentState -
Returns:
a PropDef
Throws:
ConstraintViolationException - if no applicable property definition could be found
RepositoryException - if another error occurs

findApplicablePropertyDefinition

public PropDef findApplicablePropertyDefinition(QName name,
                                                int type,
                                                NodeState parentState)
                                         throws RepositoryException,
                                                ConstraintViolationException
Helper method that finds the applicable definition for a property with the given name, type in the parent node's node type and mixin types. Other than findApplicablePropertyDefinition(QName, int, boolean, NodeState) this method does not take the multiValued flag into account in the selection algorithm. If there more than one applicable definitions then the following rules are applied:

Parameters:
name -
type -
parentState -
Returns:
a PropDef
Throws:
ConstraintViolationException - if no applicable property definition could be found
RepositoryException - if another error occurs

createNodeState

public NodeState createNodeState(NodeState parent,
                                 QName nodeName,
                                 QName nodeTypeName,
                                 QName[] mixinNames,
                                 NodeId id)
                          throws ItemExistsException,
                                 ConstraintViolationException,
                                 RepositoryException,
                                 IllegalStateException
Creates a new node.

Note that access rights are not enforced!

Precondition: the state manager needs to be in edit mode.

Parameters:
parent -
nodeName -
nodeTypeName -
mixinNames -
id -
Returns:
Throws:
ItemExistsException
ConstraintViolationException
RepositoryException
IllegalStateException - if the state mananger is not in edit mode

createNodeState

public NodeState createNodeState(NodeState parent,
                                 QName nodeName,
                                 QName nodeTypeName,
                                 QName[] mixinNames,
                                 NodeId id,
                                 NodeDef def)
                          throws ItemExistsException,
                                 ConstraintViolationException,
                                 RepositoryException,
                                 IllegalStateException
Creates a new node based on the given definition.

Note that access rights are not enforced!

Precondition: the state manager needs to be in edit mode.

Parameters:
parent -
nodeName -
nodeTypeName -
mixinNames -
id -
def -
Returns:
Throws:
ItemExistsException
ConstraintViolationException
RepositoryException
IllegalStateException

createPropertyState

public PropertyState createPropertyState(NodeState parent,
                                         QName propName,
                                         int type,
                                         int numValues)
                                  throws ItemExistsException,
                                         ConstraintViolationException,
                                         RepositoryException,
                                         IllegalStateException
Creates a new property.

Note that access rights are not enforced!

Precondition: the state manager needs to be in edit mode.

Parameters:
parent -
propName -
type -
numValues -
Returns:
Throws:
ItemExistsException
ConstraintViolationException
RepositoryException
IllegalStateException - if the state mananger is not in edit mode

createPropertyState

public PropertyState createPropertyState(NodeState parent,
                                         QName propName,
                                         int type,
                                         PropDef def)
                                  throws ItemExistsException,
                                         RepositoryException
Creates a new property based on the given definition.

Note that access rights are not enforced!

Precondition: the state manager needs to be in edit mode.

Parameters:
parent -
propName -
type -
def -
Returns:
Throws:
ItemExistsException
RepositoryException

removeNodeState

public void removeNodeState(NodeState target)
                     throws RepositoryException
Unlinks the specified node state from its parent and recursively removes it including its properties and child nodes.

Note that no checks (access rights etc.) are performed on the specified target node state. Those checks have to be performed beforehand by the caller. However, the (recursive) removal of target node's child nodes are subject to the following checks: access rights, locking, versioning.

Parameters:
target -
Throws:
RepositoryException - if an error occurs

getNodeState

public NodeState getNodeState(Path nodePath)
                       throws PathNotFoundException,
                              RepositoryException
Retrieves the state of the node at the given path.

Note that access rights are not enforced!

Parameters:
nodePath -
Returns:
Throws:
PathNotFoundException
RepositoryException

getNodeState

public NodeState getNodeState(NodeId id)
                       throws ItemNotFoundException,
                              RepositoryException
Retrieves the state of the node with the given id.

Note that access rights are not enforced!

Parameters:
id -
Returns:
Throws:
ItemNotFoundException
RepositoryException

getPropertyState

public PropertyState getPropertyState(PropertyId id)
                               throws ItemNotFoundException,
                                      RepositoryException
Retrieves the state of the property with the given id.

Note that access rights are not enforced!

Parameters:
id -
Returns:
Throws:
ItemNotFoundException
RepositoryException

getItemState

public ItemState getItemState(ItemId id)
                       throws ItemNotFoundException,
                              RepositoryException
Retrieves the state of the item with the given id.

Note that access rights are not enforced!

Parameters:
id -
Returns:
Throws:
ItemNotFoundException
RepositoryException

verifyCheckedOut

protected void verifyCheckedOut(Path nodePath)
                         throws PathNotFoundException,
                                VersionException,
                                RepositoryException
Verifies that the node at nodePath is checked-out; throws a VersionException if that's not the case.

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:
nodePath -
Throws:
PathNotFoundException
VersionException
RepositoryException

verifyUnlocked

protected void verifyUnlocked(Path nodePath)
                       throws LockException,
                              RepositoryException
Verifies that the node at nodePath is not locked by somebody else than the current session.

Parameters:
nodePath - path of node to check
Throws:
PathNotFoundException
LockException - if write access to the specified path is not allowed
RepositoryException - if another error occurs

verifyNotProtected

protected void verifyNotProtected(Path nodePath)
                           throws PathNotFoundException,
                                  ConstraintViolationException,
                                  RepositoryException
Verifies that the node at nodePath is not protected.

Parameters:
nodePath - path of node to check
Throws:
PathNotFoundException - if no node exists at nodePath
ConstraintViolationException - if write access to the specified path is not allowed
RepositoryException - if another error occurs

getNodeState

protected NodeState getNodeState(ItemStateManager srcStateMgr,
                                 HierarchyManager srcHierMgr,
                                 Path nodePath)
                          throws PathNotFoundException,
                                 RepositoryException
Retrieves the state of the node at nodePath using the given item state manager.

Note that access rights are not enforced!

Parameters:
srcStateMgr -
srcHierMgr -
nodePath -
Returns:
Throws:
PathNotFoundException
RepositoryException

getItemState

protected ItemState getItemState(ItemStateManager srcStateMgr,
                                 ItemId id)
                          throws ItemNotFoundException,
                                 RepositoryException
Retrieves the state of the item with the specified id using the given item state manager.

Note that access rights are not enforced!

Parameters:
srcStateMgr -
id -
Returns:
Throws:
ItemNotFoundException
RepositoryException


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