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

Manik Surtani msurtani at jboss.com
Tue Jan 2 12:15:30 EST 2007


  User: msurtani
  Date: 07/01/02 12:15:30

  Modified:    src/org/jboss/cache/optimistic   WorkspaceNode.java
                        WorkspaceNodeImpl.java
  Log:
  some api changes
  
  Revision  Changes    Path
  1.20      +84 -3     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.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- WorkspaceNode.java	30 Dec 2006 19:48:46 -0000	1.19
  +++ WorkspaceNode.java	2 Jan 2007 17:15:30 -0000	1.20
  @@ -7,7 +7,6 @@
   package org.jboss.cache.optimistic;
   
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
   import org.jboss.cache.NodeSPI;
   
  @@ -23,37 +22,119 @@
    */
   public interface WorkspaceNode extends Node
   {
  +   /**
  +    * Attempts to merge children created during the transaction with underlying children in the tree.
  +    *
  +    * @return a merged map of child names and Nodes
  +    */
      public Map<Object, NodeSPI> getMergedChildren();
   
  +   /**
  +    * Retrieves the data version of the in-memory node.
  +    *
  +    * @return A data version
  +    */
      public DataVersion getVersion();
   
  +   /**
  +    * Sets the data version of this workspace node.
  +    *
  +    * @param version a {@link org.jboss.cache.optimistic.DataVersion} implementation.
  +    */
      public void setVersion(DataVersion version);
   
  +   /**
  +    * Retrieves all data keys
  +    *
  +    * @return an immutable set.
  +    */
      public Set<Object> getKeys();
   
  +   /**
  +    * Returns true if this node needs to be merged when the transaction commits.
  +    *
  +    * @return true if needs merging, false otherwise.
  +    */
      public boolean isDirty();
   
  +   /**
  +    * Attempts to merge data changed during the current transaction with the data in the underlying tree.
  +    *
  +    * @return a merged map of key/value pairs.
  +    */
      public Map<Object, Object> getMergedData();
   
  +   /**
  +    * Retrieves a reference to the underlying {@link NodeSPI} instance.
  +    *
  +    * @return a node
  +    */
      public NodeSPI getNode();
   
      public Set<Object> getChildrenNames();
   
  +   /**
  +    * Retrieves a TransactionWorkspace instance associated with the current transaction, which the current WorkspaceNode instance
  +    * lives in.
  +    *
  +    * @return a TransactionWorkspace.
  +    */
      public TransactionWorkspace getTransactionWorkspace();
   
  +   /**
  +    * @return true if the instance was created in the current transaction; i.e., it did not exist in the underlying data tree.
  +    */
      public boolean isCreated();
   
  +   /**
  +    * Marks the instance as having been created in the current transaction.
  +    */
      public void markAsCreated();
   
  -   public Node createChild(Object child_name, Fqn fqn, Node parent, CacheSPI cache, DataVersion version);
  +   /**
  +    * Creates a child node.
  +    *
  +    * @param child_name Object name of the child to create
  +    * @param parent     A reference to the parent node
  +    * @param cache      CacheSPI instance to create this node in
  +    * @param version    DataVersion to apply to the child.  If null, {@link DefaultDataVersion#ZERO} will be used.
  +    * @return a NodeSPI pointing to the newly created child.
  +    */
  +   public NodeSPI createChild(Object child_name, NodeSPI parent, CacheSPI cache, DataVersion version);
   
  +   /**
  +    * Tests whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using {@link org.jboss.cache.optimistic.DefaultDataVersion}
  +    * rather than a custom {@link org.jboss.cache.optimistic.DataVersion} passed in using {@link org.jboss.cache.config.Option#setDataVersion(DataVersion)})
  +    *
  +    * @return true if versioning is implicit.
  +    */
      boolean isVersioningImplicit();
   
  +   /**
  +    * Sets whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using {@link org.jboss.cache.optimistic.DefaultDataVersion}
  +    * rather than a custom {@link org.jboss.cache.optimistic.DataVersion} passed in using {@link org.jboss.cache.config.Option#setDataVersion(DataVersion)})
  +    *
  +    * @param b set to true if versioning is implicit, false otherwise.
  +    */
      void setVersioningImplicit(boolean b);
   
  +   /**
  +    * @return true if the instance has been deleted in the current transaction.
  +    */
      boolean isDeleted();
   
  +   /**
  +    * Marks the node as being deleted (or not) in the current transaction.  This is not recursive, child nodes are not affected.
  +    *
  +    * @param marker true if the node has been deleted, false if not.
  +    */
      void markAsDeleted(boolean marker);
   
  +   /**
  +    * Same as {@link #markAsDeleted(boolean)} except that the option to recurse into children is provided.
  +    *
  +    * @param marker    true if the node has been deleted, false if not.
  +    * @param recursive if true, child nodes (and their children) are marked as well.
  +    */
      void markAsDeleted(boolean marker, boolean recursive);
   }
  
  
  
  1.38      +7 -146    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.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- WorkspaceNodeImpl.java	1 Jan 2007 22:12:19 -0000	1.37
  +++ WorkspaceNodeImpl.java	2 Jan 2007 17:15:30 -0000	1.38
  @@ -14,6 +14,7 @@
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.Node;
   import org.jboss.cache.NodeSPI;
  +import org.jboss.cache.UnversionedNode;
   import org.jboss.cache.VersionedNode;
   import org.jboss.cache.factories.NodeFactory;
   
  @@ -81,12 +82,6 @@
         return node.getFqn();
      }
   
  -   public void put(Map<Object, Object> data, boolean eraseData)
  -   {
  -      realPut(data, eraseData);
  -      dirty = true;
  -   }
  -
      public void put(Map<Object, Object> data)
      {
         realPut(data, false);
  @@ -107,12 +102,6 @@
   
      }
   
  -   public void clear()
  -   {
  -      optimisticDataMap.clear();
  -      dirty = true;
  -   }
  -
      public Object get(Object key)
      {
         return optimisticDataMap.get(key);
  @@ -144,40 +133,12 @@
         if (data != null) optimisticDataMap.putAll(data);
      }
   
  -   public void removeChild(Object childName)
  -   {
  -      // TODO: MANIK: Remove dirty=true, implement merging on child mods instead.
  -      dirty = true;
  -      optimisticChildNodeMap.remove(childName);
  -   }
  -
  -   //this needs to be changed to return wrapped node
      public Node getParent()
      {
         return node.getParent();
      }
   
  -   //this what the above method should look like
  -   public Node getWrappedParent()
  -   {
  -
  -      //see if in the the transaction map
  -      WorkspaceNode workspaceNode = workspace.getNode(node.getParent().getFqn());
  -      if (workspaceNode == null)
  -      {
  -         workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node.getParent(), workspace);
  -         workspace.addNode(workspaceNode);
  -
  -      }
  -      return workspaceNode;
  -   }
  -
  -   public Node createChild(Object child_name, Fqn fqn, Node parent)
  -   {
  -      throw new UnsupportedOperationException("Unsupported for optimistic nodes");
  -   }
  -
  -   public Node createChild(Object child_name, Fqn fqn, Node parent, CacheSPI cache, DataVersion version)
  +   public NodeSPI createChild(Object child_name, NodeSPI parent, CacheSPI cache, DataVersion version)
      {
         if (child_name == null)
         {
  @@ -190,17 +151,12 @@
         // if not we need to create it
         if (child == null)
         {
  -         child = (NodeSPI) NodeFactory.getInstance().createNodeOfType(parent, child_name, fqn, parent, null, cache, version);
  +         Fqn childFqn = new Fqn(parent.getFqn(), child_name);
  +         child = (NodeSPI) NodeFactory.getInstance().createNodeOfType(parent, child_name, childFqn, parent, null, cache, version);
            optimisticChildNodeMap.put(child_name, child);
         }
  -      if (log.isTraceEnabled())
  -      {
  -         log.trace("createChild: fqn=" + fqn);
  -      }
  -      // TODO: MANIK: Remove dirty=true, implement merging on child mods instead.
         dirty = true;
         return child;
  -
      }
   
      public boolean isVersioningImplicit()
  @@ -213,33 +169,12 @@
         versioningImplicit = b;
      }
   
  -   //this needs to be changed to return wrapped node
      public Node getChild(Object childName)
      {
         //see if in the the transaction map
         return optimisticChildNodeMap.get(childName);
      }
   
  -   //this what the above method should be like
  -   public Node getWrappedChild(Object fqn)
  -   {
  -
  -      //see if in the the transaction map
  -      WorkspaceNode wrapper = workspace.getNode((Fqn) fqn);
  -      if (wrapper == null)
  -      {
  -         NodeSPI temp = optimisticChildNodeMap.get(fqn);
  -         if (temp != null)
  -         {
  -            wrapper = new WorkspaceNodeImpl(temp, workspace);
  -            workspace.addNode(wrapper);
  -            // childrenInWorkspace.add( wrapper );
  -         }
  -
  -      }
  -      return wrapper;
  -   }
  -
      public NodeSPI getNode()
      {
         return node;
  @@ -257,40 +192,14 @@
   
      public Map<Object, NodeSPI> getMergedChildren()
      {
  -      //return mergeMaps((OptimisticMap) optimisticChildNodeMap);
         return optimisticChildNodeMap;
      }
   
  -   //    private Map mergeMaps(OptimisticMap opMap)
  -   //    {
  -   //        Map temp = new HashMap(opMap.getOriginalMap());
  -   //        //first remove all removed keys
  -   //        for (Iterator it = opMap.getRemovedMap().keySet().iterator(); it.hasNext();)
  -   //        {
  -   //            temp.remove(it.next());
  -   //        }
  -   //        // then add in changed stuff
  -   //        for (Iterator it = opMap.getLocalMap().entrySet().iterator(); it.hasNext();)
  -   //        {
  -   //            Map.Entry entry = (Map.Entry) it.next();
  -   //            temp.put(entry.getKey(), entry.getValue());
  -   //        }
  -   //        return temp;
  -   //        TODO: MANIK: BN: Does this need to be a copy?!??
  -   //        return new HashMap(opMap.getLocalMap());
  -   //        return opMap.getLocalMap();
  -   //    }
  -
      public Map<Object, Object> getMergedData()
      {
         return optimisticDataMap;
      }
   
  -   public Object getName()
  -   {
  -      return node.getFqn().getLastElement();
  -   }
  -
      public TransactionWorkspace getTransactionWorkspace()
      {
         return workspace;
  @@ -312,11 +221,6 @@
         return Collections.unmodifiableMap(optimisticDataMap);
      }
   
  -   public boolean containsKey(Object key)
  -   {
  -      return optimisticDataMap.containsKey(key);
  -   }
  -
      public String toString()
      {
         StringBuffer sb = new StringBuffer();
  @@ -340,8 +244,7 @@
   
            if (f.size() == 1)
            {
  -            Fqn ffqn = new Fqn(getFqn(), f);
  -            newNode = createChild(f.get(0), ffqn, node, getCache(), version);
  +            newNode = createChild(f.get(0), node, getCache(), version);
            }
            else
            {
  @@ -383,7 +286,6 @@
      public Set<Node> getChildren()
      {
         throw new UnsupportedOperationException();
  -      //return node.getChildren();
      }
   
      public boolean hasChild(Fqn f)
  @@ -417,49 +319,8 @@
         }
      }
   
  -   public void removeChildren()
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public Node getOrCreateChild(Object name, GlobalTransaction tx)
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public void setCache(CacheSPI cache)
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public CacheSPI getCache()
  -   {
  -      return node.getCache();
  -   }
  -
  -   public Map<Object, Object> getRawData()
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public void setChildrenMap(Map<Object, Node> children)
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public void setFqn(Fqn fqn)
  +   protected CacheSPI getCache()
      {
  -      node.setFqn(fqn);
  +      return ((UnversionedNode) node).getCache();
      }
  -
  -   public boolean getDataLoaded()
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
  -   public void setDataLoaded(boolean dataLoaded)
  -   {
  -      throw new UnsupportedOperationException();
  -   }
  -
   }
  
  
  



More information about the jboss-cvs-commits mailing list