org.modeshape.connector.store.jpa.model.basic
Class BasicRequestProcessor

java.lang.Object
  extended by org.modeshape.graph.request.processor.RequestProcessor
      extended by org.modeshape.connector.store.jpa.model.basic.BasicRequestProcessor

@NotThreadSafe
public class BasicRequestProcessor
extends RequestProcessor

A RequestProcessor implementation for the JPA connector.


Nested Class Summary
protected static class BasicRequestProcessor.ActualLocation
           
protected  class BasicRequestProcessor.LargeValueSerializer
           
protected  class BasicRequestProcessor.NextChildIndexes
           
protected  class BasicRequestProcessor.RecordingLargeValues
           
protected  class BasicRequestProcessor.References
           
protected  class BasicRequestProcessor.SkippedLargeValues
           
 
Nested classes/interfaces inherited from class org.modeshape.graph.request.processor.RequestProcessor
RequestProcessor.LocationWithDepth
 
Field Summary
protected  RequestProcessorCache cache
           
protected  boolean compressData
           
protected  boolean creatingWorkspacesAllowed
           
protected  boolean enforceReferentialIntegrity
           
protected  javax.persistence.EntityManager entities
           
protected  long largeValueMinimumSizeInBytes
           
protected  Logger logger
           
protected  NameFactory nameFactory
           
protected  String nameOfDefaultWorkspace
           
protected  Namespaces namespaces
           
protected  PathFactory pathFactory
           
protected  String[] predefinedWorkspaceNames
           
protected  PropertyFactory propertyFactory
           
protected  UUID rootNodeUuid
           
protected  String rootNodeUuidString
           
protected  Serializer serializer
           
protected  ValueFactory<String> stringFactory
           
protected  UuidFactory uuidFactory
           
protected  Workspaces workspaces
           
 
Constructor Summary
BasicRequestProcessor(String sourceName, ExecutionContext context, Observer observer, javax.persistence.EntityManager entityManager, UUID rootNodeUuid, String nameOfDefaultWorkspace, String[] predefinedWorkspaceNames, long largeValueMinimumSizeInBytes, boolean creatingWorkspacesAllowed, boolean compressData, boolean enforceReferentialIntegrity)
           
 
Method Summary
protected  BasicRequestProcessor.ActualLocation addNewChild(Long workspaceId, BasicRequestProcessor.ActualLocation parent, String childUuid, Name childName, boolean allowSameNameChildrenInNewNode)
          Create a new child with the supplied UUID and name under the supplied parent.
 void close()
          Close this processor, allowing it to clean up any open resources.
protected  Map<String,Location> computeDeletedLocations(WorkspaceEntity workspace, Location topNodeLocation, boolean deleteTopOfBranch)
           
protected  Collection<String> createHexValues(String hexValuesString)
           
protected  String createHexValuesString(Collection<String> hexValues)
           
protected  String createProperties(WorkspaceEntity workspace, String uuidString, Collection<Property> properties)
           
protected  Location delete(Request request, Location location, String workspaceName, boolean deleteTopOfBranch)
           
protected  ChildEntity findByPathSegment(Long workspaceId, String parentUuid, Path.Segment pathSegment)
          Find the node with the supplied path segment that is a child of the supplied parent.
protected  ChildEntity findNode(long workspaceId, String uuidString)
           
protected  BasicRequestProcessor.ActualLocation getActualLocation(WorkspaceEntity workspace, Location original)
          Utility method to look up the actual information given a supplied location.
protected  LinkedList<Location> getAllChildren(Long workspaceId, BasicRequestProcessor.ActualLocation parent)
          Utility method to obtain all of the children for a node, either from the cache (if all children are known to this processor) or by querying the database (and caching the list of children).
protected  WorkspaceEntity getExistingWorkspace(String workspaceName, Request request)
           
 void process(CloneBranchRequest request)
          Process a request to clone a branch into a new workspace.
 void process(CloneWorkspaceRequest request)
          Process a request to clone an existing workspace as a new workspace.
 void process(CopyBranchRequest request)
          Process a request to copy a branch into another location.
 void process(CreateNodeRequest request)
          Process a request to create a node at a specified location.
 void process(CreateWorkspaceRequest request)
          Process a request to create a new workspace.
 void process(DeleteBranchRequest request)
          Process a request to delete a branch at a specified location.
 void process(DeleteChildrenRequest request)
          Process a request to delete all of the child nodes under the supplied existing node.
 void process(DestroyWorkspaceRequest request)
          Process a request to permanently destroy a workspace.
 void process(GetWorkspacesRequest request)
          Process a request to get the information about the available workspaces.
 void process(MoveBranchRequest request)
          Process a request to move a branch at a specified location into a different location.
 void process(ReadAllChildrenRequest request)
          Process a request to read all of the children of a node.
 void process(ReadAllPropertiesRequest request)
          Process a request to read the properties of a node at the supplied location.
 void process(ReadBlockOfChildrenRequest request)
          Process a request to read a block of the children of a node.
 void process(ReadBranchRequest request)
          Process a request to read a branch or subgraph that's below a node at a specified location.
 void process(ReadNextBlockOfChildrenRequest request)
          Process a request to read the next block of the children of a node, starting after a previously-retrieved child.
 void process(ReadNodeRequest request)
          Process a request to read the properties and children of a node at the supplied location.
 void process(ReadPropertyRequest request)
          Process a request to read a single property of a node at the supplied location.
 void process(UpdatePropertiesRequest request)
          Process a request to remove the specified properties from a node.
 void process(VerifyWorkspaceRequest request)
          Process a request to verify a named workspace.
protected  String resolveToUuid(WorkspaceEntity workspace, Reference reference)
          Attempt to resolve the reference.
protected  void verifyReferences()
          Reference entities are added and removed in the appropriate process(...)
 
Methods inherited from class org.modeshape.graph.request.processor.RequestProcessor
completeRequest, getChanges, getDefaultCachePolicy, getExecutionContext, getNowInUtc, getSourceName, notifyObserverOfChanges, process, process, process, process, process, process, process, process, process, process, process, processUnknownRequest, recordChange, setCacheableInfo, setCacheableInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entities

protected final javax.persistence.EntityManager entities

stringFactory

protected final ValueFactory<String> stringFactory

pathFactory

protected final PathFactory pathFactory

propertyFactory

protected final PropertyFactory propertyFactory

nameFactory

protected final NameFactory nameFactory

uuidFactory

protected final UuidFactory uuidFactory

namespaces

protected final Namespaces namespaces

workspaces

protected final Workspaces workspaces

rootNodeUuid

protected final UUID rootNodeUuid

rootNodeUuidString

protected final String rootNodeUuidString

nameOfDefaultWorkspace

protected final String nameOfDefaultWorkspace

predefinedWorkspaceNames

protected final String[] predefinedWorkspaceNames

creatingWorkspacesAllowed

protected final boolean creatingWorkspacesAllowed

serializer

protected final Serializer serializer

largeValueMinimumSizeInBytes

protected final long largeValueMinimumSizeInBytes

compressData

protected final boolean compressData

logger

protected final Logger logger

cache

protected final RequestProcessorCache cache

enforceReferentialIntegrity

protected final boolean enforceReferentialIntegrity
Constructor Detail

BasicRequestProcessor

public BasicRequestProcessor(String sourceName,
                             ExecutionContext context,
                             Observer observer,
                             javax.persistence.EntityManager entityManager,
                             UUID rootNodeUuid,
                             String nameOfDefaultWorkspace,
                             String[] predefinedWorkspaceNames,
                             long largeValueMinimumSizeInBytes,
                             boolean creatingWorkspacesAllowed,
                             boolean compressData,
                             boolean enforceReferentialIntegrity)
Parameters:
sourceName -
context -
observer -
entityManager -
rootNodeUuid -
nameOfDefaultWorkspace -
predefinedWorkspaceNames -
largeValueMinimumSizeInBytes -
creatingWorkspacesAllowed -
compressData -
enforceReferentialIntegrity -
Method Detail

process

public void process(CreateNodeRequest request)
Process a request to create a node at a specified location.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the create request
See Also:
RequestProcessor.process(org.modeshape.graph.request.CreateNodeRequest)

addNewChild

protected BasicRequestProcessor.ActualLocation addNewChild(Long workspaceId,
                                                           BasicRequestProcessor.ActualLocation parent,
                                                           String childUuid,
                                                           Name childName,
                                                           boolean allowSameNameChildrenInNewNode)
Create a new child with the supplied UUID and name under the supplied parent. If the parent is null, then the child will be the root node.

Parameters:
workspaceId - the ID of the workspace in which the child is to be created
parent - the actual location of the parent, or null if the child is to be the root of the workspace
childUuid - the UUID of the child
childName - the name of the child
allowSameNameChildrenInNewNode -
Returns:
the actual location of the new child

process

public void process(ReadNodeRequest request)
Process a request to read the properties and children of a node at the supplied location.

This method does nothing if the request is null. Unless overridden, this method converts the single request into a ReadAllChildrenRequest and a ReadAllPropertiesRequest.

Overrides:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadNodeRequest)

process

public void process(ReadAllChildrenRequest request)
Process a request to read all of the children of a node.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadAllChildrenRequest)

getAllChildren

protected LinkedList<Location> getAllChildren(Long workspaceId,
                                              BasicRequestProcessor.ActualLocation parent)
Utility method to obtain all of the children for a node, either from the cache (if all children are known to this processor) or by querying the database (and caching the list of children).

Parameters:
workspaceId - the ID of the workspace; may not be null
parent - the actual location of the parent node; may not be null
Returns:
the list of child locations

process

public void process(ReadBlockOfChildrenRequest request)
Process a request to read a block of the children of a node. The block is defined by a starting index and a maximum number of children to include in the block.

This method does nothing if the request is null. The default implementation converts the command to a ReadAllChildrenRequest, and then finds the children within the block. Obviously for large numbers of children, this implementation may not be efficient and may need to be overridden.

Overrides:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadBlockOfChildrenRequest)

process

public void process(ReadNextBlockOfChildrenRequest request)
Process a request to read the next block of the children of a node, starting after a previously-retrieved child.

This method does nothing if the request is null. The default implementation converts the command to a ReadAllChildrenRequest, and then finds the children within the block. Obviously for large numbers of children, this implementation may not be efficient and may need to be overridden.

Overrides:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadNextBlockOfChildrenRequest)

process

public void process(ReadAllPropertiesRequest request)
Process a request to read the properties of a node at the supplied location.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadAllPropertiesRequest)

process

public void process(ReadPropertyRequest request)
Process a request to read a single property of a node at the supplied location.

This method does nothing if the request is null. Unless overridden, this method converts the request that reads the node and simply returns the one property.

Overrides:
process in class RequestProcessor
Parameters:
request - the read request
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadPropertyRequest)

process

public void process(UpdatePropertiesRequest request)
Process a request to remove the specified properties from a node.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the remove request
See Also:
RequestProcessor.process(org.modeshape.graph.request.UpdatePropertiesRequest)

process

public void process(ReadBranchRequest request)
Process a request to read a branch or subgraph that's below a node at a specified location.

This method does nothing if the request is null. The default implementation processes the branch by submitting the equivalent requests to read the nodes and the children. It starts by doing this for the top-level node, then proceeds for each of the children of that node, and so forth.

Overrides:
process in class RequestProcessor
Parameters:
request - the request to read the branch
See Also:
RequestProcessor.process(org.modeshape.graph.request.ReadBranchRequest)

process

public void process(CopyBranchRequest request)
Process a request to copy a branch into another location.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the copy request
See Also:
RequestProcessor.process(org.modeshape.graph.request.CopyBranchRequest)

process

public void process(CloneBranchRequest request)
Process a request to clone a branch into a new workspace.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.CloneBranchRequest)

process

public void process(DeleteBranchRequest request)
Process a request to delete a branch at a specified location.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the delete request
See Also:
RequestProcessor.process(org.modeshape.graph.request.DeleteBranchRequest)

process

public void process(DeleteChildrenRequest request)
Process a request to delete all of the child nodes under the supplied existing node.

This method does nothing if the request is null.

Overrides:
process in class RequestProcessor
Parameters:
request - the delete request
See Also:
RequestProcessor.process(org.modeshape.graph.request.DeleteChildrenRequest)

delete

protected Location delete(Request request,
                          Location location,
                          String workspaceName,
                          boolean deleteTopOfBranch)

computeDeletedLocations

protected Map<String,Location> computeDeletedLocations(WorkspaceEntity workspace,
                                                       Location topNodeLocation,
                                                       boolean deleteTopOfBranch)

process

public void process(MoveBranchRequest request)
Process a request to move a branch at a specified location into a different location.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the move request
See Also:
RequestProcessor.process(org.modeshape.graph.request.MoveBranchRequest)

process

public void process(VerifyWorkspaceRequest request)
Process a request to verify a named workspace.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.VerifyWorkspaceRequest)

process

public void process(GetWorkspacesRequest request)
Process a request to get the information about the available workspaces.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.GetWorkspacesRequest)

process

public void process(CreateWorkspaceRequest request)
Process a request to create a new workspace.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.CreateWorkspaceRequest)

process

public void process(CloneWorkspaceRequest request)
Process a request to clone an existing workspace as a new workspace.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.CloneWorkspaceRequest)

process

public void process(DestroyWorkspaceRequest request)
Process a request to permanently destroy a workspace.

This method does nothing if the request is null.

Specified by:
process in class RequestProcessor
Parameters:
request - the request
See Also:
RequestProcessor.process(org.modeshape.graph.request.DestroyWorkspaceRequest)

close

public void close()
Close this processor, allowing it to clean up any open resources.

Overrides:
close in class RequestProcessor
Throws:
ReferentialIntegrityException - if the integrity of the references has been compromised
See Also:
RequestProcessor.close()

getExistingWorkspace

protected WorkspaceEntity getExistingWorkspace(String workspaceName,
                                               Request request)

verifyReferences

protected void verifyReferences()
                         throws ReferentialIntegrityException
Reference entities are added and removed in the appropriate process(...) methods. However, this method is typically called in close() and performs the following steps:
  1. Remove all references that have a "from" node that is under the versions branch.
  2. Verify that all remaining references have a valid and existing "to" node

Throws:
ReferentialIntegrityException - if the integrity of the references has been compromised

createProperties

protected String createProperties(WorkspaceEntity workspace,
                                  String uuidString,
                                  Collection<Property> properties)
                           throws IOException
Throws:
IOException

resolveToUuid

protected String resolveToUuid(WorkspaceEntity workspace,
                               Reference reference)
Attempt to resolve the reference.

Parameters:
workspace - the workspace in which the reference occurs; may not be null
reference - the reference
Returns:
the UUID of the node to which the reference points, or null if the reference could not be resolved

getActualLocation

protected BasicRequestProcessor.ActualLocation getActualLocation(WorkspaceEntity workspace,
                                                                 Location original)
                                                          throws PathNotFoundException
Utility method to look up the actual information given a supplied location. This method verifies that the location actually represents an existing node, or it throws a PathNotFoundException. In all cases, the resulting information contains the correct path and the correct UUID.

Note that this method sometimes performs "unnecessary" work when the location contains both a path to a node and the node's corresponding UUID. Strictly speaking, this method would need to do very little. However, in such cases, this method does verify that the information is still correct (ensuring that calls to use the ChildEntity will be correct). So, while this work may be unnecessary, it does ensure that the location is consistent and correct (something that is not unnecessary).

There are cases when a request containing a Path and a UUID are no longer correct. The node may have been just moved by another request (perhaps from a different client), or there may be an error in the component making the request. In these cases, this method assumes that the path is incorrect (since paths may change) and finds the correct path given the UUID.

This method will also find the path when the location contains just the UUID.

Parameters:
workspace - the workspace; may not be null
original - the original location; may not be null
Returns:
the actual location, which includes the verified location and additional information needed by this method that may be usable after this method is called
Throws:
PathNotFoundException - if the location does not represent a location that could be found

findNode

protected ChildEntity findNode(long workspaceId,
                               String uuidString)

findByPathSegment

protected ChildEntity findByPathSegment(Long workspaceId,
                                        String parentUuid,
                                        Path.Segment pathSegment)
Find the node with the supplied path segment that is a child of the supplied parent.

Parameters:
workspaceId - the ID of the workspace
parentUuid - the UUID of the parent node, in string form
pathSegment - the path segment of the child
Returns:
the existing namespace, or null if one does not exist
Throws:
IllegalArgumentException - if the manager or URI are null

createHexValuesString

protected String createHexValuesString(Collection<String> hexValues)

createHexValues

protected Collection<String> createHexValues(String hexValuesString)


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