[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/collection ...

Ben Wang bwang at jboss.com
Tue Sep 5 02:11:25 EDT 2006


  User: bwang   
  Date: 06/09/05 02:11:25

  Modified:    src-50/org/jboss/cache/pojo/collection   
                        CachedListImpl.java CachedMapImpl.java
                        CachedSetImpl.java
  Log:
  First cuto of the using 2.0 Cache API
  
  Revision  Changes    Path
  1.9       +10 -6     JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CachedListImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- CachedListImpl.java	2 Aug 2006 15:40:24 -0000	1.8
  +++ CachedListImpl.java	5 Sep 2006 06:11:25 -0000	1.9
  @@ -8,8 +8,11 @@
   
   import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Node;
   import org.jboss.cache.pojo.util.AopUtil;
   import org.jboss.cache.pojo.util.Null;
  +import org.jboss.cache.pojo.util.CacheApiUtil;
   import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.impl.PojoCacheImpl;
   import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
  @@ -20,6 +23,7 @@
   import java.util.ListIterator;
   import java.util.Map;
   import java.util.NoSuchElementException;
  +import java.util.Collection;
   
   /**
    * List implementation that uses cache as a backend store.
  @@ -32,14 +36,14 @@
   
   //   protected static final Log log_ = LogFactory.getLog(CachedListImpl.class);
      @SuppressWarnings({"CanBeFinal"})
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private PojoCacheImpl pCache_;
      private AbstractCollectionInterceptor interceptor_;
   
      public CachedListImpl(PojoCacheImpl cache, AbstractCollectionInterceptor interceptor)
      {
         pCache_ = cache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         interceptor_ = interceptor;
      }
   
  @@ -49,11 +53,11 @@
      }
   
      // implementation of the java.util.List interface
  -   private DataNode getNode()
  +   private Node getNode()
      {
         try
         {
  -         return cache_._get(getFqn());
  +         return CacheApiUtil.getDataNode(cache_, getFqn());
         } catch (Exception e)
         {
            throw new RuntimeException(e);
  @@ -87,13 +91,13 @@
   
      public int size()
      {
  -      DataNode node = getNode();
  +      Node node = getNode();
         if (node == null)
         {
            return 0;
         }
   
  -      Map children = node.getChildren();
  +      Collection<Node> children = node.getChildren();
         return children == null ? 0 : children.size();
      }
   
  
  
  
  1.12      +23 -25    JBossCache/src-50/org/jboss/cache/pojo/collection/CachedMapImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CachedMapImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedMapImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- CachedMapImpl.java	2 Aug 2006 15:40:24 -0000	1.11
  +++ CachedMapImpl.java	5 Sep 2006 06:11:25 -0000	1.12
  @@ -9,8 +9,10 @@
   import org.jboss.cache.CacheException;
   import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Node;
   import org.jboss.cache.pojo.util.Null;
  -import org.jboss.cache.pojo.PojoTreeCache;
  +import org.jboss.cache.pojo.util.CacheApiUtil;
   import org.jboss.cache.pojo.annotation.Reentrant;
   import org.jboss.cache.pojo.impl.PojoCacheImpl;
   import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
  @@ -40,13 +42,13 @@
   //   protected static final Log log_ = LogFactory.getLog(CachedMapImpl.class);
   
      private PojoCacheImpl pCache_;
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private AbstractCollectionInterceptor interceptor_;
   
      public CachedMapImpl(PojoCacheImpl pCache, AbstractCollectionInterceptor interceptor)
      {
         pCache_ = pCache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         interceptor_ = interceptor;
   
      }
  @@ -68,11 +70,11 @@
   
      // implementation of the java.util.Map interface
   
  -   private DataNode getNode()
  +   private Node getNode()
      {
         try
         {
  -         return cache_._get(getFqn());
  +         return CacheApiUtil.getDataNode(cache_, getFqn());
         } catch (Exception e)
         {
            throw new RuntimeException(e);
  @@ -133,13 +135,13 @@
   
      public int size()
      {
  -      DataNode node = getNode();
  +      Node node = getNode();
         if (node == null)
         {
            return 0;
         }
   
  -      Map children = node.getChildren();
  +      Map children = node.getData();
         return children == null ? 0 : children.size();
      }
   
  @@ -150,7 +152,7 @@
   
      public boolean containsKey(Object object)
      {
  -      Map children = getNode().getChildren();
  +      Map children = getNode().getData();
         return children != null && children.containsKey(Null.toNullKeyObject(object));
      }
   
  @@ -168,17 +170,17 @@
   
            public int size()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               return children == null ? 0 : children.size();
            }
   
            public Iterator iterator()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               final Iterator i =
                       children == null
                               ? Collections.EMPTY_LIST.iterator()
  -                            : children.keySet().iterator();
  +                            : children.iterator();
               return new Iterator()
               {
                  Object lastKey; // for remove
  @@ -190,7 +192,7 @@
   
                  public Object next()
                  {
  -                  return new Entry(lastKey = i.next());
  +                  return new Entry(lastKey = ((Node)i.next()).getFqn().getLast());
                  }
   
                  public void remove()
  @@ -211,7 +213,7 @@
   
            public int size()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               return children == null ? 0 : children.size();
            }
   
  @@ -222,11 +224,11 @@
   
            public Iterator iterator()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               final Iterator i =
                       children == null
                               ? Collections.EMPTY_LIST.iterator()
  -                            : children.keySet().iterator();
  +                            : children.iterator();
   
               return new Iterator()
               {
  @@ -241,12 +243,8 @@
                  {
                     try
                     {
  -                     lastKey = i.next();
  -                     return Null.toNullValue(pCache_.getObject(constructFqn(getFqn(), lastKey)));
  -                  }
  -                  catch (NotSerializableException e)
  -                  {
  -                     throw new RuntimeException(e);
  +                     lastKey = ((Node)i.next()).getFqn().getLast();
  +                     return Null.toNullValue(pCache_.getObject((Fqn)lastKey));
                     }
                     catch (CacheException e)
                     {
  @@ -275,17 +273,17 @@
   
            public int size()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               return children == null ? 0 : children.size();
            }
   
            public Iterator iterator()
            {
  -            Map children = getNode().getChildren();
  +            Collection<Node> children = getNode().getChildren();
               final Iterator i =
                       children == null
                               ? Collections.EMPTY_LIST.iterator()
  -                            : children.keySet().iterator();
  +                            : children.iterator();
   
               return new Iterator()
               {
  @@ -298,7 +296,7 @@
   
                  public Object next()
                  {
  -                  lastKey = i.next();
  +                  lastKey = ((Node)i.next()).getFqn().getLast();
                     return Null.toNullKeyValue(lastKey);
   
                  }
  
  
  
  1.8       +25 -9     JBossCache/src-50/org/jboss/cache/pojo/collection/CachedSetImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CachedSetImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedSetImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- CachedSetImpl.java	2 Aug 2006 15:40:24 -0000	1.7
  +++ CachedSetImpl.java	5 Sep 2006 06:11:25 -0000	1.8
  @@ -9,8 +9,11 @@
   import org.jboss.cache.CacheException;
   import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Node;
   import org.jboss.cache.pojo.util.AopUtil;
   import org.jboss.cache.pojo.util.Null;
  +import org.jboss.cache.pojo.util.CacheApiUtil;
   import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.annotation.Reentrant;
   import org.jboss.cache.pojo.impl.PojoCacheImpl;
  @@ -22,6 +25,7 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  +import java.util.LinkedList;
   
   /**
    * Set that uses cache as a underlying backend store
  @@ -35,22 +39,22 @@
   {
   //   protected static final Log log_=LogFactory.getLog(CachedSetImpl.class);
   
  -   private PojoTreeCache cache_;
      private PojoCacheImpl pCache_;
  +   private CacheSPI cache_;
      private AbstractCollectionInterceptor interceptor_;
   
      public CachedSetImpl(PojoCacheImpl cache, AbstractCollectionInterceptor interceptor)
      {
         pCache_ = cache;
  -      this.cache_ = (PojoTreeCache)pCache_.getCache();
  +      this.cache_ = (CacheSPI)pCache_.getCache();
         this.interceptor_ = interceptor;
      }
   
  -   private DataNode getNode()
  +   private Node getNode()
      {
         try
         {
  -         return cache_._get(getFqn());
  +         return CacheApiUtil.getDataNode(cache_, getFqn());
         } catch (Exception e)
         {
            throw new RuntimeException(e);
  @@ -66,7 +70,14 @@
      // implementation of the java.util.Set interface
      public int size()
      {
  -      return keySet().size();
  +      Node node = getNode();
  +      if (node == null)
  +      {
  +         return 0;
  +      }
  +
  +      Collection<Node> children = node.getChildren();
  +      return children == null ? 0 : children.size();
      }
   
      public Iterator iterator()
  @@ -170,16 +181,21 @@
   
      private Collection keySet()
      {
  -      DataNode node = getNode();
  +      Node node = getNode();
   
  +      // TODO Not efficient here!!
         if (node != null)
         {
  -         Map children = node.getChildren();
  +         Collection<Node> children = node.getChildren();
  +         if (children == null) return null;
   
  -         if (children != null)
  +         LinkedList keys = new LinkedList();
  +         for(Node n : children)
            {
  -            return children.keySet();
  +            keys.add(n.getFqn().getLast());
            }
  +
  +         return keys;
         }
   
         return Collections.EMPTY_SET;
  
  
  



More information about the jboss-cvs-commits mailing list