|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.graph.session.GraphSession<Payload,PropertyPayload>
Payload
- the type of the payload object for each node, used to allow the nodes to hold additional cached informationPropertyPayload
- the type of payload object for each property, used to allow the nodes to hold additional cached
information@NotThreadSafe public class GraphSession<Payload,PropertyPayload>
This class represents an interactive session for working with the content within a graph. This session maintains a cache of
content read from the repository, as well as transient changes that have been made to the nodes within this session that are
then pushed to the graph when the session is saved
.
Like the other Graph APIs, the mutable objects in this session should not be held onto for very long periods of time. When the
session is saved
or {refreshed
(or when a node is saved
or
refreshed
), the session may unload
and discard some of its nodes. Using
nodes after they are discarded may result in assertion errors (assuming Java assertions are enabled).
Nested Class Summary | |
---|---|
static interface |
GraphSession.Authorizer
|
protected static class |
GraphSession.Dependencies
|
protected class |
GraphSession.LoadAllChildrenVisitor
A visitor that ensures that all children of a node are loaded, and provides a hook to post-process the parent . |
protected class |
GraphSession.LoadNodesVisitor
An abstract base class for visitors that need to load nodes using a single batch for all read operations. |
static class |
GraphSession.Node<Payload,PropertyPayload>
|
static class |
GraphSession.NodeId
An immutable identifier for a node, used within the GraphSession . |
static interface |
GraphSession.NodeIdFactory
|
static class |
GraphSession.NodeOperations<Payload,PropertyPayload>
A default implementation of GraphSession.Operations that provides all the basic functionality required by a graph
session. |
static class |
GraphSession.NodeVisitor<NodePayload,PropertyPayloadType>
The node visitor. |
protected static class |
GraphSession.NoOpAuthorizer
GraphSession.Authorizer implementation that does nothing. |
static interface |
GraphSession.Operations<NodePayload,PropertyPayload>
|
static class |
GraphSession.PropertyInfo<PropertyPayload>
|
protected static class |
GraphSession.RefreshState<Payload,PropertyPayload>
|
protected static class |
GraphSession.Snapshot<PropertyPayload>
|
static class |
GraphSession.Status
|
static class |
GraphSession.StructureSnapshot<PropertyPayload>
A read-only visitor that walks the cache to obtain a snapshot of the cache structure. |
Constructor Summary | |
---|---|
GraphSession(Graph graph,
String workspaceName,
GraphSession.Operations<Payload,PropertyPayload> nodeOperations)
Create a session that uses the supplied graph and the supplied node operations. |
|
GraphSession(Graph graph,
String workspaceName,
GraphSession.Operations<Payload,PropertyPayload> nodeOperations,
GraphSession.Authorizer authorizer)
Create a session that uses the supplied graph and the supplied node operations. |
Method Summary | |
---|---|
void |
clearAllChangedNodes()
Remove any cached information that has been marked as a transient change. |
protected void |
clearNodes()
|
protected GraphSession.Node<Payload,PropertyPayload> |
createNode(GraphSession.Node<Payload,PropertyPayload> parent,
GraphSession.NodeId nodeId,
Location location)
|
GraphSession.Node<Payload,PropertyPayload> |
findNodeRelativeTo(GraphSession.Node<Payload,PropertyPayload> startingPoint,
Path relativePath)
Find the node with the supplied path relative to another node. |
protected GraphSession.Node<Payload,PropertyPayload> |
findNodeRelativeTo(GraphSession.Node<Payload,PropertyPayload> startingPoint,
Path relativePath,
boolean loadIfRequired)
Find the node with the supplied path relative to another node. |
GraphSession.Node<Payload,PropertyPayload> |
findNodeWith(GraphSession.NodeId id)
Find in the session the node with the supplied identifier. |
GraphSession.Node<Payload,PropertyPayload> |
findNodeWith(GraphSession.NodeId id,
Path path)
Find the node with the supplied identifier or, if no such node is found, the node at the supplied path. |
GraphSession.Node<Payload,PropertyPayload> |
findNodeWith(Location location)
Find in the session the node with the supplied location. |
GraphSession.Node<Payload,PropertyPayload> |
findNodeWith(Path path)
Find the node with the supplied path. |
protected GraphSession.Node<Payload,PropertyPayload> |
findNodeWith(Path path,
boolean loadIfRequired)
Find the node with the supplied path. |
protected long |
getCurrentTime()
|
int |
getDepthForLoadingNodes()
Get the subgraph depth that is read when a node is loaded from the persistence store. |
PathFactory |
getPathFactory()
Get the path factory that should be used to adjust the path objects. |
GraphSession.Node<Payload,PropertyPayload> |
getRoot()
Get the root node. |
boolean |
hasPendingChanges()
Returns whether the session cache has any pending changes that need to be executed. |
void |
immediateClone(Path source,
String sourceWorkspace,
Path destination,
boolean removeExisting,
boolean destPathIncludesSegment)
Clone the supplied source branch and place into the destination location, optionally removing any existing copy that already exists in the destination location, doing so immediately without enqueuing the operation within the session's operations. |
void |
immediateCopy(Path source,
Path destination)
Copy the node at the supplied source path in the named workspace, and place the copy at the supplied location within the current workspace, doing so immediately without enqueuing the operation within the session's operations. |
Location |
immediateCopy(Path source,
String sourceWorkspace,
Path destination)
Copy the node at the supplied source path in the named workspace, and place the copy at the supplied location within the current workspace, doing so immediately without enqueuing the operation within the session's operations. |
Location |
immediateCreateOrReplace(Path path,
Collection<Property> properties)
Create a new node at the supplied location, appending to any existing node at that path. |
void |
immediateMove(Path nodeToMove,
Path destination)
Move this node from its current location so that is is a child of the supplied parent, doing so immediately without enqueuing the operation within the session's operations. |
protected GraphSession.Node<Payload,PropertyPayload> |
node(GraphSession.NodeId id)
|
protected GraphSession.Node<Payload,PropertyPayload> |
node(UUID uuid)
|
protected Graph.Batch |
operations()
|
protected void |
put(GraphSession.Node<Payload,PropertyPayload> node)
|
protected void |
recordDelete(GraphSession.Node<Payload,PropertyPayload> node)
Record the fact that the supplied node is in the process of being deleted, so any cached information (outside of the node object itself) should be cleaned up. |
protected void |
recordMove(GraphSession.Node<Payload,PropertyPayload> nodeBeingMoved,
GraphSession.Node<Payload,PropertyPayload> oldParent,
GraphSession.Node<Payload,PropertyPayload> newParent)
|
protected void |
recordUnloaded(GraphSession.Node<Payload,PropertyPayload> node)
Record the fact that the supplied node is in the process of being unloaded, so any cached information (outside of the node object itself) should be cleaned up. |
void |
refresh(boolean keepChanges)
Refreshes (removes the cached state) for all cached nodes. |
void |
refresh(GraphSession.Node<Payload,PropertyPayload> node,
boolean keepChanges)
Refreshes (removes the cached state) for the given node and its descendants. |
void |
refresh(Path path,
boolean keepChanges)
Refreshes (removes the cached state) for the given node and its descendants. |
void |
refreshProperties(GraphSession.Node<Payload,PropertyPayload> node)
Refreshes all properties for the given node only. |
protected void |
removeNode(GraphSession.NodeId id)
|
void |
save()
Save any changes that have been accumulated by this session. |
void |
save(GraphSession.Node<Payload,PropertyPayload> node)
Save any changes to the identified node or its descendants. |
void |
setDepthForLoadingNodes(int depth)
Set the loading depth parameter, which controls how deep a subgraph should be read when a node is loaded from the persistence store. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final ListMultimap<Name,GraphSession.Node<Payload,PropertyPayload>> NO_CHILDREN
protected final Map<Name,GraphSession.PropertyInfo<PropertyPayload>> NO_PROPERTIES
protected final GraphSession.Authorizer authorizer
protected final ExecutionContext context
protected final Graph store
protected final GraphSession.Node<Payload,PropertyPayload> root
protected final GraphSession.Operations<Payload,PropertyPayload> nodeOperations
protected final PathFactory pathFactory
protected final GraphSession.NodeIdFactory idFactory
protected final String workspaceName
protected int loadDepth
protected final Map<GraphSession.NodeId,GraphSession.Node<Payload,PropertyPayload>> nodes
protected final Map<UUID,GraphSession.Node<Payload,PropertyPayload>> nodesByUuid
protected final Map<GraphSession.NodeId,GraphSession.Dependencies> changeDependencies
protected final Set<UUID> deletedNodes
operations
) but not
yet saved
. This is used to know whether a node has been locally removed to prevent reloading the node from
the persistent store.
protected Graph.Batch operations
Constructor Detail |
---|
public GraphSession(Graph graph, String workspaceName, GraphSession.Operations<Payload,PropertyPayload> nodeOperations)
graph
- the graph that this session is to useworkspaceName
- the name of the workspace that is to be used, or null if the current workspace should be usednodeOperations
- the operations that are to be performed during various stages in the lifecycle of a node, or null if
there are no special operations that should be performedpublic GraphSession(Graph graph, String workspaceName, GraphSession.Operations<Payload,PropertyPayload> nodeOperations, GraphSession.Authorizer authorizer)
graph
- the graph that this session is to useworkspaceName
- the name of the workspace that is to be used, or null if the current workspace should be usednodeOperations
- the operations that are to be performed during various stages in the lifecycle of a node, or null if
there are no special operations that should be performedauthorizer
- the authorizing component, or null if no special authorization is to be performed
IllegalArgumentException
- if the graph reference is null
IllegalArgumentException
- if the depth is not positiveMethod Detail |
---|
protected void put(GraphSession.Node<Payload,PropertyPayload> node)
protected GraphSession.Node<Payload,PropertyPayload> node(GraphSession.NodeId id)
protected GraphSession.Node<Payload,PropertyPayload> node(UUID uuid)
protected void removeNode(GraphSession.NodeId id)
protected void clearNodes()
protected Graph.Batch operations()
public int getDepthForLoadingNodes()
public void setDepthForLoadingNodes(int depth)
depth
- the depth that should be read whenever a single node is loaded
IllegalArgumentException
- if the depth is not positivepublic GraphSession.Node<Payload,PropertyPayload> getRoot()
public PathFactory getPathFactory()
public GraphSession.Node<Payload,PropertyPayload> findNodeWith(Location location) throws PathNotFoundException, AccessControlException
location
- the location of the node
PathNotFoundException
- if the node at the supplied location does not exist
AccessControlException
- if the user does not have permission to read the node given by the supplied location
IllegalArgumentException
- if the location is nullpublic GraphSession.Node<Payload,PropertyPayload> findNodeWith(GraphSession.NodeId id)
id
- the identifier of the node
IllegalArgumentException
- if the identifier is nullpublic GraphSession.Node<Payload,PropertyPayload> findNodeWith(GraphSession.NodeId id, Path path) throws PathNotFoundException, AccessControlException
id
- the identifier to the node; may be null if the node is to be found by pathpath
- the path that should be used to find the node only when the cache doesn't contain a node with the identifier
IllegalArgumentException
- if the identifier and path are both node
PathNotFoundException
- if the node at the supplied path does not exist
AccessControlException
- if the user does not have permission to read the nodes given by the supplied pathpublic GraphSession.Node<Payload,PropertyPayload> findNodeWith(Path path) throws PathNotFoundException, AccessControlException
path
- the path to the node
PathNotFoundException
- if the node at the supplied path does not exist
AccessControlException
- if the user does not have permission to read the nodes given by the supplied pathprotected GraphSession.Node<Payload,PropertyPayload> findNodeWith(Path path, boolean loadIfRequired) throws PathNotFoundException, AccessControlException
loadIfRequired
is false
, then any
node along the path that is not loaded will result in this method returning null.
path
- the path to the nodeloadIfRequired
- true if any missing nodes should be loaded, or false if null should be returned if any nodes along
the path are not loaded
PathNotFoundException
- if the node at the supplied path does not exist
AccessControlException
- if the user does not have permission to read the nodes given by the supplied pathpublic GraphSession.Node<Payload,PropertyPayload> findNodeRelativeTo(GraphSession.Node<Payload,PropertyPayload> startingPoint, Path relativePath) throws PathNotFoundException, AccessControlException
startingPoint
- the node from which the path is relativerelativePath
- the relative path from the designated starting point to the desired node; may not be null and may not
be an absolute
path
PathNotFoundException
- if the node at the supplied path does not exist
AccessControlException
- if the user does not have permission to read the nodes given by the supplied pathprotected GraphSession.Node<Payload,PropertyPayload> findNodeRelativeTo(GraphSession.Node<Payload,PropertyPayload> startingPoint, Path relativePath, boolean loadIfRequired) throws PathNotFoundException, AccessControlException
startingPoint
- the node from which the path is relativerelativePath
- the relative path from the designated starting point to the desired node; may not be null and may not
be an absolute
pathloadIfRequired
- true if any missing nodes should be loaded, or false if null should be returned if any nodes along
the path are not loaded
loadRequired
was false)
PathNotFoundException
- if the node at the supplied path does not exist
AccessControlException
- if the user does not have permission to read the nodes given by the supplied pathpublic boolean hasPendingChanges()
public void clearAllChangedNodes()
public void immediateMove(Path nodeToMove, Path destination) throws AccessControlException, RepositorySourceException
nodeToMove
- the path to the node that is to be moved; may not be nulldestination
- the desired new path; may not be null
IllegalArgumentException
- if the node being moved is the root node
AccessControlException
- if the caller does not have the permission to perform the operation
RepositorySourceException
- if any error resulting while performing the operationpublic void immediateCopy(Path source, Path destination) throws AccessControlException, RepositorySourceException
Note that the destination path should not include a same-name-sibling index, since this will be ignored and will always be recomputed (as the copy will be appended to any children already in the destination's parent).
source
- the path to the node that is to be copied; may not be nulldestination
- the path where the copy is to be placed; may not be null
IllegalArgumentException
- either path is null or invalid
AccessControlException
- if the caller does not have the permission to perform the operation
RepositorySourceException
- if any error resulting while performing the operationpublic Location immediateCopy(Path source, String sourceWorkspace, Path destination) throws InvalidWorkspaceException, AccessControlException, PathNotFoundException, RepositorySourceException
Note that the destination path should not include a same-name-sibling index, since this will be ignored and will always be recomputed (as the copy will be appended to any children already in the destination's parent).
source
- the path to the node that is to be copied; may not be nullsourceWorkspace
- the name of the workspace where the source node is to be found, or null if the current workspace
should be useddestination
- the path where the copy is to be placed; may not be null
IllegalArgumentException
- either path is null or invalid
PathNotFoundException
- if the node being copied or the parent of the destination path do not exist
InvalidWorkspaceException
- if the source workspace name is invalid or does not exist
AccessControlException
- if the caller does not have the permission to perform the operation
RepositorySourceException
- if any error resulting while performing the operationpublic Location immediateCreateOrReplace(Path path, Collection<Property> properties) throws AccessControlException, RepositorySourceException
path
- the path where the new node should be createdproperties
- the properties to be added to the node; may be null or empty
AccessControlException
- if the caller does not have the permission to perform the operation
RepositorySourceException
- if any error resulting while performing the operationpublic void immediateClone(Path source, String sourceWorkspace, Path destination, boolean removeExisting, boolean destPathIncludesSegment) throws InvalidWorkspaceException, AccessControlException, UuidAlreadyExistsException, PathNotFoundException, RepositorySourceException
source
- the path to the node that is to be cloned; may not be nullsourceWorkspace
- the name of the workspace where the source node is to be found, or null if the current workspace
should be useddestination
- the path for the new cloned copy; may not be null indexremoveExisting
- true if the original should be removed, or false if the original should be leftdestPathIncludesSegment
- true if the destination path includes the segment that should be used
IllegalArgumentException
- either path is null or invalid
InvalidWorkspaceException
- if the source workspace name is invalid or does not exist
UuidAlreadyExistsException
- if copy could not be completed because the current workspace already includes at least
one of the nodes at or below the source
branch in the source workspace
PathNotFoundException
- if the node being clone or the destination node do not exist
AccessControlException
- if the caller does not have the permission to perform the operation
RepositorySourceException
- if any error resulting while performing the operationpublic void refresh(boolean keepChanges) throws InvalidStateException, RepositorySourceException
If keepChanges == true
, modified nodes will not have their state refreshed, while all others will either be
unloaded or changed to reflect the current state of the persistent store.
keepChanges
- indicates whether changed nodes should be kept or refreshed from the repository.
InvalidStateException
- if any error resulting while reading information from the repository
RepositorySourceException
- if any error resulting while reading information from the repositorypublic void refresh(Path path, boolean keepChanges) throws InvalidStateException, RepositorySourceException
If keepChanges == true
, modified nodes will not have their state refreshed, while all others will either be
unloaded or changed to reflect the current state of the persistent store.
path
- the path to the node that is to be refreshed; may not be nullkeepChanges
- indicates whether changed nodes should be kept or refreshed from the repository.
InvalidStateException
- if any error resulting while reading information from the repository
RepositorySourceException
- if any error resulting while reading information from the repositorypublic void refresh(GraphSession.Node<Payload,PropertyPayload> node, boolean keepChanges) throws InvalidStateException, RepositorySourceException
If keepChanges == true
, modified nodes will not have their state refreshed, while all others will either be
unloaded or changed to reflect the current state of the persistent store.
node
- the node that is to be refreshed; may not be nullkeepChanges
- indicates whether changed nodes should be kept or refreshed from the repository.
InvalidStateException
- if any error resulting while reading information from the repository
RepositorySourceException
- if any error resulting while reading information from the repositorypublic void refreshProperties(GraphSession.Node<Payload,PropertyPayload> node) throws InvalidStateException, RepositorySourceException
This method is not recursive and will not modify or access any descendants of the given node.
NOTE: Calling this method on a node that already has modified properties can result in the enqueued property changes overwriting the current properties on a save() call. This method should be used with great care to avoid this situation.
node
- the node for which the properties are to be refreshed; may not be null
InvalidStateException
- if the node is new
RepositorySourceException
- if any error resulting while reading information from the repositorypublic void save() throws PathNotFoundException, ValidationException, InvalidStateException
PathNotFoundException
- if the state of this session is invalid and is attempting to change a node that doesn't exist
ValidationException
- if any of the changes being made result in an invalid node state
InvalidStateException
- if the supplied node is no longer a node within this cache (because it was unloaded)public void save(GraphSession.Node<Payload,PropertyPayload> node) throws PathNotFoundException, ValidationException, InvalidStateException
node
- the node being saved; may not be null
PathNotFoundException
- if the state of this session is invalid and is attempting to change a node that doesn't exist
ValidationException
- if any of the changes being made result in an invalid node state
InvalidStateException
- if the supplied node is no longer a node within this cache (because it was unloaded)protected GraphSession.Node<Payload,PropertyPayload> createNode(GraphSession.Node<Payload,PropertyPayload> parent, GraphSession.NodeId nodeId, Location location)
protected long getCurrentTime()
protected void recordMove(GraphSession.Node<Payload,PropertyPayload> nodeBeingMoved, GraphSession.Node<Payload,PropertyPayload> oldParent, GraphSession.Node<Payload,PropertyPayload> newParent)
protected void recordDelete(GraphSession.Node<Payload,PropertyPayload> node)
node
- the node being deleted; never nullprotected void recordUnloaded(GraphSession.Node<Payload,PropertyPayload> node)
node
- the node being unloaded; never null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |