org.modeshape.graph.connector.base
Class PathTransaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>

java.lang.Object
  extended by org.modeshape.graph.connector.base.BaseTransaction<NodeType,WorkspaceType>
      extended by org.modeshape.graph.connector.base.PathTransaction<NodeType,WorkspaceType>
Type Parameters:
WorkspaceType - the type of workspace
NodeType - the type of node
All Implemented Interfaces:
Transaction<NodeType,WorkspaceType>
Direct Known Subclasses:
JdbcMetadataRepository.JdbcMetadataTransaction

@NotThreadSafe
public abstract class PathTransaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>
extends BaseTransaction<NodeType,WorkspaceType>

An implementation of Transaction that maintains a cache of nodes by their path.


Nested Class Summary
protected  class PathTransaction.WorkspaceChanges
          Record of the changes made to a particular workspace.
 
Field Summary
 
Fields inherited from class org.modeshape.graph.connector.base.BaseTransaction
context, nameFactory, pathFactory, propertyFactory, rootLocation, rootNodeUuid, valueFactories
 
Constructor Summary
protected PathTransaction(Repository<NodeType,WorkspaceType> repository, UUID rootNodeUuid)
          Create a new transaction.
 
Method Summary
 NodeType addChild(WorkspaceType workspace, NodeType parent, Name name, int index, UUID uuid, Iterable<Property> properties)
          Creates a new child node under the supplied parent, where the new child will have the specified name, properties, and (optionally) UUID.
 Location addChild(WorkspaceType workspace, NodeType parent, NodeType newChild, NodeType beforeOtherChild, Name desiredName)
          Inserts the specified child at the specified position in the list of children.
 NodeType cloneNode(WorkspaceType originalWorkspace, NodeType original, WorkspaceType newWorkspace, NodeType newParent, Name desiredName, Path.Segment desiredSegment, boolean removeExisting, Set<Location> removedExistingNodes)
          This should clone the subgraph given by the original node and place the cloned copy under the supplied new parent.
 void commit()
          Commit any changes that have been made to the repository.
protected  NodeType copyBranch(WorkspaceType originalWorkspace, NodeType original, PathTransaction.WorkspaceChanges newWorkspaceChanges, WorkspaceType newWorkspace, NodeType newParent)
           
 NodeType copyNode(WorkspaceType originalWorkspace, NodeType original, WorkspaceType newWorkspace, NodeType newParent, Name desiredName, boolean recursive)
          This should copy the subgraph given by the original node and place the new copy under the supplied new parent.
protected abstract  NodeType createNode(Path.Segment name, Path parentPath, Iterable<Property> properties)
          Create a new instance of the node, given the supplied name and parent path.
protected  void destroyNode(WorkspaceType workspace, NodeType node)
          Destroy the node.
protected  NodeType findNode(WorkspaceType workspace, Path path)
          Attempt to find the node with the supplied path.
protected  PathTransaction.WorkspaceChanges getChangesFor(WorkspaceType workspace, boolean createIfMissing)
          Get the changes for the supplied workspace, optionally creating the necessary object if it does not yet exist.
 NodeType getChild(WorkspaceType workspace, NodeType parent, Path.Segment childSegment)
          Find in the supplied parent node the child with the supplied name and same-name-sibling index.
 List<NodeType> getChildren(WorkspaceType workspace, NodeType node)
          Get the children for the supplied node.
 NodeType getNode(WorkspaceType workspace, Location location)
          Find the node with the supplied unique identifier.
 NodeType getParent(WorkspaceType workspace, NodeType node)
          Returns the parent of the supplied node.
protected  Path pathTo(NodeType node)
          Returns the path to the given node
protected  void print(WorkspaceType workspace, NodeType node, int level)
           
 QueryResults query(WorkspaceType workspace, AccessQueryRequest accessQuery)
          Perform a query of this workspace.
 void removeAllChildren(WorkspaceType workspace, NodeType node)
          Removes all of the children for this node in a single operation.
 Location removeNode(WorkspaceType workspace, NodeType node)
          Removes the given node from the repository.
 NodeType removeProperty(WorkspaceType workspace, NodeType node, Name propertyName)
          Removes the property with the given name
 void rollback()
          Rollback any changes that have been made to this repository.
 QueryResults search(WorkspaceType workspace, FullTextSearchRequest search)
          Perform a full-text search of this workspace.
 NodeType setProperties(WorkspaceType workspace, NodeType node, Iterable<Property> propertiesToSet, Iterable<Name> propertiesToRemove, boolean removeAllExisting)
          Sets the given properties in a single operation, overwriting any previous properties for the same name.
protected  void validateNode(WorkspaceType workspace, NodeType node)
           
 
Methods inherited from class org.modeshape.graph.connector.base.BaseTransaction
getContext, getFirstChild, getNode, getRepository, getRootNode, getWorkspaceNames, lockNode, pathFor, readable, unlockNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.modeshape.graph.connector.base.Transaction
destroyWorkspace, getWorkspace
 

Constructor Detail

PathTransaction

protected PathTransaction(Repository<NodeType,WorkspaceType> repository,
                          UUID rootNodeUuid)
Create a new transaction.

Parameters:
repository - the repository against which the transaction will be operating; may not be null
rootNodeUuid - the UUID of the root node; may not be null
Method Detail

getChangesFor

protected PathTransaction.WorkspaceChanges getChangesFor(WorkspaceType workspace,
                                                         boolean createIfMissing)
Get the changes for the supplied workspace, optionally creating the necessary object if it does not yet exist. The changes object is used to record the changes made to the workspace by operations within this transaction, which are either pushed into the workspace upon commit() or cleared upon rollback().

Parameters:
workspace - the workspace
createIfMissing - true if the changes object should be created if it does not yet exist, or false otherwise
Returns:
the changes object; may be null if createIfMissing is false and the changes object does not yet exist, or never null if createIfMissing is true

getNode

public NodeType getNode(WorkspaceType workspace,
                        Location location)
Find the node with the supplied unique identifier.

Parameters:
workspace - the workspace; may not be null
location - of the node; may not be null
Returns:
the node, or null if there is no node with the supplied identifier
See Also:
Transaction.getNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.Location)

findNode

protected NodeType findNode(WorkspaceType workspace,
                            Path path)
Attempt to find the node with the supplied path. This method is "Changes-aware". That is, it checks the cache of changes for the workspace before returning the node.

Parameters:
workspace - the workspace; may not be null
path - the path of the node; may not be null
Returns:
the node, or null if no such node exists

destroyNode

protected void destroyNode(WorkspaceType workspace,
                           NodeType node)
Destroy the node.

Parameters:
workspace - the workspace; never null
node - the node to be destroyed

pathTo

protected Path pathTo(NodeType node)
Returns the path to the given node

Parameters:
node - the node for which the path should be returned; may not be null
Returns:
the path to that node

addChild

public NodeType addChild(WorkspaceType workspace,
                         NodeType parent,
                         Name name,
                         int index,
                         UUID uuid,
                         Iterable<Property> properties)
Creates a new child node under the supplied parent, where the new child will have the specified name, properties, and (optionally) UUID. The child will be appended to the list of children, and will be given the appropriate same-name-sibling index.

Parameters:
workspace - the workspace; may not be null
parent - the parent node; may not be null
name - the name; may not be null
index - index at which the specified child is to be inserted, or -1 if the child is to be appended
uuid - the UUID of the node, or null if the UUID is to be generated
properties - the properties for the new node; may be null if there are no other properties
Returns:
the representation of the new node
See Also:
Transaction.addChild(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name, int, java.util.UUID, java.lang.Iterable)

addChild

public Location addChild(WorkspaceType workspace,
                         NodeType parent,
                         NodeType newChild,
                         NodeType beforeOtherChild,
                         Name desiredName)
Inserts the specified child at the specified position in the list of children. Shifts the child currently at that position (if any) and any subsequent children to the right (adds one to their indices). The child is automatically removed from its existing parent (if it has one), though this method can be used to reorder a child within the same parent.

This method can also be used to rename an existing child by 'moving' the child node to the existing parent and a new desired name. However, if no 'beforeOtherChild' is supplied, then the node being renamed will also be moved to the end of the children.

Parameters:
workspace - the workspace; may not be null
parent - the parent node; may not be null
newChild - the node that is to be added as a child of the parent; may not be null
beforeOtherChild - the existing child before which the child is to be added; may be null if the child is to be added at the end
desiredName - the desired name for the node; may be null if the new child node's name is to be kept
Returns:
the actual location of the node, or null if the node didn't exist
See Also:
Transaction.addChild(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.connector.base.Node, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name)

createNode

protected abstract NodeType createNode(Path.Segment name,
                                       Path parentPath,
                                       Iterable<Property> properties)
Create a new instance of the node, given the supplied name and parent path. This method should do nothing but instantiate the new node; the caller will add to the appropriate internal structures.

Parameters:
name - the name of the new node; may be null if this is the root node
parentPath - the path of the parent node; may be null if this is the root node
properties - the properties; may be null if there are no properties
Returns:
the new node; never null

getChild

public NodeType getChild(WorkspaceType workspace,
                         NodeType parent,
                         Path.Segment childSegment)
Find in the supplied parent node the child with the supplied name and same-name-sibling index. This method returns null if the parent has no such child.

Parameters:
workspace - the workspace; may not be null
parent - the parent node; may not be null
childSegment - the segment of the child; may not be null
Returns:
the child of this node; or null if no such child exists
See Also:
Transaction.getChild(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Path.Segment)

getChildren

public List<NodeType> getChildren(WorkspaceType workspace,
                                  NodeType node)
Get the children for the supplied node.

Parameters:
workspace - the workspace; may not be null
node - the node whose children are to be returned; may not be null
Returns:
the children, never null but possibly empty
See Also:
Transaction.getChildren(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node)

getParent

public NodeType getParent(WorkspaceType workspace,
                          NodeType node)
Returns the parent of the supplied node. This method returns null if the supplied node is the root node.

Parameters:
workspace - the workspace; may not be null
node - the child node; may not be null
Returns:
the parent of this node; or null if the node is the root node for its workspace
See Also:
Transaction.getParent(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node)

removeAllChildren

public void removeAllChildren(WorkspaceType workspace,
                              NodeType node)
Removes all of the children for this node in a single operation.

Parameters:
workspace - the workspace; may not be null
node - the node whose children are to be removed; may not be null
See Also:
Transaction.removeAllChildren(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node)

removeNode

public Location removeNode(WorkspaceType workspace,
                           NodeType node)
Removes the given node from the repository.

Parameters:
workspace - the workspace; may not be null
node - the node to be removed; may not be null
Returns:
the actual location of the node, or null if the node didn't exist
See Also:
Transaction.removeNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node)

removeProperty

public NodeType removeProperty(WorkspaceType workspace,
                               NodeType node,
                               Name propertyName)
Removes the property with the given name

Parameters:
workspace - the workspace; may not be null
node - the node; may not be null
propertyName - the name of the property to remove; may not be null
Returns:
this map node
See Also:
Transaction.removeProperty(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name)

setProperties

public NodeType setProperties(WorkspaceType workspace,
                              NodeType node,
                              Iterable<Property> propertiesToSet,
                              Iterable<Name> propertiesToRemove,
                              boolean removeAllExisting)
Sets the given properties in a single operation, overwriting any previous properties for the same name. This bulk mutator should be used when multiple properties are being set in order to allow underlying implementations to optimize their access to their respective persistent storage mechanism. The implementation should not change the identification properties.

Parameters:
workspace - the workspace; may not be null
node - the node; may not be null
propertiesToSet - the properties to set; may be null or empty if there are no properties being added or set
propertiesToRemove - the names of the properties that are to be removed; may be null or empty if no properties are being removed
removeAllExisting - true if all existing, non-identification properties should be removed, or false otherwise
Returns:
this map node
See Also:
Transaction.setProperties(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, java.lang.Iterable, java.lang.Iterable, boolean)

copyNode

public NodeType copyNode(WorkspaceType originalWorkspace,
                         NodeType original,
                         WorkspaceType newWorkspace,
                         NodeType newParent,
                         Name desiredName,
                         boolean recursive)
This should copy the subgraph given by the original node and place the new copy under the supplied new parent. Note that internal references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.

Parameters:
originalWorkspace - the workspace containing the original node that is being cloned; may not be null
original - the node to be copied; may not be null
newWorkspace - the workspace containing the new parent node; may not be null
newParent - the parent where the copy is to be placed; may not be null
desiredName - the desired name for the node; if null, the name will be obtained from the original node
recursive - true if the copy should be recursive
Returns:
the new node, which is the top of the new subgraph
See Also:
Transaction.copyNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name, boolean)

print

protected void print(WorkspaceType workspace,
                     NodeType node,
                     int level)

cloneNode

public NodeType cloneNode(WorkspaceType originalWorkspace,
                          NodeType original,
                          WorkspaceType newWorkspace,
                          NodeType newParent,
                          Name desiredName,
                          Path.Segment desiredSegment,
                          boolean removeExisting,
                          Set<Location> removedExistingNodes)
                                    throws UuidAlreadyExistsException
This should clone the subgraph given by the original node and place the cloned copy under the supplied new parent. Note that internal references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.

Parameters:
originalWorkspace - the workspace containing the original node that is being cloned; may not be null
original - the node to be cloned; may not be null
newWorkspace - the workspace containing the new parent node; may not be null
newParent - the parent where the clone is to be placed; may not be null
desiredName - the desired name for the node; if null, the name will be calculated from desiredSegment; Exactly one of desiredSegment and desiredName must be non-null
desiredSegment - the exact segment at which the clone should be rooted; if null, the name will be inferred from desiredName; Exactly one of desiredSegment and desiredName must be non-null
removeExisting - true if existing nodes in the new workspace with the same UUIDs as nodes in the branch rooted at original should be removed; if false, a UuidAlreadyExistsException will be thrown if a UUID conflict is detected
removedExistingNodes - the set into which should be placed all of the existing nodes that were removed as a result of this clone operation, or null if these nodes need not be collected
Returns:
the new node, which is the top of the new subgraph
Throws:
UuidAlreadyExistsException - if removeExisting is true and and a UUID in the source tree already exists in the new workspace
See Also:
Transaction.cloneNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name, org.modeshape.graph.property.Path.Segment, boolean, java.util.Set)

copyBranch

protected NodeType copyBranch(WorkspaceType originalWorkspace,
                              NodeType original,
                              PathTransaction.WorkspaceChanges newWorkspaceChanges,
                              WorkspaceType newWorkspace,
                              NodeType newParent)

query

public QueryResults query(WorkspaceType workspace,
                          AccessQueryRequest accessQuery)
Perform a query of this workspace.

This implementation does not support querying the repository contents, so this method returns null. Subclasses can override this if they do support querying.

Parameters:
workspace - the workspace to be searched; may not be null
accessQuery - the access query; may not be null
Returns:
the query results, or null if the query is not supported
See Also:
Transaction.query(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.request.AccessQueryRequest)

search

public QueryResults search(WorkspaceType workspace,
                           FullTextSearchRequest search)
Perform a full-text search of this workspace.

This implementation does not support searching the repository contents, so this method returns null. Subclasses can override this if they do support searching.

Parameters:
workspace - the workspace to be searched; may not be null
search - the full-text search; may not be null
Returns:
the query results, or null if the query is not supported
See Also:
Transaction.search(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.request.FullTextSearchRequest)

validateNode

protected void validateNode(WorkspaceType workspace,
                            NodeType node)

commit

public void commit()
Commit any changes that have been made to the repository. This method may throw runtime exceptions if there are failures committing the changes, but the transaction is still expected to be closed.

Specified by:
commit in interface Transaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>
Overrides:
commit in class BaseTransaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>
See Also:
BaseTransaction.commit()

rollback

public void rollback()
Rollback any changes that have been made to this repository. This method may throw runtime exceptions if there are failures rolling back the changes, but the transaction is still expected to be closed.

Specified by:
rollback in interface Transaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>
Overrides:
rollback in class BaseTransaction<NodeType extends PathNode,WorkspaceType extends PathWorkspace<NodeType>>
See Also:
BaseTransaction.rollback()


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.