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

Manik Surtani msurtani at jboss.com
Tue Jan 2 14:19:05 EST 2007


  User: msurtani
  Date: 07/01/02 14:19:05

  Modified:    src/org/jboss/cache/factories  NodeFactory.java
  Log:
  Optimised NodeFactory
  
  Revision  Changes    Path
  1.17      +15 -62    JBossCache/src/org/jboss/cache/factories/NodeFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/NodeFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- NodeFactory.java	30 Dec 2006 17:49:57 -0000	1.16
  +++ NodeFactory.java	2 Jan 2007 19:19:05 -0000	1.17
  @@ -12,7 +12,6 @@
   import org.jboss.cache.NodeSPI;
   import org.jboss.cache.UnversionedNode;
   import org.jboss.cache.VersionedNode;
  -import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.optimistic.TransactionWorkspace;
   import org.jboss.cache.optimistic.WorkspaceNode;
   import org.jboss.cache.optimistic.WorkspaceNodeImpl;
  @@ -26,36 +25,25 @@
    */
   public class NodeFactory
   {
  -   private static NodeFactory _singleton;
  -
      public enum NodeType
      {
  -      UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE;
  +      UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE
      }
   
  -   /**
  -    * private empty ctor
  -    */
  -   private NodeFactory()
  -   {
  -   }
  +   private CacheSPI cache;
  +   private boolean optimistic = cache.getConfiguration().isNodeLockingOptimistic();
   
      /**
  -    * Singleton accessor
  -    *
  -    * @return a singleton instance of the NodeFactory
  +    * Constructs an instance of the factory
       */
  -   public static NodeFactory getInstance()
  +   public NodeFactory(CacheSPI cache)
      {
  -      if (_singleton == null)
  -         _singleton = new NodeFactory();
  -      return _singleton;
  +      this.cache = cache;
      }
   
      /**
       * Creates a new {@link Node} instance.
       *
  -    * @param nodeType  either {@link org.jboss.cache.factories.NodeFactory.NodeType#UNVERSIONED_NODE} or {@link org.jboss.cache.factories.NodeFactory.NodeType#VERSIONED_NODE}
       * @param childName the new node's name
       * @param fqn       the new node's Fqn
       * @param parent    the new node's parent
  @@ -64,49 +52,20 @@
       *                  be directly assigned to the new node's data field;
       *                  <code>false</code> if param <code>data</code>'s contents
       *                  should be copied into the new node's data field.
  -    * @param cache     the cache to which the new node will be added
       * @return the new node
       */
  -   public Node createDataNode(NodeType nodeType, Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe,
  -                              DataVersion version, CacheSPI cache)
  -   {
  -      switch (nodeType)
  +   public Node createDataNode(Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe)
         {
  -         case UNVERSIONED_NODE:
  -            return new UnversionedNode(childName, fqn, data, mapSafe, cache);
  -         case VERSIONED_NODE:
  -            return new VersionedNode(childName, fqn, parent, data, cache);
  -         default:
  -            throw new IllegalArgumentException();
  -      }
  +      return optimistic ? new VersionedNode(childName, fqn, parent, data, cache) : new UnversionedNode(childName, fqn, data, mapSafe, cache);
      }
   
  -   /**
  -    * Creates a node of the same type of the node passed in as a template.  The template passed in is entirely unaffected
  -    * and is not related in any way to the new node except that they will share the same type.
  -    *
  -    * @return TreeNode
  -    * @deprecated - passing in childName and fqn shuld be redundant.
  -    */
  -   public Node createNode(Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache)
  +   public Node createNode(Object childName, Node parent, Map data)
      {
  -      return createNodeOfType(parent, childName, fqn, parent, data, cache, null);
  +      return createNodeOfType(parent, childName, parent, data);
      }
   
  -   public Node createNode(Object childName, Node parent, Map data, CacheSPI cache)
  +   public Node createNodeOfType(Node template, Object childName, Node parent, Map data)
      {
  -      return createNodeOfType(parent, childName, new Fqn(parent.getFqn(), childName), parent, data, cache, null);
  -   }
  -
  -   /**
  -    * same as above, passing in an explicit version
  -    *
  -    * @deprecated - passing in childName and fqn shuld be redundant.
  -    */
  -   public Node createNodeOfType(Node template, Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache,
  -                                DataVersion version)
  -   {
  -      // TODO: MANIK - not the most elegant - temporary for now.
         if (template instanceof WorkspaceNode)
         {
            Node dataNodeParent = ((WorkspaceNode) parent).getNode();
  @@ -114,14 +73,8 @@
            return createWorkspaceNode(dataNodeParent, workspace);
         }
   
  -      if (parent instanceof NodeSPI)
  -      {
  -         if (template instanceof VersionedNode)
  -            return createDataNode(NodeType.VERSIONED_NODE, childName, fqn, parent, data, false, version, cache);
  -         if (template instanceof UnversionedNode)
  -            return createDataNode(NodeType.UNVERSIONED_NODE, childName, fqn, parent, data, false, null, cache);
  -      }
  -      return null;
  +      // not a workspace node.
  +      return createDataNode(childName, new Fqn(parent.getFqn(), childName), parent, data, false);
      }
   
      public WorkspaceNode createWorkspaceNode(Node dataNode, TransactionWorkspace workspace)
  @@ -129,9 +82,9 @@
         return new WorkspaceNodeImpl((NodeSPI) dataNode, workspace);
      }
   
  -   public NodeSPI createRootDataNode(NodeType type, CacheSPI cache)
  +   public NodeSPI createRootDataNode()
      {
  -      return (NodeSPI) createDataNode(type, null, Fqn.ROOT, null, null, false, null, cache);
  +      return (NodeSPI) createDataNode(null, Fqn.ROOT, null, null, false);
      }
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list