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

Manik Surtani msurtani at jboss.com
Sat Dec 30 12:50:04 EST 2006


  User: msurtani
  Date: 06/12/30 12:50:04

  Modified:    src/org/jboss/cache/optimistic   WorkspaceNodeImpl.java
                        WorkspaceNode.java
  Log:
  Major changes to restructure cache and node object model
  
  Revision  Changes    Path
  1.33      +37 -154   JBossCache/src/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WorkspaceNodeImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/optimistic/WorkspaceNodeImpl.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -b -r1.32 -r1.33
  --- WorkspaceNodeImpl.java	20 Dec 2006 13:56:49 -0000	1.32
  +++ WorkspaceNodeImpl.java	30 Dec 2006 17:50:04 -0000	1.33
  @@ -10,20 +10,13 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.AbstractNode;
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.Node;
   import org.jboss.cache.NodeNotExistsException;
   import org.jboss.cache.NodeSPI;
  -import org.jboss.cache.OptimisticTreeNode;
  -import org.jboss.cache.TreeCache;
  -import org.jboss.cache.TreeNode;
  +import org.jboss.cache.VersionedNode;
   import org.jboss.cache.factories.NodeFactory;
  -import org.jboss.cache.lock.IdentityLock;
  -import org.jboss.cache.lock.LockingException;
  -import org.jboss.cache.lock.NodeLock;
  -import org.jboss.cache.lock.TimeoutException;
   
   import java.util.Collections;
   import java.util.HashMap;
  @@ -43,37 +36,36 @@
   
      private static Log log = LogFactory.getLog(WorkspaceNodeImpl.class);
   
  -   private Node node;
  +   private NodeSPI node;
      private TransactionWorkspace workspace;
      private DataVersion version = DefaultDataVersion.ZERO;
      private boolean dirty;
      private boolean created;
  -   private Map<Object, Node> optimisticChildNodeMap;
  +   private Map<Object, NodeSPI> optimisticChildNodeMap;
      private Map optimisticDataMap;
      private boolean versioningImplicit;
   
      /**
       * Constructs with a node and workspace.
       */
  -   public WorkspaceNodeImpl(Node node, TransactionWorkspace workspace)
  +   public WorkspaceNodeImpl(NodeSPI node, TransactionWorkspace workspace)
      {
  -      if (!(node instanceof OptimisticTreeNode))
  +      if (!(node instanceof VersionedNode))
         {
  -         throw new IllegalArgumentException("node " + node + " not OptimisticTreeNode");
  +         throw new IllegalArgumentException("node " + node + " not VersionedNode");
         }
         this.node = node;
         this.workspace = workspace;
  -      optimisticDataMap = new HashMap(node.getNodeSPI().getRawData());
  -      //log.fatal("Children map is " + node.getNodeSPI().getChildrenMap());
  -      Map childrenMap = node.getNodeSPI().getChildrenMap();
  +      optimisticDataMap = new HashMap(node.getRawData());
  +      Map childrenMap = node.getChildrenMap();
         if (childrenMap == null)
            optimisticChildNodeMap = new ConcurrentHashMap();
         else
  -         optimisticChildNodeMap = new ConcurrentHashMap(node.getNodeSPI().getChildrenMap());
  -      this.version = ((OptimisticTreeNode) node).getVersion();
  +         optimisticChildNodeMap = new ConcurrentHashMap(node.getChildrenMap());
  +      this.version = node.getVersion();
         if (version == null)
         {
  -         throw new IllegalStateException("OptimisticTreeNode version null");
  +         throw new IllegalStateException("VersionedNode version null");
         }
      }
   
  @@ -194,12 +186,12 @@
         }
   
         //see if we already have it
  -      Node child = optimisticChildNodeMap.get(child_name);
  +      NodeSPI child = optimisticChildNodeMap.get(child_name);
   
         // if not we need to create it
         if (child == null)
         {
  -         child = NodeFactory.getInstance().createNodeOfType(parent, child_name, fqn, parent, (Map) null, cache, version);
  +         child = (NodeSPI) NodeFactory.getInstance().createNodeOfType(parent, child_name, fqn, parent, null, cache, version);
            optimisticChildNodeMap.put(child_name, child);
         }
         if (log.isTraceEnabled())
  @@ -237,7 +229,7 @@
         WorkspaceNode wrapper = workspace.getNode((Fqn) fqn);
         if (wrapper == null)
         {
  -         DataNode temp = (DataNode) optimisticChildNodeMap.get(fqn);
  +         NodeSPI temp = optimisticChildNodeMap.get(fqn);
            if (temp != null)
            {
               wrapper = new WorkspaceNodeImpl(temp, workspace);
  @@ -249,7 +241,7 @@
         return wrapper;
      }
   
  -   public Node getNode()
  +   public NodeSPI getNode()
      {
         return node;
      }
  @@ -331,126 +323,6 @@
         return optimisticDataMap.containsKey(key);
      }
   
  -   public Set getDataKeys()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public boolean childExists(Object child_name)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public NodeLock getImmutableLock()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public IdentityLock getLock()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public int numAttributes()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public boolean hasChildren()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public TreeNode getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean createIfNotExists)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, Object key, Object value)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void removeAllChildren()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void print(StringBuffer sb, int indent)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void printDetails(StringBuffer sb, int indent)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void printIndent(StringBuffer sb, int indent)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void addChild(Object child_name, Node n)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void printLockInfo(StringBuffer sb, int indent)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public boolean isLocked()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void releaseAll(Object owner)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void releaseAllForce()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public Set acquireAll(Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, InterruptedException
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void setRecursiveTreeCacheInstance(TreeCache cache)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public boolean getChildrenLoaded()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void setChildrenLoaded(boolean b)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void setChildren(Map children)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void release(Object caller)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public void releaseForce()
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
      public String toString()
      {
         StringBuffer sb = new StringBuffer();
  @@ -476,7 +348,7 @@
            if (f.size() == 1)
            {
               Fqn ffqn = new Fqn(getFqn(), f);
  -            newNode = createChild(f.get(0), ffqn, this.node, getCache(), version);
  +            newNode = createChild(f.get(0), ffqn, node, getCache(), version);
            }
            else
            {
  @@ -484,6 +356,9 @@
               Node currentParent = this;
               for (Object o : f.peekElements())
               {
  +               if (currentParent instanceof WorkspaceNode)
  +                  newNode = ((WorkspaceNode) currentParent).getNode().getOrCreateChild(o, gtx);
  +               else
                  newNode = currentParent.getNodeSPI().getOrCreateChild(o, gtx);
                  currentParent = newNode;
               }
  @@ -507,9 +382,17 @@
   
      public Node getChild(Fqn f)
      {
  -      // ???
  +      boolean origVal = getCache().getInvocationContext().getOptionOverrides().isBypassInterceptorChain();
  +      if (!origVal) getCache().getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
  +      try
  +      {
         return node.getChild(f);
      }
  +      finally
  +      {
  +         if (!origVal) getCache().getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
  +      }
  +   }
   
      public Set<Node> getChildren()
      {
  @@ -524,6 +407,11 @@
         // return false;
      }
   
  +   public NodeSPI getNodeSPI()
  +   {
  +      throw new UnsupportedOperationException("WorkspaceNode has no access to a NodeSPI");
  +   }
  +
      public void move(Node newParent) throws NodeNotExistsException
      {
         throw new UnsupportedOperationException();
  @@ -556,11 +444,6 @@
         throw new UnsupportedOperationException();
      }
   
  -   public NodeSPI getNodeSPI()
  -   {
  -      return this;// node.getNodeSPI();
  -   }
  -
      public Node getOrCreateChild(Object name, GlobalTransaction tx)
      {
         throw new UnsupportedOperationException();
  @@ -573,7 +456,7 @@
   
      public CacheSPI getCache()
      {
  -      return node.getNodeSPI().getCache();
  +      return node.getCache();
      }
   
      public Map<Object, Object> getRawData()
  @@ -588,7 +471,7 @@
   
      public void setFqn(Fqn fqn)
      {
  -      node.getNodeSPI().setFqn(fqn);
  +      node.setFqn(fqn);
      }
   
      public boolean getDataLoaded()
  
  
  
  1.18      +10 -4     JBossCache/src/org/jboss/cache/optimistic/WorkspaceNode.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WorkspaceNode.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/optimistic/WorkspaceNode.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- WorkspaceNode.java	14 Dec 2006 17:18:48 -0000	1.17
  +++ WorkspaceNode.java	30 Dec 2006 17:50:04 -0000	1.18
  @@ -9,19 +9,19 @@
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  -import org.jboss.cache.TreeNode;
  +import org.jboss.cache.NodeSPI;
   
   import java.util.Map;
   import java.util.Set;
   
   /**
  - * Represents a type of {@link org.jboss.cache.NodeImpl} that is to be copied into a {@link TransactionWorkspace} for optimistically locked
  + * Represents a type of {@link org.jboss.cache.Node} that is to be copied into a {@link TransactionWorkspace} for optimistically locked
    * nodes.  Adds versioning and dirty flags over conventional Nodes.
    *
    * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
    * @author Steve Woodcock (<a href="mailto:stevew at jofti.com">stevew at jofti.com</a>)
    */
  -public interface WorkspaceNode extends TreeNode
  +public interface WorkspaceNode extends Node
   {
      public Map getMergedChildren();
   
  @@ -35,7 +35,7 @@
   
      public Map getMergedData();
   
  -   public Node getNode();
  +   public NodeSPI getNode();
   
      public Set getChildrenNames();
   
  @@ -50,4 +50,10 @@
      boolean isVersioningImplicit();
   
      void setVersioningImplicit(boolean b);
  +
  +   boolean isDeleted();
  +
  +   void markAsDeleted(boolean marker);
  +
  +   void markAsDeleted(boolean marker, boolean recursive);
   }
  
  
  



More information about the jboss-cvs-commits mailing list