org.modeshape.graph.connector.base
Class StandardMapWorkspace<NodeType extends MapNode>

java.lang.Object
  extended by org.modeshape.graph.connector.base.MapWorkspace<NodeType>
      extended by org.modeshape.graph.connector.base.StandardMapWorkspace<NodeType>
Type Parameters:
NodeType - the type of node
All Implemented Interfaces:
Workspace
Direct Known Subclasses:
InfinispanWorkspace, InMemoryWorkspace

@NotThreadSafe
public class StandardMapWorkspace<NodeType extends MapNode>
extends MapWorkspace<NodeType>

The Workspace implementation that represents all nodes as MapNode objects and stores them within a Map keyed by their UUID.

Subclasses are required to provide thread-safe access and modification of the state within the encapsulated map, since multiple Transaction implementations may be committing changes to the map at the same time. However, this class does not provide any thread-safety, since the nature of the thread-safety will almost certainly depend on the actual map implementation. For example, a subclass may use a lock, or it may use a map implementation that provides the thread-safety.


Field Summary
 
Fields inherited from class org.modeshape.graph.connector.base.MapWorkspace
name, rootNodeUuid
 
Constructor Summary
StandardMapWorkspace(String name, Map<UUID,NodeType> nodesByUuid, NodeType rootNode)
          Create a new instance of the workspace.
StandardMapWorkspace(String name, Map<UUID,NodeType> nodesByUuid, StandardMapWorkspace<NodeType> originalToClone)
          Create a new instance of the workspace.
 
Method Summary
 NodeType getNode(UUID uuid)
          Get the node with the supplied UUID.
 NodeType putNode(NodeType node)
          Add the node into this workspace's map, overwriting any previous record of the node
 void removeAll()
          Remove all of the nodes in this workspace, and make sure there is a single root node with no properties and no children.
 NodeType removeNode(UUID uuid)
          Remove and return the node with the supplied UUID.
 
Methods inherited from class org.modeshape.graph.connector.base.MapWorkspace
getName, getRootNode, getRootNodeUuid, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StandardMapWorkspace

public StandardMapWorkspace(String name,
                            Map<UUID,NodeType> nodesByUuid,
                            NodeType rootNode)
Create a new instance of the workspace.

Parameters:
name - the workspace name; may not be null
nodesByUuid - the map of nodes keyed by their UUIDs; may not be null
rootNode - the root node that is expected to already exist in the map

StandardMapWorkspace

public StandardMapWorkspace(String name,
                            Map<UUID,NodeType> nodesByUuid,
                            StandardMapWorkspace<NodeType> originalToClone)
Create a new instance of the workspace.

Parameters:
name - the workspace name; may not be null
nodesByUuid - the map of nodes keyed by their UUIDs; may not be null
originalToClone - the workspace that is to be cloned; may not be null
Method Detail

getNode

public NodeType getNode(UUID uuid)
Get the node with the supplied UUID.

Specified by:
getNode in class MapWorkspace<NodeType extends MapNode>
Parameters:
uuid - the UUID of the node
Returns:
the node state as known by this workspace, or null if no such node exists in this workspace

putNode

public NodeType putNode(NodeType node)
Add the node into this workspace's map, overwriting any previous record of the node

Specified by:
putNode in class MapWorkspace<NodeType extends MapNode>
Parameters:
node - the new node; may not be null
Returns:
the previous node state, or null if the node is new to this workspace

removeNode

public NodeType removeNode(UUID uuid)
Remove and return the node with the supplied UUID. This method will never remove the root node.

Specified by:
removeNode in class MapWorkspace<NodeType extends MapNode>
Parameters:
uuid - the UUID of the node to be removed
Returns:
the node that was removed, or null if the supplied UUID is the root node's UUID or if this workspace does not contain a node with the supplied UUID

removeAll

public void removeAll()
Remove all of the nodes in this workspace, and make sure there is a single root node with no properties and no children.

Specified by:
removeAll in class MapWorkspace<NodeType extends MapNode>


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