[jbosscache-commits] JBoss Cache SVN: r4489 - in pojo/trunk/src: main/java/org/jboss/cache/pojo/impl and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Sep 20 00:28:36 EDT 2007


Author: jason.greene at jboss.com
Date: 2007-09-20 00:28:36 -0400 (Thu, 20 Sep 2007)
New Revision: 4489

Modified:
   pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
   pojo/trunk/src/test/java/org/jboss/cache/pojo/NewLocalTest.java
Log:
PCACHE-2 - Add FQN based versions to API


Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java	2007-09-19 17:05:59 UTC (rev 4488)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java	2007-09-20 04:28:36 UTC (rev 4489)
@@ -11,6 +11,7 @@
 import java.util.regex.Pattern;
 
 import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
 import org.jboss.cache.pojo.notification.annotation.PojoCacheListener;
 
 /**
@@ -56,6 +57,35 @@
    Object attach(String id, Object pojo) throws PojoCacheException;
 
    /**
+    * <p>Attach a POJO into PojoCache. It will also recursively put any
+    * sub-POJO into the cache system. A POJO can be the following and have the
+    * consqeuences when attached:</p> <p/> <li>it is Replicable, that is, it
+    * has been annotated with {@link @org.jboss.cache.pojo.annotation.Replicable} annotation (or via XML),
+    * and has
+    * been "instrumented" either compile- or load-time. The POJO will be mapped
+    * recursively to the system and fine-grained replication will be
+    * performed.</li> <li>It is Serializable. The POJO will still be stored in
+    * the cache system. However, it is treated as an "opaque" object per se.
+    * That is, the POJO will neither be intercepted
+    * (for fine-grained operation) or object relantionship will be
+    * maintained.</li>
+    * <li>Neither of above. In this case, a user can specify whether it wants
+    * this POJO to be stored (e.g., replicated or persistent). If not, a
+    * PojoCacheException will be thrown.</li>
+    *
+    * @param id   An id String to identify the object in the cache. To promote
+    *             concurrency, we recommend the use of hierarchical String separating by a
+    *             designated separator. Default is "/" but it can be set differently via a
+    *             System property, jbosscache.separator in the future release. E.g., "ben",
+    *             or "student/joe", etc.
+    * @param pojo object to be inerted into the cache. If null, it will nullify
+    *             the fqn node.
+    * @return Existing POJO or null if there is none.
+    * @throws PojoCacheException Throws if there is an error related to the cache operation.
+    */
+   Object attach(Fqn<?> id, Object pojo) throws PojoCacheException;
+
+   /**
     * Remove POJO object from the cache.
     *
     * @param id Is string that associates with this node.
@@ -65,6 +95,15 @@
    Object detach(String id) throws PojoCacheException;
 
    /**
+    * Remove POJO object from the cache.
+    *
+    * @param id location of the object to remove
+    * @return Original value object from this node.
+    * @throws PojoCacheException Throws if there is an error related to the cache operation.
+    */
+   Object detach(Fqn<?> id) throws PojoCacheException;
+
+   /**
     * Return the POJO id that is associated with PojoCache. Note that if a POJO has not yet
     * attached to the cache system, it will simply return null.
     *
@@ -84,6 +123,16 @@
    Object find(String id) throws PojoCacheException;
 
    /**
+    * Retrieve POJO from the cache system. Return null if object does not exist in the cache.
+    * Note that this operation is fast if there is already a POJO instance attached to the cache.
+    *
+    * @param id that associates with this node.
+    * @return Current content value. Null if does not exist.
+    * @throws PojoCacheException Throws if there is an error related to the cache operation.
+    */
+   Object find(Fqn<?> id) throws PojoCacheException;
+
+   /**
     * Query all managed POJO objects under the id recursively. Note that this will not return
     * the sub-object POJOs, e.g., if <em>Person</em> has a sub-object of <em>Address</em>, it
     * won't return <em>Address</em> pojo. Also note also that this operation is not thread-safe
@@ -94,9 +143,22 @@
     * @return Map of all POJOs found with (id, POJO) pair. Return size of 0, if not found.
     * @throws PojoCacheException Throws if there is an error related to the cache operation.
     */
-   Map findAll(String id) throws PojoCacheException;
+   Map<Fqn<?>, Object> findAll(String id) throws PojoCacheException;
 
    /**
+    * Query all managed POJO objects under the id recursively. Note that this will not return
+    * the sub-object POJOs, e.g., if <em>Person</em> has a sub-object of <em>Address</em>, it
+    * won't return <em>Address</em> pojo. Also note also that this operation is not thread-safe
+    * now. In addition, it assumes that once a POJO is found with a id, no more POJO is stored
+    * under the children of the id. That is, we don't mix the id with different POJOs.
+    *
+    * @param id The starting place to find all POJOs.
+    * @return Map of all POJOs found with (id, POJO) pair. Return size of 0, if not found.
+    * @throws PojoCacheException Throws if there is an error related to the cache operation.
+    */
+   Map<Fqn<?>, Object> findAll(Fqn<?> id) throws PojoCacheException;
+
+   /**
     * Lifecycle method to start PojoCache.
     *
     * @throws PojoCacheException

Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java	2007-09-19 17:05:59 UTC (rev 4488)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java	2007-09-20 04:28:36 UTC (rev 4489)
@@ -27,7 +27,6 @@
 import org.jboss.cache.pojo.annotation.Attach;
 import org.jboss.cache.pojo.annotation.Detach;
 import org.jboss.cache.pojo.annotation.Find;
-import org.jboss.cache.pojo.notification.annotation.PojoCacheListener;
 
 /**
  * Implementation class for PojoCache interface
@@ -73,7 +72,7 @@
    {
       try
       {
-         cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(config, toStart);
+         cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(config, toStart);
       }
       catch (Exception e)
       {
@@ -83,7 +82,7 @@
       delegate_ = new PojoCacheDelegate(this);
    }
 
-   public CacheSPI getCacheSPI()
+   public CacheSPI<Object, Object> getCacheSPI()
    {
       return cache;
    }
@@ -94,7 +93,7 @@
    }
 
    @Attach
-   public Object attach(Fqn id, Object pojo) throws PojoCacheException
+   public Object attach(Fqn<?> id, Object pojo) throws PojoCacheException
    {
       try
       {
@@ -108,7 +107,7 @@
    }
 
    @Attach
-   public Object attach(Fqn id, Object pojo, String field) throws PojoCacheException
+   public Object attach(Fqn<?> id, Object pojo, String field) throws PojoCacheException
    {
       try
       {
@@ -124,7 +123,7 @@
    /**
     * This public API is called from internal package only.
     */
-   public Object putObject(Fqn id, Object pojo, String field)
+   public Object putObject(Fqn<?> id, Object pojo, String field)
            throws CacheException
    {
       Object obj = null;
@@ -143,7 +142,7 @@
    }
 
    @Detach
-   public Object detach(Fqn id, String field) throws PojoCacheException
+   public Object detach(Fqn<?> id, String field) throws PojoCacheException
    {
       try
       {
@@ -159,12 +158,12 @@
       }
    }
 
-   public Object detach(Fqn id) throws PojoCacheException
+   public Object detach(Fqn<?> id) throws PojoCacheException
    {
       return detach(id, null);
    }
 
-   public Object removeObject(Fqn id, String field) throws CacheException
+   public Object removeObject(Fqn<?> id, String field) throws CacheException
    {
       delegate_.setBulkRemove(false);
       return delegate_.removeObject(id, field);
@@ -181,7 +180,7 @@
    }
 
    @Find
-   public Object find(Fqn id) throws PojoCacheException
+   public Object find(Fqn<?> id) throws PojoCacheException
    {
       try
       {
@@ -193,24 +192,24 @@
       }
    }
 
-   public Object getObject(Fqn id) throws CacheException
+   public Object getObject(Fqn<?> id) throws CacheException
    {
       return getObject(id, null);
    }
 
-   public Object getObject(Fqn id, String field) throws CacheException
+   public Object getObject(Fqn<?> id, String field) throws CacheException
    {
       return delegate_.getObject(id, field);
    }
 
 
-   public Map findAll(String id) throws PojoCacheException
+   public Map<Fqn<?>, Object> findAll(String id) throws PojoCacheException
    {
       return findAll(Fqn.fromString(id));
    }
 
    @Find
-   public Map findAll(Fqn id) throws PojoCacheException
+   public Map<Fqn<?>, Object> findAll(Fqn<?> id) throws PojoCacheException
    {
       // Should produce "/"
       if (id == null) id = Fqn.ROOT;
@@ -320,22 +319,6 @@
    }
 
    /**
-    * Used by internal implementation. Not for general public.
-    */
-   public Object _evictObject(Fqn fqn) throws CacheException
-   {
-      boolean evict = true;
-      boolean removeCacheInterceptor = false;
-
-      // Configurable option to see if we want to remove the cache interceptor when the pojo is
-      // evicted.
-      //      if(detachPojoWhenEvicted_) removeCacheInterceptor = true;
-      delegate_.setBulkRemove(false);
-      //      return delegate_._removeObject(fqn, removeCacheInterceptor);
-      return null;
-   }
-
-   /**
     * Obtain a cache aop type for user to traverse the defined "primitive" types in aop.
     * Note that this is not a synchronized call now for speed optimization.
     *

Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/NewLocalTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/NewLocalTest.java	2007-09-19 17:05:59 UTC (rev 4488)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/NewLocalTest.java	2007-09-20 04:28:36 UTC (rev 4489)
@@ -211,7 +211,7 @@
       map = cache_.findAll("/");
       assertEquals("Objects size should be ", 2, map.size());
 
-      map = cache_.findAll(null); // should everything.
+      map = cache_.findAll((String)null); // should everything.
       assertEquals("Objects size should be ", 2, map.size());
    }
 }




More information about the jbosscache-commits mailing list