7.1.7 Moving and Copying

Moving and copying of nodes is done through methods of the Session and Workspace interfaces.

Session provides a move method:

javax.jcr.
Session

void

move(String srcAbsPath, String destAbsPath)

Moves the node at srcAbsPath (and its entire subtree) to the new location at destAbsPath.

In order to persist the change, save must be called on either the session or a common ancestor to both the source and destination locations.

A ConstraintViolationException is thrown either immediately (by this method) or on save if performing this operation would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

As well, a ConstraintViolationException will be thrown on save if an attempt is made to save only either the source or destination node separately.

Note that this behavior differs from that of Workspace.move (see below), which operates directly in the persistent workspace and does not require a save.

The destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown immediately. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the moved node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the newly moved node is appended to the end of the child node list.

This method cannot be used to move just an individual property by itself. It moves an entire node and its subtree (including, of course, any properties contained therein).

If no node exists at srcAbsPath or no node exists one level above destAbsPath (in other words, there is no node that will serve as the parent of the moved item) then a PathNotFoundException is thrown either immediately or on save. Implementations may differ on when this validation is performed.

An ItemExistsException is thrown either immediately or on save if a property already exists at destAbsPath or a node already exists there and same-name siblings are not allowed. Implementations may differ on when this validation is performed.

A VersionException is thrown either immediately or on save if the parent node of destAbsPath or the parent node of srcAbsPath is versionable and checked-in, or is non-versionable and its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

A LockException is thrown either immediately or on save if a lock prevents the move. Implementations may differ on when this validation is performed.

A RepositoryException is thrown if another error occurs.


Workspace
provides a move method as well as the methods copy and clone:

javax.jcr.
Workspace

void

copy(String srcAbsPath,
String destAbsPath)

This method copies the node at srcAbsPath and its entire subtree to the new location at destAbsPath. This operation is performed entirely within the persistent workspace, it does not involve transient storage and therefore does not require a save.

Copies of referenceable nodes are automatically given new UUIDs.

The destAbsPath provided must not have an index on its final element. If it does, then a RepositoryException is thrown. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the copied node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the newly moved node is appended to the end of the child node list.

This method cannot be used to copy just an individual property by itself. It copies an entire node and its subtree (including, of course, any properties contained therein).

A ConstraintViolationException is thrown if the operation would violate a node-type or other implementation-specific constraint.

A VersionException is thrown if the parent node of destAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

An AccessDeniedException is thrown if the current session (i.e., the session that was used to acquire this Workspace object) does not have sufficient access permissions to complete the operation.

A PathNotFoundException is thrown if the node at srcAbsPath or the parent of destAbsPath does not exist.

An ItemExistsException is thrown if a property already exists at destAbsPath or a node already exists there and same-name siblings are not allowed.

A LockException is thrown if a lock prevents the copy.

A RepositoryException is thrown if another error occurs.

void

copy(String srcWorkspace,
String srcAbsPath,
String destAbsPath)

This method copies the subtree at srcAbsPath in srcWorkspace to destAbsPath in this workspace. Unlike clone, this method does assign new UUIDs to the new copies of referenceable nodes. This operation is performed entirely within the persistent workspace, it does not involve transient storage and therefore does not require a save.

The destAbsPath provided must not have an index on its final element. If it does, then a RepositoryException is thrown. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the copied node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the new copy of the node is appended to the end of the child node list.

This method cannot be used to copy just an individual property by itself. It copies an entire node and its subtree (including, of course, any properties contained therein).

A NoSuchWorkspaceException is thrown if srcWorkspace does not exist.

A ConstraintViolationException is thrown if the operation would violate a node-type or other implementation-specific constraint.

A VersionException is thrown if the parent node of destAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

An AccessDeniedException is thrown if the current session (i.e., the session that was used to acquire this Workspace object) does not have sufficient access permissions to complete the operation.

A PathNotFoundException is thrown if the node at srcAbsPath in srcWorkspace or the parent of destAbsPath in this workspace does not exist.

An ItemExistsException is thrown if a property already exists at destAbsPath or a node already exists there and same-name siblings are not allowed.

A LockException is thrown if a lock prevents the copy.

A RepositoryException is thrown if another error occurs.

void

clone(String srcWorkspace,
String srcAbsPath,
String destAbsPath,
boolean removeExisting)

Clones the subtree at the node srcAbsPath in srcWorkspace workspace to destAbsPath in this workspace. Unlike the signature of copy that copies between workspaces, this method does not assign new UUIDs to new referenceable nodes but preserves the UUIDs of their respective source nodes.

If removeExisting is true and an existing node in this workspace (the destination workspace) has the same UUID as a node being cloned from srcWorkspace, then the incoming node takes precedence, and the existing node (and its subtree) is removed. If removeExisting is false then a UUID collision causes this method to throw a ItemExistsException and no changes are made.

If successful, the changes are persisted immediately, there is no need to call save.

The destAbsPath provided must not have an index on its final element. If it does, then a RepositoryException is thrown. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the copied node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the new clone of the node moved node is appended to the end of the child node list.

This method cannot be used to clone just an individual property by itself. It clones an entire node and its subtree (including, of course, any properties contained therein).

A NoSuchWorkspaceException is thrown if srcWorkspace does not exist.

A ConstraintViolationException is thrown if the operation would violate a node-type or other implementation-specific constraint

A VersionException is thrown if the parent node of destAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

An AccessDeniedException is thrown if the current session (i.e. the session that was used to acquire this Workspace object) does not have sufficient access permissions to complete the operation.

A PathNotFoundException is thrown if the node at srcAbsPath in srcWorkspace or the parent of destAbsPath in this workspace do not exist.

An ItemExistsException is thrown if a property already exists at destAbsPath or a node already exists there and same-name siblings are not allowed or if removeExisting is false and a UUID conflict occurs.

A LockException is thrown if a lock prevents the clone.

A RepositoryException if another error occurs.

void

move(String srcAbsPath, String destAbsPath)

Moves the node at srcPath (and its entire subtree) to the new location at destPath. If successful, the change is persisted immediately, there is no need to call save. Note that this is in contrast to Session.move which operates within the transient space and hence requires a save.

The destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the moved node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the newly moved node is appended to the end of the child node list.

This method cannot be used to move just an individual property by itself. It moves an entire node and its subtree (including, of course, any properties contained therein).

A ConstraintViolationException is thrown if the operation would violate a node-type or other implementation-specific constraint

A VersionException is thrown if the parent node of destAbsPath or the parent node of srcAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

An AccessDeniedException is thrown if the current session does not have sufficient access permissions to complete the operation.

A PathNotFoundException is thrown if the item at srcAbsPath or the parent of destAbsPath does not exist.

An ItemExistsException is thrown if a property already exists at destAbsPath or a node already exists there and same-name siblings are not allowed.

A LockException is thrown if a lock prevents the move.

A RepositoryException is thrown if another error occurs.