Index: modeshape-graph/src/main/java/org/modeshape/graph/connector/base/MapTransaction.java =================================================================== --- modeshape-graph/src/main/java/org/modeshape/graph/connector/base/MapTransaction.java (revision 2513) +++ modeshape-graph/src/main/java/org/modeshape/graph/connector/base/MapTransaction.java (working copy) @@ -68,6 +68,8 @@ public abstract class MapTransaction changesByWorkspaceName; + /** The set of nodes that have been read during this transaction */ + private Map> nodesByWorkspaceName; /** * Create a new transaction. @@ -110,6 +112,50 @@ public abstract class MapTransaction getCachedNodesfor( WorkspaceType workspace ) { + if (nodesByWorkspaceName == null) { + nodesByWorkspaceName = new HashMap>(); + } + + Map cachedNodes = nodesByWorkspaceName.get(workspace); + if (cachedNodes == null) { + cachedNodes = new HashMap(); + nodesByWorkspaceName.put(workspace, cachedNodes); + } + + return cachedNodes; + } + + /** + * Returns the node with the given UUID in the given workspace from the transaction read cache, if it exists in that cache. + * Otherwise, this method uses {@link MapWorkspace#getNode(UUID)} to retrieve the node directly from the workspace. + *

+ * The values returned by this method do not take any node modifications or deletions from this session into consideration. + *

+ * + * @param workspace the workspace from which the node should be read; may not be null + * @param uuid the UUID of the node to read; may not be null + * @return the node with the given UUID in the given workspace + */ + private NodeType getNode( WorkspaceType workspace, + UUID uuid ) { + Map cachedNodes = getCachedNodesfor(workspace); + NodeType cachedNode = cachedNodes.get(uuid); + if (cachedNode == null) { + cachedNode = workspace.getNode(uuid); + cachedNodes.put(uuid, cachedNode); + } + + return cachedNode; + } + + /** * {@inheritDoc} * * @see org.modeshape.graph.connector.base.Transaction#getNode(org.modeshape.graph.connector.base.Workspace, @@ -140,7 +186,7 @@ public abstract class MapTransaction