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

Manik Surtani msurtani at jboss.com
Tue Sep 19 13:10:50 EDT 2006


  User: msurtani
  Date: 06/09/19 13:10:50

  Modified:    src/org/jboss/cache/interceptors   
                        OptimisticCreateIfNotExistsInterceptor.java
                        OptimisticInterceptor.java
                        OptimisticNodeInterceptor.java
  Log:
  Getting there with moving and opt locking ...
  
  Revision  Changes    Path
  1.29      +28 -25    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.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- OptimisticCreateIfNotExistsInterceptor.java	30 Aug 2006 20:01:58 -0000	1.28
  +++ OptimisticCreateIfNotExistsInterceptor.java	19 Sep 2006 17:10:50 -0000	1.29
  @@ -11,9 +11,9 @@
   import org.jboss.cache.Fqn;
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.InvocationContext;
  +import org.jboss.cache.Node;
   import org.jboss.cache.OptimisticTransactionEntry;
   import org.jboss.cache.TransactionEntry;
  -import org.jboss.cache.TransactionTable;
   import org.jboss.cache.TreeCacheProxyImpl;
   import org.jboss.cache.TreeNode;
   import org.jboss.cache.factories.NodeFactory;
  @@ -42,47 +42,50 @@
         {
            Object[] args = m.getArgs();
            Fqn fqn = (Fqn) (args != null ? args[1] : null);
  -         if (fqn == null)
  -         {
  -            throw new CacheException("failed extracting FQN from method " + m);
  -         }
  +
            if (!cache.hasChild(fqn))
            {
  -            GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction();
  -            if (gtx != null)
  -            {
  -               createNode(fqn, gtx, txTable);
  +            createNode(fqn);
               }
  -            else
  +      }
  +      else if (m.getMethodId() == MethodDeclarations.moveMethodLocal_id)
               {
  -               throw new CacheException("no transaction or temporary transaction found " + m);
  +         Object[] args = m.getArgs();
  +         move((Fqn) args[0], (Fqn) args[1]);
               }
   
  +      return super.invoke(m);
            }
  +
  +   private void move(Fqn newParent, Fqn nodeFqn)
  +   {
  +      List<Fqn> fqns = new ArrayList<Fqn>();
  +      fqns.add(newParent);
  +
  +      //  peek into Node and get a hold of all child fqns as these need to be in the workspace.
  +      Node node = cache.getChild(nodeFqn);
  +      greedyGetFqns(fqns, node);
  +
  +      for (Fqn f : fqns)
  +      {
  +         if (!cache.hasChild(f)) createNode(f);
         }
  -      return super.invoke(m);
      }
   
      /**
       * The only method that should be creating nodes.
       *
       * @param fqn
  -    * @param gtx
  -    * @param tx_table
       * @throws CacheException
       */
  -   private void createNode(Fqn fqn, GlobalTransaction gtx, TransactionTable tx_table)
  -           throws CacheException
  +   private void createNode(Fqn fqn) throws CacheException
      {
  -
         // we do nothing if fqn is null
  -      if (fqn == null)
  -      {
  -         return;
  -      }
  +      if (fqn == null) return;
   
         // get the transaction to create the nodes in
  -      TransactionEntry baseTransactionEntry = tx_table.get(gtx);
  +      GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction();
  +      TransactionEntry baseTransactionEntry = txTable.get(gtx);
         OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry) baseTransactionEntry;
   
         if (transactionEntry == null)
  
  
  
  1.6       +47 -22    JBossCache/src/org/jboss/cache/interceptors/OptimisticInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- OptimisticInterceptor.java	17 Aug 2006 21:57:58 -0000	1.5
  +++ OptimisticInterceptor.java	19 Sep 2006 17:10:50 -0000	1.6
  @@ -6,10 +6,17 @@
    */
   package org.jboss.cache.interceptors;
   
  -import org.jboss.cache.*;
  +import org.jboss.cache.CacheException;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.GlobalTransaction;
  +import org.jboss.cache.Node;
  +import org.jboss.cache.OptimisticTransactionEntry;
  +import org.jboss.cache.TransactionTable;
   import org.jboss.cache.optimistic.TransactionWorkspace;
   
   import javax.transaction.TransactionManager;
  +import java.util.List;
   
   /**
    * Abstract interceptor for optimistic locking
  @@ -40,4 +47,22 @@
           // try and get the workspace from the transaction
           return transactionEntry.getTransactionWorkSpace();
       }
  +
  +   /**
  +    * Adds the Fqn of the node as well as all children and childrens children to the list.
  +    *
  +    * @param list
  +    * @param n
  +    */
  +   protected void greedyGetFqns(List<Fqn> list, Node n)
  +   {
  +      list.add(n.getFqn());
  +
  +      for (Node child : n.getChildren())
  +      {
  +         greedyGetFqns(list, child);
  +      }
  +   }
  +
  +
   }
  
  
  
  1.28      +32 -7     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.27
  retrieving revision 1.28
  diff -u -b -r1.27 -r1.28
  --- OptimisticNodeInterceptor.java	13 Sep 2006 10:34:53 -0000	1.27
  +++ OptimisticNodeInterceptor.java	19 Sep 2006 17:10:50 -0000	1.28
  @@ -21,7 +21,6 @@
   import org.jboss.cache.optimistic.TransactionWorkspace;
   import org.jboss.cache.optimistic.WorkspaceNode;
   
  -import javax.transaction.Transaction;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.SortedMap;
  @@ -37,7 +36,6 @@
      public Object invoke(MethodCall m) throws Throwable
      {
         InvocationContext ctx = cache.getInvocationContext();
  -      Transaction tx = ctx.getTransaction();
         Object[] args = m.getArgs();
   
         Object result = null;
  @@ -46,13 +44,24 @@
   
         TransactionWorkspace workspace = getTransactionWorkspace(gtx);
   
  -      if (MethodDeclarations.isCrudMethod(m.getMethodId()))
  +      if (MethodDeclarations.moveMethodLocal_id == m.getMethodId())
         {
  -         if (tx == null || !isValid(tx))
  -         {
  -            throw new CacheException("Must be in a valid transaction " + m);
  -         }
  +         if (ctx.getOptionOverrides().getDataVersion() != null)
  +            throw new CacheException("Setting a data version while performing a move() is not supported!!");
  +
  +         Fqn parentFqn = (Fqn) args[0], nodeFqn = (Fqn) args[1];
  +         WorkspaceNode parent = getOrCreateWorkspaceNode(parentFqn, workspace);
  +         WorkspaceNode node = getOrCreateWorkspaceNode(nodeFqn, workspace);
  +
  +         // be greedy about it - get children as well.
  +         greedyGetNodes(node, workspace);
   
  +         // now that we have all we need in the workspace, perform the move.
  +
  +         throw new CacheException("Implement optimistic moving!!");
  +      }
  +      else if (MethodDeclarations.isCrudMethod(m.getMethodId()))
  +      {
            // assign a global transaction here if we need to - should do all
            // this in the transaction interceptor
            WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(getFqn(args), workspace);
  @@ -136,6 +145,22 @@
         return result;
      }
   
  +   /**
  +    * performs a getOrCreateNode on all n's children, recursively.
  +    *
  +    * @param n
  +    */
  +   protected void greedyGetNodes(WorkspaceNode n, TransactionWorkspace ws)
  +   {
  +      Fqn myFqn = n.getFqn();
  +
  +      for (Object child : n.getChildrenNames())
  +      {
  +         Fqn childFqn = new Fqn(myFqn, child);
  +         greedyGetNodes(getOrCreateWorkspaceNode(childFqn, ws), ws);
  +      }
  +   }
  +
      private Fqn getFqn(Object[] args)
      {
         return (Fqn) args[1];
  
  
  



More information about the jboss-cvs-commits mailing list