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

Manik Surtani msurtani at jboss.com
Fri Sep 15 20:23:35 EDT 2006


  User: msurtani
  Date: 06/09/15 20:23:35

  Modified:    src/org/jboss/cache    Node.java TreeCache.java
                        TreeCacheProxyImpl.java
  Log:
  Updates to the move() API plus more UTs
  
  Revision  Changes    Path
  1.46      +171 -167  JBossCache/src/org/jboss/cache/Node.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Node.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Node.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -b -r1.45 -r1.46
  --- Node.java	17 Aug 2006 17:34:59 -0000	1.45
  +++ Node.java	16 Sep 2006 00:23:35 -0000	1.46
  @@ -12,24 +12,22 @@
   
   /**
    * Along with {@link Cache}, this is a central construct in the tree structure of JBoss Cache.
  - *
  + * <p/>
    * A Node represents a point in the tree.  A Node has references to it's children, parent
    * (each Node has a single parent) and data contained within the Node (key value pairs).
    *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @see Cache
    * @since 2.0.0
  - * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
   public interface Node 
   {
       /**
  -     *
        * @return the parent node.  If the current node is a root node, this call returns null.
        */
       Node getParent();
   
       /**
  -     *
        * @return an immutable {@link Collection} of child nodes.  Empty {@link Collection} if there aren't any children.
        */
       Collection<Node> getChildren();
  @@ -45,16 +43,15 @@
       Set getKeys();
   
       /**
  -     *
        * @return The {@link Fqn} which represents the location of this {@link Node} in the tree structure.  The {@link Fqn} returned is absolute.
        */
       Fqn getFqn();
   
       /**
        * Adds a child node with the given {@link Fqn} under the current node.  Returns the newly created node.
  -     *
  +    * <p/>
        * If the child exists returns the child node anyway.  Guaranteed to return a non-null node.
  -     *
  +    * <p/>
        * The {@link Fqn} passed in is relative to the current node.  The new child node will have an absolute fqn
        * calculated as follows: <pre>new Fqn(getFqn(), f)</pre>.  See {@link Fqn} for the operation of this constructor.
        *
  @@ -65,7 +62,7 @@
   
       /**
        * Removes a child node specified by the given relative {@link Fqn}.
  -     *
  +    * <p/>
        * If you wish to remove children based on absolute {@link Fqn}s, use the {@link Cache} interface instead.
        *
        * @param f {@link Fqn} of the child node, relative to the current node.
  @@ -74,6 +71,7 @@
   
       /**
        * Returns the child node
  +    *
        * @param f {@link Fqn} of the child node
        * @return null if the child does not exist.
        */
  @@ -82,6 +80,7 @@
       /**
        * Puts a key and a value into the current node's data map.
        * Overwrites if the key already exists.
  +    *
        * @param k
        * @param v
        */
  @@ -90,6 +89,7 @@
       /**
        * Puts a key and a value into the current node's data map if nothing exists under the key.
        * Does nothing if the key already exists.
  +    *
        * @param k
        * @param v
        */
  @@ -111,8 +111,9 @@
       /**
        * Puts an entire map of key-value pairs into the current node's data map.  If any data exists, existing
        * keys are not overwritten with the keys in the new map.
  -     *
  +    * <p/>
        * Forms a union of the 2 data sets with the old data set taking precedence.
  +    *
        * @param m
        */
       void putIfNull(Map m);
  @@ -120,6 +121,7 @@
   
       /**
        * Gets data stored in the current node under key k
  +    *
        * @param k key of the data to return
        * @return arbitrary object stored under the key in this node, null if there is no data under the given key.
        */
  @@ -127,6 +129,7 @@
   
       /**
        * Removes data stored under the given key.
  +    *
        * @param k
        * @return Returns the old value contained under this key.  Null if key doesn't exist.
        */
  @@ -139,37 +142,37 @@
   
       /**
        * Moves a part of the tree to a different subtree.
  -     *
  +    * <p/>
        * E.g.:
  -     *
  +    * <p/>
        * assume a tree structure such as:
  -     *
  +    * <p/>
        * <pre>
        *  /a/b/c
        *  /a/b/d
        *  /a/b/e
  -     *
  -     *
  +    * <p/>
  +    * <p/>
        *  Node n = cache.getChild("/a/b/c");
  -     *
  +    * <p/>
        *  n.move(cache.getChild("/a/b/d"));
        * </pre>
  -     *
  +    * <p/>
        * Will result in:
        * <pre>
  -     *
  +    * <p/>
        * /a/b/d/c
        * /a/b/e
  -     *
  +    * <p/>
        * </pre>
  -     *
  +    * <p/>
        * and now
  -     *
  +    * <p/>
        * <pre>
        * Node n2 = cache.getChild("/a/b/e");
        * n2.move(cache.getChild("/a"));
        * </pre>
  -     *
  +    * <p/>
        * will result in:
        * <pre>
        * /a/b/d/c
  @@ -178,8 +181,9 @@
        * No-op if called on a root node.
        *
        * @param newParent new location under which to attach the current node.
  +    * @throws NodeNotExistsException may throw one of these if the target node does not exist or if a different thread has moved this node elsewhere already.
        */
  -    void move(Node newParent);
  +   void move(Node newParent) throws NodeNotExistsException;
   
       /**
        * @param f {@link Fqn} relative to the current node of the child you are testing the existence of.
  
  
  
  1.247     +44 -38    JBossCache/src/org/jboss/cache/TreeCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
  retrieving revision 1.246
  retrieving revision 1.247
  diff -u -b -r1.246 -r1.247
  --- TreeCache.java	15 Sep 2006 18:01:01 -0000	1.246
  +++ TreeCache.java	16 Sep 2006 00:23:35 -0000	1.247
  @@ -93,7 +93,7 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @author Brian Stansberry
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Id: TreeCache.java,v 1.246 2006/09/15 18:01:01 msurtani Exp $
  + * @version $Id: TreeCache.java,v 1.247 2006/09/16 00:23:35 msurtani Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -3650,20 +3650,26 @@
         // parent pointer is calculated on the fly using Fqns.
   
         // now adjust Fqns of node and all children.
  -      moveFqns(node, oldParent.getFqn(), newParent.getFqn());
  +      moveFqns(node, newParent.getFqn());
  +
  +      // now register an undo op
  +      if (getInvocationContext().getTransaction() != null)
  +      {
  +         MethodCall undo = MethodCallFactory.create(MethodDeclarations.moveMethodLocal, oldParent.getFqn(), new Fqn(newParentFqn, nodeToMoveFqn.getLast()));
  +         tx_table.addUndoOperation(getInvocationContext().getGlobalTransaction(), undo);
  +      }
      }
   
  -   private void moveFqns(NodeImpl node, Fqn oldBase, Fqn newBase)
  +   private void moveFqns(NodeImpl node, Fqn newBase)
      {
  -      Fqn oldFqn = node.getFqn();
  -      Fqn newFqn = new Fqn(newBase, oldFqn.getLast());
  +      Fqn newFqn = new Fqn(newBase, node.getName());
         node.setFqn(newFqn);
   
         // process children
         for (Object n : node.getChildren().values())
         {
            NodeImpl child = (NodeImpl) n;
  -         moveFqns(child, oldFqn, newFqn);
  +         moveFqns(child, newFqn);
         }
      }
   
  
  
  
  1.35      +8 -1      JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheProxyImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -b -r1.34 -r1.35
  --- TreeCacheProxyImpl.java	15 Sep 2006 18:01:02 -0000	1.34
  +++ TreeCacheProxyImpl.java	16 Sep 2006 00:23:35 -0000	1.35
  @@ -447,7 +447,7 @@
         }
      }
   
  -   public void move(Node newParent)
  +   public void move(Node newParent) throws NodeNotExistsException
      {
         treeCache.move(newParent.getFqn(), currentNode.getFqn());
      }
  @@ -570,4 +570,11 @@
         return result;
      }
   
  +
  +   public String toString()
  +   {
  +      return "TreeCacheProxyImpl{" +
  +             "Fqn=" + currentNode.getFqn() +
  +             '}';
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list