Class BatchedItemOperations
- java.lang.Object
-
- org.apache.jackrabbit.core.ItemValidator
-
- org.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 theItemState
level.
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
CLONE
protected static int
CLONE_REMOVE_EXISTING
protected static int
COPY
protected SessionImpl
session
current session used for checking access rightsprotected UpdatableItemStateManager
stateMgr
wrapped item state manager-
Fields inherited from class org.apache.jackrabbit.core.ItemValidator
CHECK_ACCESS, CHECK_CHECKED_OUT, CHECK_CONSTRAINTS, CHECK_HOLD, CHECK_LOCK, CHECK_PENDING_CHANGES, CHECK_PENDING_CHANGES_ON_NODE, CHECK_REFERENCES, CHECK_RETENTION, context
-
-
Constructor Summary
Constructors Constructor Description BatchedItemOperations(UpdatableItemStateManager stateMgr, SessionContext sessionContext)
Creates a newBatchedItemOperations
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancel an update operation.void
checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options)
Checks if adding a child node callednodeName
of node typenodeTypeName
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.NodeId
clone(NodeState srcState, NodeState destParentState, Name destName)
Implementation ofclone(Path, Path)
that has already determined the affectedNodeState
s.NodeId
clone(Path srcPath, Path destPath)
Clones the subtree at the nodesrcAbsPath
in to the new location atdestAbsPath
.NodeId
copy(Path srcPath, ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, AccessManager srcAccessMgr, Path destPath, int flag)
Copies the tree atsrcPath
retrieved using the specifiedsrcStateMgr
to the new location atdestPath
.NodeId
copy(Path srcPath, Path destPath, int flag)
Copies the tree atsrcPath
to the new location atdestPath
.NodeState
createNodeState(NodeState parent, Name nodeName, Name nodeTypeName, Name[] mixinNames, NodeId id)
Creates a new node.NodeState
createNodeState(NodeState parent, Name nodeName, Name nodeTypeName, Name[] mixinNames, NodeId id, QNodeDefinition def)
Creates a new node based on the given definition.PropertyState
createPropertyState(NodeState parent, Name propName, int type, int numValues)
Creates a new property.PropertyState
createPropertyState(NodeState parent, Name propName, int type, QPropertyDefinition 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.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.NodeState
getNodeState(NodeId id)
Retrieves the state of the node with the given id.protected NodeState
getNodeState(ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, Path nodePath)
Retrieves the state of the node atnodePath
using the given item state manager.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.NodeId
move(Path srcPath, Path destPath)
Moves the tree atsrcPath
to the new location atdestPath
.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 atnodePath
can be read.void
verifyCanWrite(Path nodePath)
Verifies that the node atnodePath
is writable.protected void
verifyCheckedOut(Path nodePath)
Verifies that the node atnodePath
is checked-out; throws aVersionException
if that's not the case.protected void
verifyNotProtected(Path nodePath)
Verifies that the node atnodePath
is not protected.protected void
verifyUnlocked(Path nodePath)
Verifies that the node atnodePath
is not locked by somebody else than the current session.-
Methods inherited from class org.apache.jackrabbit.core.ItemValidator
canModify, checkModify, checkRemove, findApplicableNodeDefinition, findApplicablePropertyDefinition, findApplicablePropertyDefinition, getEffectiveNodeType, performRelaxed, safeGetJCRPath, safeGetJCRPath, validate, validate
-
-
-
-
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
-
stateMgr
protected final UpdatableItemStateManager stateMgr
wrapped item state manager
-
session
protected final SessionImpl session
current session used for checking access rights
-
-
Constructor Detail
-
BatchedItemOperations
public BatchedItemOperations(UpdatableItemStateManager stateMgr, SessionContext sessionContext) throws RepositoryException
Creates a newBatchedItemOperations
instance.- Parameters:
stateMgr
- item state managersessionContext
- the session context- Throws:
RepositoryException
-
-
Method Detail
-
edit
public void edit() throws IllegalStateException
Starts an edit operation on the wrapped state manager. At the end of this operation, eitherupdate()
orcancel()
must be invoked.- Throws:
IllegalStateException
- if the state manager 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 invocation ofedit()
. If this operation fails, no item will have been saved.- Throws:
RepositoryException
- if the update operation failedIllegalStateException
- if the state manager is not in edit mode
-
cancel
public void cancel() throws IllegalStateException
Cancel an update operation. This will undo all changes made since the last invocation ofedit()
.- Throws:
IllegalStateException
- if the state manager is not in edit mode
-
clone
public NodeId clone(Path srcPath, Path destPath) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException
Clones the subtree at the nodesrcAbsPath
in to the new location atdestAbsPath
. This operation is only supported:- If the source element has the mixin
mix:shareable
(or some derived node type) - If the parent node of
destAbsPath
has not already a shareable node in the same shared set as the node atsrcPath
.
- Parameters:
srcPath
- source pathdestPath
- destination path- Returns:
- the node id of the destination's parent
- Throws:
ConstraintViolationException
- if the operation would violate a node-type or other implementation-specific constraint.VersionException
- if the parent node ofdestAbsPath
is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in. This exception will also be thrown ifremoveExisting
istrue
, and a UUID conflict occurs that would require the moving and/or altering of a node that is checked-in.AccessDeniedException
- if the current session does not have sufficient access rights to complete the operation.PathNotFoundException
- if the node atsrcAbsPath
insrcWorkspace
or the parent ofdestAbsPath
in this workspace does not exist.ItemExistsException
- if a property already exists atdestAbsPath
or a node already exist there, and same name siblings are not allowed or ifremoveExisting
is false and a UUID conflict occurs.LockException
- if a lock prevents the clone.RepositoryException
- if the last element ofdestAbsPath
has an index or if another error occurs.IllegalStateException
- If the source element has the mixin
-
clone
public NodeId clone(NodeState srcState, NodeState destParentState, Name destName) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException
Implementation ofclone(Path, Path)
that has already determined the affectedNodeState
s.- Parameters:
srcState
- source statedestParentState
- destination parent statedestName
- destination name- Returns:
- the node id of the destination's parent
- Throws:
ConstraintViolationException
- if the operation would violate a node-type or other implementation-specific constraint.VersionException
- if the parent node ofdestAbsPath
is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in. This exception will also be thrown ifremoveExisting
istrue
, and a UUID conflict occurs that would require the moving and/or altering of a node that is checked-in.AccessDeniedException
- if the current session does not have sufficient access rights to complete the operation.PathNotFoundException
- if the node atsrcAbsPath
insrcWorkspace
or the parent ofdestAbsPath
in this workspace does not exist.ItemExistsException
- if a property already exists atdestAbsPath
or a node already exist there, and same name siblings are not allowed or ifremoveExisting
is false and a UUID conflict occurs.LockException
- if a lock prevents the clone.RepositoryException
- if the last element ofdestAbsPath
has an index or if another error occurs.IllegalStateException
- See Also:
clone(Path, Path)
-
copy
public NodeId copy(Path srcPath, Path destPath, int flag) throws RepositoryException
Copies the tree atsrcPath
to the new location atdestPath
. Returns the id of the node at its new position.Precondition: the state manager needs to be in edit mode.
- Parameters:
srcPath
-destPath
-flag
- one ofCOPY
CLONE
CLONE_REMOVE_EXISTING
- Returns:
- the id of the node at its new position
- Throws:
RepositoryException
- if the copy operation fails
-
copy
public NodeId 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 atsrcPath
retrieved using the specifiedsrcStateMgr
to the new location atdestPath
. Returns the id of the node at its new position.Precondition: the state manager needs to be in edit mode.
- Parameters:
srcPath
-srcStateMgr
-srcHierMgr
-srcAccessMgr
-destPath
-flag
- one ofCOPY
CLONE
CLONE_REMOVE_EXISTING
- Returns:
- the id of the node at its new position
- Throws:
ConstraintViolationException
AccessDeniedException
VersionException
PathNotFoundException
ItemExistsException
LockException
RepositoryException
IllegalStateException
- if the state manager is not in edit mode.
-
move
public NodeId move(Path srcPath, Path destPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException
Moves the tree atsrcPath
to the new location atdestPath
. Returns the id of the moved node.Precondition: the state manager needs to be in edit mode.
- Parameters:
srcPath
-destPath
-- Returns:
- the id of the moved node
- Throws:
ConstraintViolationException
VersionException
AccessDeniedException
PathNotFoundException
ItemExistsException
LockException
RepositoryException
IllegalStateException
- if the state manager 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.
-
checkAddNode
public void checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, RepositoryException
Checks if adding a child node callednodeName
of node typenodeTypeName
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:
: make sure current session is granted read & write access on parent nodeItemValidator.CHECK_ACCESS
: make sure there's no foreign lock on parent nodeItemValidator.CHECK_LOCK
: make sure parent node is checked-outItemValidator.CHECK_CHECKED_OUT
: make sure no node type constraints would be violatedItemValidator.CHECK_CONSTRAINTS
: check for effective holds preventing the add operationItemValidator.CHECK_HOLD
: check for effective retention policy preventing the add operationItemValidator.CHECK_RETENTION
- 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:
: make sure current session is granted read access on parent and remove privilege on target nodeItemValidator.CHECK_ACCESS
: make sure there's no foreign lock on parent nodeItemValidator.CHECK_LOCK
: make sure parent node is checked-outItemValidator.CHECK_CHECKED_OUT
: make sure no node type constraints would be violatedItemValidator.CHECK_CONSTRAINTS
: make sure no references exist on target nodeItemValidator.CHECK_REFERENCES
: check for effective holds preventing the add operationItemValidator.CHECK_HOLD
: check for effective retention policy preventing the add operationItemValidator.CHECK_RETENTION
- 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:
: make sure current session is granted read access on parent and remove privilege on target nodeItemValidator.CHECK_ACCESS
: make sure there's no foreign lock on parent nodeItemValidator.CHECK_LOCK
: make sure parent node is checked-outItemValidator.CHECK_CHECKED_OUT
: make sure no node type constraints would be violatedItemValidator.CHECK_CONSTRAINTS
: make sure no references exist on target nodeItemValidator.CHECK_REFERENCES
: check for effective holds preventing the add operationItemValidator.CHECK_HOLD
: check for effective retention policy preventing the add operationItemValidator.CHECK_RETENTION
- 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 atnodePath
is writable. The following conditions must hold true:- the node must exist
- the current session must be granted read & write access on it
- the node must not be locked by another session
- the node must not be checked-in
- the node must not be protected
- the node must not be affected by a hold or a retention policy
- Parameters:
nodePath
- path of node to check- Throws:
PathNotFoundException
- if no node exists atnodePath
of the current session is not granted read access to the specified pathAccessDeniedException
- if write access to the specified path is not allowedConstraintViolationException
- if the node atnodePath
is protectedVersionException
- if the node atnodePath
is checked-inLockException
- if the node atnodePath
is locked by another sessionRepositoryException
- if another error occurs
-
verifyCanRead
public void verifyCanRead(Path nodePath) throws PathNotFoundException, RepositoryException
Verifies that the node atnodePath
can be read. The following conditions must hold true:- the node must exist
- the current session must be granted read access on it
- Parameters:
nodePath
- path of node to check- Throws:
PathNotFoundException
- if no node exists atnodePath
of the current session is not granted read access to the specified pathRepositoryException
- if another error occurs
-
createNodeState
public NodeState createNodeState(NodeState parent, Name nodeName, Name nodeTypeName, Name[] 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 manager is not in edit mode.
-
createNodeState
public NodeState createNodeState(NodeState parent, Name nodeName, Name nodeTypeName, Name[] mixinNames, NodeId id, QNodeDefinition 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, Name 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 manager is not in edit mode
-
createPropertyState
public PropertyState createPropertyState(NodeState parent, Name propName, int type, QPropertyDefinition 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 atnodePath
is checked-out; throws aVersionException
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 atnodePath
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 allowedRepositoryException
- if another error occurs
-
verifyNotProtected
protected void verifyNotProtected(Path nodePath) throws PathNotFoundException, ConstraintViolationException, RepositoryException
Verifies that the node atnodePath
is not protected.- Parameters:
nodePath
- path of node to check- Throws:
PathNotFoundException
- if no node exists atnodePath
ConstraintViolationException
- if write access to the specified path is not allowedRepositoryException
- if another error occurs
-
getNodeState
protected NodeState getNodeState(ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, Path nodePath) throws PathNotFoundException, RepositoryException
Retrieves the state of the node atnodePath
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
-
-