org.modeshape.graph.connector.base
Class BaseTransaction<NodeType extends Node,WorkspaceType extends Workspace>

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

@NotThreadSafe
public abstract class BaseTransaction<NodeType extends Node,WorkspaceType extends Workspace>
extends Object
implements Transaction<NodeType,WorkspaceType>


Field Summary
protected  ExecutionContext context
           
protected  NameFactory nameFactory
           
protected  PathFactory pathFactory
           
protected  PropertyFactory propertyFactory
           
protected  Location rootLocation
           
protected  UUID rootNodeUuid
           
protected  ValueFactories valueFactories
           
 
Constructor Summary
protected BaseTransaction(ExecutionContext context, Repository<NodeType,WorkspaceType> repository, UUID rootNodeUuid)
           
 
Method Summary
 void commit()
          Commit any changes that have been made to the repository.
 ExecutionContext getContext()
          Get the context in which this operator executes.
 NodeType getFirstChild(WorkspaceType workspace, NodeType parent, Name childName)
          Find in the supplied parent node the first child with the supplied name.
protected  NodeType getNode(WorkspaceType workspace, Path path, Location location)
           
protected  Repository<NodeType,WorkspaceType> getRepository()
          Obtain the repository object against which this transaction is running.
 NodeType getRootNode(WorkspaceType workspace)
          Get the root node of the repository workspace.
 Set<String> getWorkspaceNames()
          Get the names of the existing workspaces.
 void lockNode(WorkspaceType workspace, NodeType node, LockBranchRequest.LockScope lockScope, long lockTimeoutInMillis)
          Attempts to lock the given node with the given timeout.
 Path pathFor(WorkspaceType workspace, NodeType node)
          Returns the path for the given node with this workspace if one exists, or a null if no node exists at the given path.
protected  String readable(Object obj)
           
 void rollback()
          Rollback any changes that have been made to this repository.
 void unlockNode(WorkspaceType workspace, NodeType node)
          Attempts to unlock the given node.
 
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
addChild, addChild, cloneNode, copyNode, destroyWorkspace, getChild, getChildren, getNode, getParent, getWorkspace, query, removeAllChildren, removeNode, removeProperty, search, setProperties
 

Field Detail

rootNodeUuid

protected final UUID rootNodeUuid

context

protected final ExecutionContext context

pathFactory

protected final PathFactory pathFactory

nameFactory

protected final NameFactory nameFactory

propertyFactory

protected final PropertyFactory propertyFactory

valueFactories

protected final ValueFactories valueFactories

rootLocation

protected final Location rootLocation
Constructor Detail

BaseTransaction

protected BaseTransaction(ExecutionContext context,
                          Repository<NodeType,WorkspaceType> repository,
                          UUID rootNodeUuid)
Method Detail

readable

protected String readable(Object obj)

getContext

public ExecutionContext getContext()
Get the context in which this operator executes.

Specified by:
getContext in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Returns:
the execution context; never null
See Also:
Transaction.getContext()

getRepository

protected Repository<NodeType,WorkspaceType> getRepository()
Obtain the repository object against which this transaction is running.

Returns:
the repository object; never null

getWorkspaceNames

public Set<String> getWorkspaceNames()
Get the names of the existing workspaces.

Specified by:
getWorkspaceNames in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Returns:
the immutable set of workspace names; never null
See Also:
Transaction.getWorkspaceNames()

getRootNode

public NodeType getRootNode(WorkspaceType workspace)
Get the root node of the repository workspace.

Specified by:
getRootNode in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Parameters:
workspace - the workspace; may not be null
Returns:
the root node; never null
See Also:
Transaction.getRootNode(org.modeshape.graph.connector.base.Workspace)

getNode

protected NodeType getNode(WorkspaceType workspace,
                           Path path,
                           Location location)

pathFor

public Path pathFor(WorkspaceType workspace,
                    NodeType node)
Returns the path for the given node with this workspace if one exists, or a null if no node exists at the given path.

Specified by:
pathFor in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Parameters:
workspace - the workspace; may not be null
node - the node for which the path should be retrieved; may not be null
Returns:
the path for the given node with this workspace if one exists or null if the node does not exist in this workspace
See Also:
Transaction.pathFor(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node)

getFirstChild

public NodeType getFirstChild(WorkspaceType workspace,
                              NodeType parent,
                              Name childName)
Find in the supplied parent node the first child with the supplied name. This method returns null if the parent has no such child.

This method is implemented by iterating through the children, looking for the first child that has a matching name. Obviously this may be implemented more efficiently in certain systems. For example, an implementation might create a path by appending the child name to the supplied parent, and find the node with this path.

Specified by:
getFirstChild in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Parameters:
workspace - the workspace; may not be null
parent - the parent node; may not be null
childName - the name of the child; may not be null
Returns:
the child of this node; or null if no such child exists
See Also:
Transaction.getFirstChild(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.property.Name)

lockNode

public void lockNode(WorkspaceType workspace,
                     NodeType node,
                     LockBranchRequest.LockScope lockScope,
                     long lockTimeoutInMillis)
              throws LockFailedException
Attempts to lock the given node with the given timeout. If the lock attempt fails, a LockFailedException will be thrown.

Specified by:
lockNode in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Parameters:
workspace - the workspace; may not be null
node - the node to be locked; may not be null
lockScope - the scope of the lock (i.e., whether descendants of node should be included in the lock
lockTimeoutInMillis - the maximum lifetime of the lock in milliseconds; zero (0) indicates that the connector default should be used
Throws:
LockFailedException - if the implementing connector supports locking but the lock could not be acquired.
See Also:
Transaction.lockNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.Node, org.modeshape.graph.request.LockBranchRequest.LockScope, long)

unlockNode

public void unlockNode(WorkspaceType workspace,
                       NodeType node)
Attempts to unlock the given node.

Specified by:
unlockNode in interface Transaction<NodeType extends Node,WorkspaceType extends Workspace>
Parameters:
workspace - the workspace; may not be null
node - the node to be unlocked; may not be null
See Also:
Transaction.unlockNode(org.modeshape.graph.connector.base.Workspace, org.modeshape.graph.connector.base.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 Node,WorkspaceType extends Workspace>
See Also:
Transaction.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 Node,WorkspaceType extends Workspace>
See Also:
Transaction.rollback()


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