[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...

Manik Surtani msurtani at jboss.com
Tue Jan 9 11:21:53 EST 2007


  User: msurtani
  Date: 07/01/09 11:21:53

  Modified:    src/org/jboss/cache/interceptors  
                        OptimisticNodeInterceptor.java
                        OptimisticCreateIfNotExistsInterceptor.java
  Log:
  Added tests and fix for JBCACHE-927
  
  Revision  Changes    Path
  1.46      +26 -18    JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticNodeInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -b -r1.45 -r1.46
  --- OptimisticNodeInterceptor.java	4 Jan 2007 05:35:37 -0000	1.45
  +++ OptimisticNodeInterceptor.java	9 Jan 2007 16:21:53 -0000	1.46
  @@ -12,6 +12,7 @@
   import org.jboss.cache.Fqn;
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.InvocationContext;
  +import org.jboss.cache.NodeNotExistsException;
   import org.jboss.cache.NodeSPI;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.factories.NodeFactory;
  @@ -72,8 +73,9 @@
               log.trace("Adding nodes " + parentFqn + " and " + nodeFqn + " to the workspace.");
            }
   
  -         WorkspaceNode parent = getOrCreateWorkspaceNode(parentFqn, workspace);
  -         WorkspaceNode node = getOrCreateWorkspaceNode(nodeFqn, workspace);
  +         WorkspaceNode parent = getOrCreateWorkspaceNode(parentFqn, workspace, false);
  +         if (parent == null) throw new NodeNotExistsException("Node " + parentFqn + " does not exist!");
  +         WorkspaceNode node = getOrCreateWorkspaceNode(nodeFqn, workspace, true);
   
            if (log.isTraceEnabled()) log.trace("Parent: " + parent);
            if (log.isTraceEnabled()) log.trace("Node: " + node);
  @@ -94,7 +96,7 @@
            // assign a global transaction here if we need to - should do all
            // this in the transaction interceptor
            Fqn fqn = getFqn(args);
  -         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
  +         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, true);
   
   
            if (workspaceNode != null)
  @@ -229,7 +231,8 @@
            log.warn("Attempting to move the root node.  Not taking any action, treating this as a no-op.");
            return;
         }
  -      WorkspaceNode oldParent = getOrCreateWorkspaceNode(nodeFqn.getParent(), ws);
  +      WorkspaceNode oldParent = getOrCreateWorkspaceNode(nodeFqn.getParent(), ws, false);
  +      if (oldParent == null) throw new NodeNotExistsException("Node " + nodeFqn.getParent() + " does not exist!");
         Object nodeName = nodeFqn.getLastElement();
   
         // now that we have the parent and target nodes:
  @@ -259,16 +262,14 @@
      private void moveFqns(WorkspaceNode node, Fqn newBase, TransactionWorkspace ws)
      {
         Fqn newFqn = new Fqn(newBase, node.getFqn().getLastElement());
  -      WorkspaceNode movedNode = getOrCreateWorkspaceNode(newFqn, ws);
  +      WorkspaceNode movedNode = getOrCreateWorkspaceNode(newFqn, ws, true);
         movedNode.put(node.getData());
   
         // process children
         for (Object n : node.getChildrenNames())
         {
  -         //         movedNode.createChild(n, new Fqn(node.getFqn(), n), movedNode.getNode(), ((TreeCacheProxyImpl)cache).cache, null);
  -         WorkspaceNode child = getOrCreateWorkspaceNode(new Fqn(node.getFqn(), n), ws);
  -         moveFqns(child, newFqn, ws);
  -         //movedNode.addChild(n, child);
  +         WorkspaceNode child = getOrCreateWorkspaceNode(new Fqn(node.getFqn(), n), ws, false);
  +         if (child != null) moveFqns(child, newFqn, ws);
         }
      }
   
  @@ -284,7 +285,7 @@
         for (Object child : n.getChildrenNames())
         {
            Fqn childFqn = new Fqn(myFqn, child);
  -         WorkspaceNode cn = getOrCreateWorkspaceNode(childFqn, ws);
  +         WorkspaceNode cn = getOrCreateWorkspaceNode(childFqn, ws, false);
            if (!ws.hasNode(childFqn)) ws.addNode(cn);
            greedyGetNodes(cn, ws);
         }
  @@ -335,10 +336,10 @@
         boolean debug = log.isDebugEnabled();
   
         Fqn parentFqn = workspaceNode.getFqn().getParent();
  -      WorkspaceNode parentNode = getOrCreateWorkspaceNode(parentFqn, workspace);
  +      WorkspaceNode parentNode = getOrCreateWorkspaceNode(parentFqn, workspace, false);
         if (parentNode == null)
         {
  -         throw new CacheException("Unable to find parent node with Fqn " + parentFqn);
  +         throw new NodeNotExistsException("Unable to find parent node with Fqn " + parentFqn);
         }
   
         parentNode.removeChild(new Fqn(workspaceNode.getFqn().getLastElement()));
  @@ -391,7 +392,7 @@
      {
         Fqn fqn = (Fqn) args[0];
         Object key = args[1];
  -      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
  +      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);
   
         if (workspaceNode == null)
         {
  @@ -413,7 +414,7 @@
      {
         Fqn fqn = (Fqn) args[0];
   
  -      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
  +      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);
   
         if (workspaceNode == null)
         {
  @@ -433,7 +434,7 @@
      {
         Fqn fqn = (Fqn) args[0];
   
  -      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
  +      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);
   
         if (workspaceNode == null)
         {
  @@ -454,7 +455,7 @@
      {
         Fqn fqn = (Fqn) args[0];
   
  -      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
  +      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);
   
         if (workspaceNode == null)
         {
  @@ -471,7 +472,7 @@
         }
      }
   
  -   private WorkspaceNode getOrCreateWorkspaceNode(Fqn fqn, TransactionWorkspace workspace)
  +   private WorkspaceNode getOrCreateWorkspaceNode(Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary)
      {
         WorkspaceNode workspaceNode = workspace.getNode(fqn);
         // if we do not have the node then we need to add it to the workspace
  @@ -489,7 +490,14 @@
         if (workspaceNode.isDeleted())
         {
            if (log.isDebugEnabled()) log.debug("Node " + fqn + " has been deleted in the workspace.");
  -         return null;
  +         if (undeleteIfNecessary)
  +         {
  +            workspaceNode.markAsDeleted(false);
  +         }
  +         else
  +         {
  +            workspaceNode = null;
  +         }
         }
         return workspaceNode;
      }
  
  
  
  1.40      +0 -2      JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticCreateIfNotExistsInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -b -r1.39 -r1.40
  --- OptimisticCreateIfNotExistsInterceptor.java	4 Jan 2007 05:35:37 -0000	1.39
  +++ OptimisticCreateIfNotExistsInterceptor.java	9 Jan 2007 16:21:53 -0000	1.40
  @@ -145,7 +145,6 @@
   
            // we will always have one root node here, by this stage
            Fqn tmpFqn = Fqn.ROOT;
  -         Fqn copy;
            for (int i = 0; i < treeNodeSize; i++)
            {
               boolean isTargetFqn = (i == (treeNodeSize - 1));
  @@ -187,7 +186,6 @@
                        log.debug("Parent node exists: " + workspaceNode);
                     }
                  }
  -               copy = tmpFqn.clone();
                  // this does not add it into the real child nodes - but in its
                  // local child map for the transaction
   
  
  
  



More information about the jboss-cvs-commits mailing list