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

Manik Surtani manik at jboss.org
Wed Mar 7 17:46:29 EST 2007


  User: msurtani
  Date: 07/03/07 17:46:29

  Modified:    src/org/jboss/cache/interceptors   Tag:
                        Branch_JBossCache_1_4_0
                        OptimisticValidatorInterceptor.java
                        OptimisticNodeInterceptor.java
  Log:
  JBCACHE-961 - more sophisticated merging of child maps in workspace nodes backported to 1.4.x
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.25.2.15 +41 -12    JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticValidatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java,v
  retrieving revision 1.25.2.14
  retrieving revision 1.25.2.15
  diff -u -b -r1.25.2.14 -r1.25.2.15
  --- OptimisticValidatorInterceptor.java	31 Jan 2007 13:05:44 -0000	1.25.2.14
  +++ OptimisticValidatorInterceptor.java	7 Mar 2007 22:46:28 -0000	1.25.2.15
  @@ -13,6 +13,7 @@
   import org.jboss.cache.InvocationContext;
   import org.jboss.cache.OptimisticTreeNode;
   import org.jboss.cache.TreeCache;
  +import org.jboss.cache.TreeNode;
   import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
   import org.jboss.cache.optimistic.DataVersioningException;
  @@ -25,6 +26,8 @@
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.List;
  +import java.util.Set;
   
   /**
    * Validates the data in the transaction workspace against data in the actual
  @@ -198,19 +201,47 @@
               {
                   // "Will somebody please think of the children!!"
                   // if (wrappedNode.hasCreatedOrRemovedChildren() handleChildNodes(wrappedNode);
  +                //if (wrappedNode.isDirty())
  +                //{
  +              OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
  +              boolean updateVersion = false;
  +
  +              if (wrappedNode.isChildrenModified())
  +              {
  +                 log.trace("Updating children since node has modified children");
  + 	              // merge children.
  +                 List deltas = wrappedNode.getMergedChildren();
  +
  +                 if (trace) log.trace("Applying children deltas to parent node " + current.getFqn());
  + 	              for (Iterator i = ((Set) deltas.get(0)).iterator(); i.hasNext();)
  + 	              {
  +                     TreeNode child = (TreeNode) i.next();
  +                     current.addChild(child.getName(), child);
  + 	              }
  +
  + 	              for (Iterator i = ((Set) deltas.get(1)).iterator(); i.hasNext();)
  +                 {
  +                    TreeNode child = (TreeNode) i.next();
  +                    current.removeChild(child.getName());
  +                 }
  +
  +                  updateVersion = cache.getLockParentForChildInsertRemove();
  +              }
  +
                   if (wrappedNode.isDirty())
                   {
                       cache.notifyNodeModify(wrappedNode.getFqn(), true);
  -                    OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
  -                    Map mergedChildren = wrappedNode.getMergedChildren();
   
  -                    // this could be done better to account for more subtle merges
  -                    current.setChildren(mergedChildren);
  -
  -                    if (trace) log.trace("inserting merged data " + wrappedNode.getMergedData());
  +                    log.trace("Merging data since node is dirty");
                       Map mergedData = wrappedNode.getMergedData();
                       current.put(mergedData, true);
  +                    updateVersion = true;
  +                    cache.notifyNodeModified(wrappedNode.getFqn());
  +                    cache.notifyNodeModify(wrappedNode.getFqn(), false);
  +               }
   
  +               if (updateVersion)
  +               {
                       if (wrappedNode.isVersioningImplicit())
                       {
                           if (trace) log.trace("Versioning is implicit; incrementing.");
  @@ -225,12 +256,10 @@
                           current.setVersion(wrappedNode.getVersion());
                       }
                       if (trace) log.trace("Setting version of node from " + wrappedNode.getVersion() + " to " + current.getVersion());
  -                    cache.notifyNodeModified(wrappedNode.getFqn());
  -                    cache.notifyNodeModify(wrappedNode.getFqn(), false);
                   }
                   else
                   {
  -                    if (trace) log.trace("Merging not necessary since the node is not dirty");
  +                    if (trace) log.trace("Version update on " + wrappedNode.getFqn() + " not necessary since the node is not dirty or LockParentForChildInsertRemove is set to false");
                       cache.notifyNodeVisited(wrappedNode.getFqn());
                   }
               }
  
  
  
  1.21.2.9  +5 -1      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.21.2.8
  retrieving revision 1.21.2.9
  diff -u -b -r1.21.2.8 -r1.21.2.9
  --- OptimisticNodeInterceptor.java	28 Feb 2007 10:58:41 -0000	1.21.2.8
  +++ OptimisticNodeInterceptor.java	7 Mar 2007 22:46:28 -0000	1.21.2.9
  @@ -339,6 +339,7 @@
   
      private WorkspaceNode getOrCreateWorkspaceNode(Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary)
      {
  +      if (log.isTraceEnabled()) log.trace("Attempting to get node " + fqn + " into the workspace");
         WorkspaceNode workspaceNode = workspace.getNode(fqn);
         // if we do not have the node then we need to add it to the workspace
         if (workspaceNode == null)
  @@ -369,7 +370,10 @@
         }
   
         if (workspaceNode != null && !(workspaceNode.getVersion() instanceof DefaultDataVersion))
  +      {
  +         log.trace("Setting versioning to explicit");
            workspaceNode.setVersioningImplicit(false);      
  +      }
         return workspaceNode;
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list