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

java.lang.Object
  extended by org.modeshape.connector.store.jpa.model.basic.SubgraphQuery

public class SubgraphQuery
extends Object

Represents a temporary working area for a query that efficiently retrieves the nodes in a subgraph. This class uses the database to build up the content of the subgraph, and therefore requires write privilege on the database. The benefit is that it minimizes the amount of memory required to process the subgraph, plus the set of nodes that make up the subgraph can be produced with database joins.

The use of database joins also produces another benefit: the number of SQL statements necessary to build the set of nodes in a subgraph is equal to the depth of the subgraph, regardless of the number of child nodes at any level.


Constructor Summary
protected SubgraphQuery(ExecutionContext context, javax.persistence.EntityManager manager, Long workspaceId, SubgraphQueryEntity query, Path subgraphRootPath, int maxDepth)
           
 
Method Summary
 void close()
          Close this query object and clean up all in-database records associated with this query.
static SubgraphQuery create(ExecutionContext context, javax.persistence.EntityManager entities, Long workspaceId, UUID subgraphRootUuid, Path subgraphRootPath, int maxDepth)
          Create a query that returns a subgraph at and below the node with the supplied path and the supplied UUID.
 void deleteSubgraph(boolean includeRoot)
          Delete the nodes in the subgraph.
 javax.persistence.EntityManager getEntityManager()
           
 List<ReferenceEntity> getInternalReferences()
          Get the list of references that are owned by nodes within the subgraph and that point to other nodes in this same subgraph.
 List<ReferenceEntity> getInwardReferences()
          Get the list of references that are owned by nodes outside of the subgraph that point to nodes in this subgraph.
 int getMaxDepth()
           
 ChildEntity getNode()
          Get the root node of the subgraph.
 int getNodeCount(boolean includeRoot)
           
 List<Location> getNodeLocations(boolean includeRoot, boolean includeChildrenOfMaxDepthNodes)
          Get the Location for each of the nodes in the subgraph.
 List<ChildEntity> getNodes(boolean includeRoot, boolean includeChildrenOfMaxDepthNodes)
          Get the nodes in the subgraph.
 List<ReferenceEntity> getOutwardReferences()
          Get the list of references that are owned by nodes within the subgraph and that point to nodes not in this same subgraph.
 List<PropertiesEntity> getProperties(boolean includeRoot, boolean includeChildrenOfMaxDepthNodes)
          Get the properties for each of the nodes in the subgraph.
 SubgraphQueryEntity getSubgraphQueryEntity()
           
 Path getSubgraphRootPath()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubgraphQuery

protected SubgraphQuery(ExecutionContext context,
                        javax.persistence.EntityManager manager,
                        Long workspaceId,
                        SubgraphQueryEntity query,
                        Path subgraphRootPath,
                        int maxDepth)
Method Detail

create

public static SubgraphQuery create(ExecutionContext context,
                                   javax.persistence.EntityManager entities,
                                   Long workspaceId,
                                   UUID subgraphRootUuid,
                                   Path subgraphRootPath,
                                   int maxDepth)
Create a query that returns a subgraph at and below the node with the supplied path and the supplied UUID.

Parameters:
context - the execution context; may not be null
entities - the entity manager; may not be null
workspaceId - the ID of the workspace; may not be null
subgraphRootUuid - the UUID (in string form) of the root node in the subgraph
subgraphRootPath - the path of the root node in the subgraph
maxDepth - the maximum depth of the subgraph, or 0 if there is no maximum depth
Returns:
the object representing the subgraph

getMaxDepth

public int getMaxDepth()
Returns:
maxDepth

getEntityManager

public javax.persistence.EntityManager getEntityManager()
Returns:
manager

getSubgraphRootPath

public Path getSubgraphRootPath()
Returns:
subgraphRootPath

getSubgraphQueryEntity

public SubgraphQueryEntity getSubgraphQueryEntity()
Returns:
query

getNodeCount

public int getNodeCount(boolean includeRoot)

getNode

public ChildEntity getNode()
Get the root node of the subgraph. This must be called before the query is closed.

Returns:
the subgraph's root nodes

getNodes

public List<ChildEntity> getNodes(boolean includeRoot,
                                  boolean includeChildrenOfMaxDepthNodes)
Get the nodes in the subgraph. This must be called before the query is closed.

Parameters:
includeRoot - true if the subgraph's root node is to be included, or false otherwise
includeChildrenOfMaxDepthNodes - true if the method is to include nodes that are children of nodes that are at the maximum depth, or false if only nodes up to the maximum depth are to be included
Returns:
the list of nodes, in breadth-first order

getProperties

public List<PropertiesEntity> getProperties(boolean includeRoot,
                                            boolean includeChildrenOfMaxDepthNodes)
Get the properties for each of the nodes in the subgraph. This must be called before the query is closed.

Parameters:
includeRoot - true if the properties for the subgraph's root node are to be included, or false otherwise
includeChildrenOfMaxDepthNodes - true if the method is to include nodes that are children of nodes that are at the maximum depth, or false if only nodes up to the maximum depth are to be included
Returns:
the list of properties for each of the nodes, in breadth-first order

getNodeLocations

public List<Location> getNodeLocations(boolean includeRoot,
                                       boolean includeChildrenOfMaxDepthNodes)
Get the Location for each of the nodes in the subgraph. This must be called before the query is closed.

This method calls getNodes(boolean,boolean). Therefore, calling getNodes(boolean,boolean) and this method for the same subgraph is not efficient; consider just calling getNodes(boolean,boolean) alone.

Parameters:
includeRoot - true if the properties for the subgraph's root node are to be included, or false otherwise
includeChildrenOfMaxDepthNodes - true if the method is to include nodes that are children of nodes that are at the maximum depth, or false if only nodes up to the maximum depth are to be included
Returns:
the list of locations, one for each of the nodes in the subgraph, in breadth-first order

getInternalReferences

public List<ReferenceEntity> getInternalReferences()
Get the list of references that are owned by nodes within the subgraph and that point to other nodes in this same subgraph. This set of references is important in copying a subgraph, since all intra-subgraph references in the original subgraph must also be intra-subgraph references in the copy.

Returns:
the list of references completely contained by this subgraphs

getOutwardReferences

public List<ReferenceEntity> getOutwardReferences()
Get the list of references that are owned by nodes within the subgraph and that point to nodes not in this same subgraph. This set of references is important in copying a subgraph.

Returns:
the list of references that are owned by the subgraph but that point to nodes outside of the subgraph

getInwardReferences

public List<ReferenceEntity> getInwardReferences()
Get the list of references that are owned by nodes outside of the subgraph that point to nodes in this subgraph. This set of references is important in deleting nodes, since such references prevent the deletion of the subgraph.

Returns:
the list of references that are no longer valid

deleteSubgraph

public void deleteSubgraph(boolean includeRoot)
Delete the nodes in the subgraph. This method first does not check for referential integrity (see getInwardReferences()).

Parameters:
includeRoot - true if the root node should also be deleted

close

public void close()
Close this query object and clean up all in-database records associated with this query. This method must be called when this query is no longer needed, and once it is called, this subgraph query is no longer usable.



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