org.modeshape.graph.request
Class BatchRequestBuilder

java.lang.Object
  extended by org.modeshape.graph.request.BatchRequestBuilder

@NotThreadSafe
public class BatchRequestBuilder
extends Object

A component that can be used to build up a list of requests. This implementation does perform some simple optimizations, such as combining adjacent compatible requests.

This builder can be used to add multiple requests. When the enqueued requests are to be processed, calling pop() will remove and return the enqueued requests (as a CompositeRequest if there is more than one enqueued request).


Constructor Summary
BatchRequestBuilder()
           
BatchRequestBuilder(LinkedList<Request> requests)
           
 
Method Summary
 BatchRequestBuilder cloneBranch(Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForClone, Path.Segment exactSegmentForClone, boolean removeExisting)
          Add a request to clone a branch to another.
 BatchRequestBuilder cloneWorkspace(String nameOfWorkspaceToBeCloned, String desiredNameOfTargetWorkspace, CreateWorkspaceRequest.CreateConflictBehavior createConflictBehavior, CloneWorkspaceRequest.CloneConflictBehavior cloneConflictBehavior)
          Add a request to clone an existing workspace to create a new workspace, and specify the behavior should a workspace already exists with a name that matches the desired name for the new workspace.
 BatchRequestBuilder copyBranch(Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForCopy)
          Add a request to copy a branch to another.
 BatchRequestBuilder copyBranch(Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForCopy, NodeConflictBehavior conflictBehavior)
          Add a request to copy a branch to another.
 BatchRequestBuilder createNode(Location parentLocation, String workspaceName, Name childName, Iterator<Property> properties)
          Add a request to create a node with the given properties under the supplied location.
 BatchRequestBuilder createNode(Location parentLocation, String workspaceName, Name childName, Iterator<Property> properties, NodeConflictBehavior conflictBehavior)
          Add a request to create a node with the given properties under the supplied location.
 BatchRequestBuilder createNode(Location parentLocation, String workspaceName, Name childName, Property[] properties)
          Add a request to create a node with the given properties under the supplied location.
 BatchRequestBuilder createNode(Location parentLocation, String workspaceName, Name childName, Property[] properties, NodeConflictBehavior conflictBehavior)
          Add a request to create a node with the given properties under the supplied location.
 BatchRequestBuilder createWorkspace(String desiredNameOfNewWorkspace, CreateWorkspaceRequest.CreateConflictBehavior createConflictBehavior)
          Add a request to create a new workspace, and specify the behavior should a workspace already exists with a name that matches the desired name for the new workspace.
 BatchRequestBuilder deleteBranch(Location at, String workspaceName)
          Add a request to delete a branch.
 BatchRequestBuilder destroyWorkspace(String workspaceName)
          Add a request to destroy an existing workspace.
 void finishPendingRequest()
          Finish any pending request
 BatchRequestBuilder getWorkspaces()
          Add a request to obtain the information about the available workspaces.
 boolean hasRequests()
          Determine whether this builder has built any requests.
 BatchRequestBuilder moveBranch(Location from, Location into, Location before, String workspaceName, Name newNameForNode)
          Create a request to move a branch from one location into another.
 BatchRequestBuilder moveBranch(Location from, Location into, String workspaceName)
          Create a request to move a branch from one location into another.
 BatchRequestBuilder moveBranch(Location from, Location into, String workspaceName, Name newNameForNode)
          Create a request to move a branch from one location into another.
 BatchRequestBuilder moveBranch(Location from, Location into, String workspaceName, NodeConflictBehavior conflictBehavior)
          Create a request to move a branch from one location into another.
 Request pop()
          Remove and return any requests that have been built by this builder since the last call to this method.
 BatchRequestBuilder readAllChildren(Location of, String workspaceName)
          Add a request to read the children of a node at the supplied location in the designated workspace.
 BatchRequestBuilder readAllProperties(Location of, String workspaceName)
          Add a request to read the properties and number of children of a node at the supplied location.
 BatchRequestBuilder readBlockOfChildren(Location of, String workspaceName, int startingIndex, int count)
          Add a request to read a block of the children of a node at the supplied location.
 BatchRequestBuilder readBranch(Location at, String workspaceName)
          Add a request to read the branch at the supplied location, to a maximum depth of 2.
 BatchRequestBuilder readBranch(Location at, String workspaceName, int maxDepth)
          Add a request to read the branch (of given depth) at the supplied location.
 BatchRequestBuilder readNextBlockOfChildren(Location startingAfter, String workspaceName, int count)
          Add a request to read those children of a node that are immediately after a supplied sibling node.
 BatchRequestBuilder readNode(Location at, String workspaceName)
          Add a request to read the properties and number of children of a node at the supplied location.
 BatchRequestBuilder readProperty(Location of, String workspaceName, Name propertyName)
          Add a request to read the properties and number of children of a node at the supplied location.
 BatchRequestBuilder removeProperties(Location on, String workspaceName, Name... propertyNames)
          Add a request to remove from the node the properties with the supplied names.
 BatchRequestBuilder removeProperty(Location on, String workspaceName, Name propertyName)
          Add a request to remove the property with the supplied name from the given node.
 BatchRequestBuilder renameNode(Location at, String workspaceName, Name newName)
          Add a request to rename the node at the supplied location.
 BatchRequestBuilder setProperties(Location on, String workspaceName, Property... properties)
          Add a request to update the properties on the node at the supplied location.
 BatchRequestBuilder setProperty(Location on, String workspaceName, Property property)
          Add a request to update the property on the node at the supplied location.
 BatchRequestBuilder submit(Request request)
          Submit any request to this batch.
 String toString()
          
 BatchRequestBuilder verifyNodeExists(Location at, String workspaceName)
          Add a request to verify the existance and location of a node at the supplied location.
 BatchRequestBuilder verifyWorkspace(String workspaceName)
          Add a request to verify the existance of the named workspace.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BatchRequestBuilder

public BatchRequestBuilder()

BatchRequestBuilder

public BatchRequestBuilder(LinkedList<Request> requests)
Method Detail

hasRequests

public boolean hasRequests()
Determine whether this builder has built any requests.

Returns:
true if there are requests (i.e., pop() will return a non-null request), or false if there are no requests

finishPendingRequest

public void finishPendingRequest()
Finish any pending request


pop

public Request pop()
Remove and return any requests that have been built by this builder since the last call to this method. This method will return null if no requests have been built. If only one request was built, then it will be returned. If multiple requests have been built, then this method will return a CompositeRequest containing them.

Returns:
the request (or CompositeRequest) representing those requests that this builder has created since the last call to this method, or null if there are no requests to return

getWorkspaces

public BatchRequestBuilder getWorkspaces()
Add a request to obtain the information about the available workspaces.

Returns:
this builder for method chaining; never null

verifyWorkspace

public BatchRequestBuilder verifyWorkspace(String workspaceName)
Add a request to verify the existance of the named workspace.

Parameters:
workspaceName - the desired name of the workspace, or null if the source's default workspace should be used
Returns:
this builder for method chaining; never null

createWorkspace

public BatchRequestBuilder createWorkspace(String desiredNameOfNewWorkspace,
                                           CreateWorkspaceRequest.CreateConflictBehavior createConflictBehavior)
Add a request to create a new workspace, and specify the behavior should a workspace already exists with a name that matches the desired name for the new workspace.

Parameters:
desiredNameOfNewWorkspace - the desired name of the new workspace
createConflictBehavior - the behavior if a workspace already exists with the same name, or null if the default behavior should be used
Returns:
this builder for method chaining; never null

cloneWorkspace

public BatchRequestBuilder cloneWorkspace(String nameOfWorkspaceToBeCloned,
                                          String desiredNameOfTargetWorkspace,
                                          CreateWorkspaceRequest.CreateConflictBehavior createConflictBehavior,
                                          CloneWorkspaceRequest.CloneConflictBehavior cloneConflictBehavior)
Add a request to clone an existing workspace to create a new workspace, and specify the behavior should a workspace already exists with a name that matches the desired name for the new workspace.

Parameters:
nameOfWorkspaceToBeCloned - the name of the existing workspace that is to be cloned
desiredNameOfTargetWorkspace - the desired name of the target workspace
createConflictBehavior - the behavior if a workspace already exists with the same name
cloneConflictBehavior - the behavior if the workspace to be cloned does not exist
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the either workspace name is null

destroyWorkspace

public BatchRequestBuilder destroyWorkspace(String workspaceName)
Add a request to destroy an existing workspace.

Parameters:
workspaceName - the name of the workspace that is to be destroyed
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the workspace name is null

verifyNodeExists

public BatchRequestBuilder verifyNodeExists(Location at,
                                            String workspaceName)
Add a request to verify the existance and location of a node at the supplied location.

Parameters:
at - the location of the node to be verified
workspaceName - the name of the workspace containing the node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

readNode

public BatchRequestBuilder readNode(Location at,
                                    String workspaceName)
Add a request to read the properties and number of children of a node at the supplied location.

Parameters:
at - the location of the node to be read
workspaceName - the name of the workspace containing the node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

readAllChildren

public BatchRequestBuilder readAllChildren(Location of,
                                           String workspaceName)
Add a request to read the children of a node at the supplied location in the designated workspace.

Parameters:
of - the location of the node whose children are to be read
workspaceName - the name of the workspace
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

readAllProperties

public BatchRequestBuilder readAllProperties(Location of,
                                             String workspaceName)
Add a request to read the properties and number of children of a node at the supplied location.

Parameters:
of - the location of the node whose children are to be read
workspaceName - the name of the workspace
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

readProperty

public BatchRequestBuilder readProperty(Location of,
                                        String workspaceName,
                                        Name propertyName)
Add a request to read the properties and number of children of a node at the supplied location.

Parameters:
of - the location of the node whose children are to be read
workspaceName - the name of the workspace
propertyName - the name of the property to read
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

readBranch

public BatchRequestBuilder readBranch(Location at,
                                      String workspaceName)
Add a request to read the branch at the supplied location, to a maximum depth of 2.

Parameters:
at - the location of the branch
workspaceName - the name of the workspace containing the branch
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if the maximum depth is not positive

readBranch

public BatchRequestBuilder readBranch(Location at,
                                      String workspaceName,
                                      int maxDepth)
Add a request to read the branch (of given depth) at the supplied location.

Parameters:
at - the location of the branch
workspaceName - the name of the workspace containing the branch
maxDepth - the maximum depth to read
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if the maximum depth is not positive

readBlockOfChildren

public BatchRequestBuilder readBlockOfChildren(Location of,
                                               String workspaceName,
                                               int startingIndex,
                                               int count)
Add a request to read a block of the children of a node at the supplied location. The block is defined by the starting index of the first child and the number of children to include. Note that this index is not the same-name-sibiling index, but rather is the index of the child as if the children were in an array.

Parameters:
of - the location of the node whose children are to be read
workspaceName - the name of the workspace containing the parent
startingIndex - the zero-based index of the first child to be included in the block
count - the maximum number of children that should be included in the block
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null, if startingIndex is negative, or if count is less than 1.

readNextBlockOfChildren

public BatchRequestBuilder readNextBlockOfChildren(Location startingAfter,
                                                   String workspaceName,
                                                   int count)
Add a request to read those children of a node that are immediately after a supplied sibling node.

Parameters:
startingAfter - the location of the previous sibling that was the last child of the previous block of children read
workspaceName - the name of the workspace containing the node
count - the maximum number of children that should be included in the block
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the workspace name or startingAfter location is null, or if count is less than 1.

createNode

public BatchRequestBuilder createNode(Location parentLocation,
                                      String workspaceName,
                                      Name childName,
                                      Iterator<Property> properties)
Add a request to create a node with the given properties under the supplied location.

Parameters:
parentLocation - the location of the existing parent node, under which the new child should be created
workspaceName - the name of the workspace containing the parent
childName - the name of the new child to create under the existing parent
properties - the properties of the new node, which should include any identification properties for the new node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location, workspace name, or child name is null

createNode

public BatchRequestBuilder createNode(Location parentLocation,
                                      String workspaceName,
                                      Name childName,
                                      Iterator<Property> properties,
                                      NodeConflictBehavior conflictBehavior)
Add a request to create a node with the given properties under the supplied location.

Parameters:
parentLocation - the location of the existing parent node, under which the new child should be created
workspaceName - the name of the workspace containing the parent
childName - the name of the new child to create under the existing parent
properties - the properties of the new node, which should include any identification properties for the new node
conflictBehavior - the expected behavior if an equivalently-named child already exists under the into location
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location, workspace name, or child name is null

createNode

public BatchRequestBuilder createNode(Location parentLocation,
                                      String workspaceName,
                                      Name childName,
                                      Property[] properties)
Add a request to create a node with the given properties under the supplied location.

Parameters:
parentLocation - the location of the existing parent node, under which the new child should be created
workspaceName - the name of the workspace containing the parent
childName - the name of the new child to create under the existing parent
properties - the properties of the new node, which should include any identification properties for the new node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location, workspace name, or child name is null

createNode

public BatchRequestBuilder createNode(Location parentLocation,
                                      String workspaceName,
                                      Name childName,
                                      Property[] properties,
                                      NodeConflictBehavior conflictBehavior)
Add a request to create a node with the given properties under the supplied location.

Parameters:
parentLocation - the location of the existing parent node, under which the new child should be created
workspaceName - the name of the workspace containing the parent
childName - the name of the new child to create under the existing parent
properties - the properties of the new node, which should include any identification properties for the new node
conflictBehavior - the expected behavior if an equivalently-named child already exists under the into location
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location, workspace name, or child name is null

setProperty

public BatchRequestBuilder setProperty(Location on,
                                       String workspaceName,
                                       Property property)
Add a request to update the property on the node at the supplied location. This request will create the property if it does not yet exist.

Parameters:
on - the location of the node to be read
workspaceName - the name of the workspace containing the node
property - the new property on the node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if there are no properties to update

setProperties

public BatchRequestBuilder setProperties(Location on,
                                         String workspaceName,
                                         Property... properties)
Add a request to update the properties on the node at the supplied location.

Parameters:
on - the location of the node to be read
workspaceName - the name of the workspace containing the node
properties - the new properties on the node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if there are no properties to update

removeProperty

public BatchRequestBuilder removeProperty(Location on,
                                          String workspaceName,
                                          Name propertyName)
Add a request to remove the property with the supplied name from the given node. Supplying a name for a property that does not exist will not cause an error.

Parameters:
on - the location of the node to be read
workspaceName - the name of the workspace containing the node
propertyName - the name of the property that is to be removed
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if there are no properties to remove

removeProperties

public BatchRequestBuilder removeProperties(Location on,
                                            String workspaceName,
                                            Name... propertyNames)
Add a request to remove from the node the properties with the supplied names. Supplying a name for a property that does not exist will not cause an error.

Parameters:
on - the location of the node to be read
workspaceName - the name of the workspace containing the node
propertyNames - the names of the properties that are to be removed
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null or if there are no properties to remove

renameNode

public BatchRequestBuilder renameNode(Location at,
                                      String workspaceName,
                                      Name newName)
Add a request to rename the node at the supplied location.

Parameters:
at - the location of the node to be read
workspaceName - the name of the workspace containing the node
newName - the new name for the node
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

copyBranch

public BatchRequestBuilder copyBranch(Location from,
                                      String fromWorkspace,
                                      Location into,
                                      String intoWorkspace,
                                      Name nameForCopy)
Add a request to copy a branch to another.

Parameters:
from - the location of the top node in the existing branch that is to be copied
fromWorkspace - the name of the workspace where the from node exists
into - the location of the existing node into which the copy should be placed
intoWorkspace - the name of the workspace where the into node is to be copied
nameForCopy - the desired name for the node that results from the copy, or null if the name of the original should be used
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if either of the locations or workspace names are null

copyBranch

public BatchRequestBuilder copyBranch(Location from,
                                      String fromWorkspace,
                                      Location into,
                                      String intoWorkspace,
                                      Name nameForCopy,
                                      NodeConflictBehavior conflictBehavior)
Add a request to copy a branch to another.

Parameters:
from - the location of the top node in the existing branch that is to be copied
fromWorkspace - the name of the workspace where the from node exists
into - the location of the existing node into which the copy should be placed
intoWorkspace - the name of the workspace where the into node is to be copied
nameForCopy - the desired name for the node that results from the copy, or null if the name of the original should be used
conflictBehavior - the expected behavior if an equivalently-named child already exists at the into location, or null if the default node conflict behavior should be used
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if either of the locations or workspace names are null

cloneBranch

public BatchRequestBuilder cloneBranch(Location from,
                                       String fromWorkspace,
                                       Location into,
                                       String intoWorkspace,
                                       Name nameForClone,
                                       Path.Segment exactSegmentForClone,
                                       boolean removeExisting)
Add a request to clone a branch to another.

Parameters:
from - the location of the top node in the existing branch that is to be cloned
fromWorkspace - the name of the workspace where the from node exists
into - the location of the existing node into which the clone should be placed
intoWorkspace - the name of the workspace where the into node is to be cloned
nameForClone - the desired name for the node that results from the clone, or null if the name of the original should be used
exactSegmentForClone - the exact segment at which the cloned tree should be rooted.
removeExisting - whether any nodes in the intoWorkspace with the same UUIDs as a node in the source branch should be removed (if true) or a UuidAlreadyExistsException should be thrown.
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if any of the parameters are null except for nameForClone or exactSegmentForClone. Exactly one of nameForClone and exactSegmentForClone must be null.

moveBranch

public BatchRequestBuilder moveBranch(Location from,
                                      Location into,
                                      String workspaceName)
Create a request to move a branch from one location into another.

Parameters:
from - the location of the top node in the existing branch that is to be moved
into - the location of the existing node into which the branch should be moved
workspaceName - the name of the workspace
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if any of the parameters are null

moveBranch

public BatchRequestBuilder moveBranch(Location from,
                                      Location into,
                                      String workspaceName,
                                      Name newNameForNode)
Create a request to move a branch from one location into another.

Parameters:
from - the location of the top node in the existing branch that is to be moved
into - the location of the existing node into which the branch should be moved
workspaceName - the name of the workspace
newNameForNode - the new name for the node being moved, or null if the name of the original should be used
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if any of the parameters are null

moveBranch

public BatchRequestBuilder moveBranch(Location from,
                                      Location into,
                                      Location before,
                                      String workspaceName,
                                      Name newNameForNode)
Create a request to move a branch from one location into another.

Parameters:
from - the location of the top node in the existing branch that is to be moved
into - the location of the existing node into which the branch should be moved
before - the location of the node before which the branch should be moved; may be null
workspaceName - the name of the workspace
newNameForNode - the new name for the node being moved, or null if the name of the original should be used
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if any of the parameters are null

moveBranch

public BatchRequestBuilder moveBranch(Location from,
                                      Location into,
                                      String workspaceName,
                                      NodeConflictBehavior conflictBehavior)
Create a request to move a branch from one location into another.

Parameters:
from - the location of the top node in the existing branch that is to be moved
into - the location of the existing node into which the branch should be moved
workspaceName - the name of the workspace
conflictBehavior - the expected behavior if an equivalently-named child already exists at the into location
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if any of the parameters are null

deleteBranch

public BatchRequestBuilder deleteBranch(Location at,
                                        String workspaceName)
Add a request to delete a branch.

Parameters:
at - the location of the top node in the existing branch that is to be deleted
workspaceName - the name of the workspace containing the parent
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the location or workspace name is null

submit

public BatchRequestBuilder submit(Request request)
Submit any request to this batch.

Parameters:
request - the request to be batched; may not be null
Returns:
this builder for method chaining; never null
Throws:
IllegalArgumentException - if the request is null

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()


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