org.modeshape.graph.connector.inmemory
Class InMemoryRepository.Workspace

java.lang.Object
  extended by org.modeshape.graph.connector.map.AbstractMapWorkspace
      extended by org.modeshape.graph.connector.inmemory.InMemoryRepository.Workspace
All Implemented Interfaces:
InMemoryNode.ChangeListener, MapWorkspace
Enclosing class:
InMemoryRepository

protected class InMemoryRepository.Workspace
extends AbstractMapWorkspace
implements InMemoryNode.ChangeListener


Constructor Summary
InMemoryRepository.Workspace(MapRepository repository, String name)
           
 
Method Summary
protected  void addNodeToMap(MapNode node)
          Adds the given node to the backing map, replacing any node already in the backing map with the same UUID.
protected  MapNode copyNode(ExecutionContext context, MapNode original, MapWorkspace newWorkspace, MapNode newParent, Name desiredName, boolean recursive, Map<UUID,UUID> oldToNewUuids)
          This should copy the subgraph given by the original node and place the new copy under the supplied new parent.
protected  MapNode createMapNode(UUID uuid)
          Creates an empty node with the given UUID.
 MapNode getNode(UUID nodeUuid)
          Gets the node with the given UUID from the backing map, if one exists
 void lockNode(MapNode node, LockBranchRequest.LockScope lockScope, long lockTimeoutInMillis)
          Attempts to lock the given node with the given timeout.
 void prepareForChange(InMemoryNode node)
          Signal that the supplied node is about to change.
protected  void releaseBackups()
           
protected  void removeAllNodesFromMap()
          Removes all of the nodes from the backing map
protected  MapNode removeNodeFromMap(UUID nodeUuid)
          Removes the node with the given UUID from the backing map, returning the node if it exists
protected  void restoreBackups()
           
 void unlockNode(MapNode node)
          Attempts to unlock the given node.
 
Methods inherited from class org.modeshape.graph.connector.map.AbstractMapWorkspace
cloneNode, copyNode, correctSameNameSiblingIndexes, createNode, createNode, equals, getLowestExistingPath, getName, getNode, getNode, getRepository, getRoot, getUuidsUnderNode, hashCode, initialize, moveNode, moveNodeToWorkspace, pathFor, query, removeNode, removeUuidReference, search, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InMemoryRepository.Workspace

public InMemoryRepository.Workspace(MapRepository repository,
                                    String name)
Method Detail

createMapNode

protected MapNode createMapNode(UUID uuid)
Creates an empty node with the given UUID.

This method does not add the new map node to the map. That must be done with a separate call to AbstractMapWorkspace.addNodeToMap(MapNode).

Overrides:
createMapNode in class AbstractMapWorkspace
Parameters:
uuid - the UUID that identifies the new node; may not be null
Returns:
the new node with the given UUID
See Also:
AbstractMapWorkspace.createMapNode(java.util.UUID)

addNodeToMap

protected void addNodeToMap(MapNode node)
Description copied from class: AbstractMapWorkspace
Adds the given node to the backing map, replacing any node already in the backing map with the same UUID.

Specified by:
addNodeToMap in class AbstractMapWorkspace
Parameters:
node - the node to add to the map; may not be null

removeNodeFromMap

protected MapNode removeNodeFromMap(UUID nodeUuid)
Description copied from class: AbstractMapWorkspace
Removes the node with the given UUID from the backing map, returning the node if it exists

Specified by:
removeNodeFromMap in class AbstractMapWorkspace
Parameters:
nodeUuid - the UUID of the node to replace; may not be null
Returns:
if a node with that UUID exists in the backing map (prior to removal), that node is returned; otherwise null

removeAllNodesFromMap

protected void removeAllNodesFromMap()
Description copied from class: AbstractMapWorkspace
Removes all of the nodes from the backing map

Specified by:
removeAllNodesFromMap in class AbstractMapWorkspace

getNode

public MapNode getNode(UUID nodeUuid)
Description copied from class: AbstractMapWorkspace
Gets the node with the given UUID from the backing map, if one exists

Specified by:
getNode in interface MapWorkspace
Specified by:
getNode in class AbstractMapWorkspace
Parameters:
nodeUuid - the UUID of the node to be retrieved; may not be null
Returns:
the node that exists in the backing map with the given UUID

copyNode

protected MapNode copyNode(ExecutionContext context,
                           MapNode original,
                           MapWorkspace newWorkspace,
                           MapNode newParent,
                           Name desiredName,
                           boolean recursive,
                           Map<UUID,UUID> oldToNewUuids)
This should copy the subgraph given by the original node and place the new copy under the supplied new parent. Note that internal references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.

This method is trivially overridden for testing purposes.

Overrides:
copyNode in class AbstractMapWorkspace
Parameters:
context - the context; may not be null
original - the node to be copied; may not be null
newWorkspace - the workspace containing the new parent node; may not be null
newParent - the parent where the copy is to be placed; may not be null
desiredName - the desired name for the node; if null, the name will be obtained from the original node
recursive - true if the copy should be recursive
oldToNewUuids - the map of UUIDs of nodes in the new subgraph keyed by the UUIDs of nodes in the original; may be null if the UUIDs are to be maintained
Returns:
the new node, which is the top of the new subgraph

lockNode

public void lockNode(MapNode node,
                     LockBranchRequest.LockScope lockScope,
                     long lockTimeoutInMillis)
              throws LockFailedException
Description copied from interface: MapWorkspace
Attempts to lock the given node with the given timeout. If the lock attempt fails, a LockFailedException will be thrown.

Specified by:
lockNode in interface MapWorkspace
Parameters:
node - the node to be locked; may not be null
lockScope - the scope of the lock (i.e., whether descendants of node should be included in the lock
lockTimeoutInMillis - the maximum lifetime of the lock in milliseconds; zero (0) indicates that the connector default should be used
Throws:
LockFailedException - if the implementing connector supports locking but the lock could not be acquired.

unlockNode

public void unlockNode(MapNode node)
Description copied from interface: MapWorkspace
Attempts to unlock the given node.

Specified by:
unlockNode in interface MapWorkspace
Parameters:
node - the node to be unlocked; may not be null

prepareForChange

public void prepareForChange(InMemoryNode node)
Signal that the supplied node is about to change.

Specified by:
prepareForChange in interface InMemoryNode.ChangeListener
Parameters:
node - the node that is about to change
See Also:
InMemoryNode.ChangeListener.prepareForChange(org.modeshape.graph.connector.inmemory.InMemoryNode)

restoreBackups

protected void restoreBackups()

releaseBackups

protected void releaseBackups()


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