db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/core RequestContext.java
Date Sat, 15 Feb 2003 10:06:48 GMT
arminw      2003/02/15 02:06:48

  Modified:    src/java/org/apache/ojb/broker/cache
                        MetaObjectCacheImpl.java
                        MetaObjectJCSCacheImpl.java ObjectCache.java
                        ObjectCacheDefaultImpl.java
                        ObjectCacheEmptyImpl.java ObjectCacheJCSImpl.java
                        ObjectCachePerBrokerImpl.java
                        PermanentObjectCacheImpl.java
               src/java/org/apache/ojb/otm/core RequestContext.java
  Added:       src/java/org/apache/ojb/broker/cache AbstractMetaCache.java
  Log:
  avoid using of the deprecated Identity
  constructor, add abstract base class for
  MetaCache implementations.
  
  PLEASE check my made changes.
  
  Revision  Changes    Path
  1.4       +10 -100   db-ojb/src/java/org/apache/ojb/broker/cache/MetaObjectCacheImpl.java
  
  Index: MetaObjectCacheImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/MetaObjectCacheImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MetaObjectCacheImpl.java	21 Nov 2002 09:34:18 -0000	1.3
  +++ MetaObjectCacheImpl.java	15 Feb 2003 10:06:48 -0000	1.4
  @@ -73,7 +73,7 @@
    * @author  rzj7l2
    * @version $Id$
    */
  -public class MetaObjectCacheImpl implements ObjectCache
  +public class MetaObjectCacheImpl extends AbstractMetaCache
   {
       private Map cachesByClass = new HashMap();
   
  @@ -97,101 +97,9 @@
        *                     for the given class
        */
       public void setClassCache(Class objectClass, ObjectCache cache)
  -    
  -    {
  -        setClassCache(objectClass.getName(), cache);
  -    }
  -
  -    /**
  -     * Caches the given Object
  -     *
  -     * @param obj  The object to cache
  -     */
  -    public void cache(Object obj)
  -    {
  -        if (obj != null)
  -        {
  -            Identity oid = new Identity(obj);
  -            cache(oid, obj);
  -        }
  -    }
  -
  -    /**
  -     * Caches the given object using the given Identity as key
  -     *
  -     * @param oid  The Identity key
  -     * @param obj  The object o cache
  -     */
  -    public void cache(Identity oid, Object obj)
  -    {
  -        if (oid != null && obj != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                cache.cache(oid, obj);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Looks up the object from the cache
  -     *
  -     * @param oid  The Identity to look up the object for
  -     * @return     The object if found, otherwise null
  -     */
  -    public Object lookup(Identity oid)
  -    {
  -        Object ret = null;
  -        if (oid != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                ret = cache.lookup(oid);
  -            }
  -        }
  -        return ret;
  -    }
   
  -    /**
  -     * Removes the object identified by the given Identity from the cache
  -     *
  -     * @param oid  The identity of the object to remove
  -     */
  -    protected void removeByOID(Identity oid)
  -    {
  -        if (oid != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                cache.remove(oid);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Removes the given object from the cache
  -     *
  -     * @param obj  The object to remove
  -     */
  -    public void remove(Object obj)
       {
  -        if (obj != null)
  -        {
  -            if (obj instanceof Identity)
  -            {
  -                removeByOID((Identity) obj);
  -                return;
  -            }
  -
  -            ObjectCache cache = getCache(obj.getClass());
  -            if (cache != null)
  -            {
  -                cache.remove(obj);
  -            }
  -        }
  +        setClassCache(objectClass.getName(), cache);
       }
   
       /**
  @@ -208,7 +116,6 @@
                   cache.clear();
               }
           }
  -
       }
   
       /**
  @@ -228,7 +135,7 @@
        * @param objectClass  The class to look up the cache for
        * @return             The cache
        */
  -    private ObjectCache getCache(Class objectClass)
  +    private ObjectCache getCachePerClass(Class objectClass)
       {
           ObjectCache cache = (ObjectCache) cachesByClass.get(objectClass.getName());
           if (cache == null)
  @@ -238,13 +145,16 @@
                   //there is a null-cache present => do not cache this class
               }
               else if (!objectClass.equals(Object.class))
  -            
  -                {
  +            {
                   //check for superclasses cache
  -                cache = getCache(objectClass.getSuperclass());
  +                cache = getCachePerClass(objectClass.getSuperclass());
               }
           }
           return cache;
       }
   
  +    protected ObjectCache getCache(Identity oid)
  +    {
  +        return getCachePerClass(oid.getObjectsClass());
  +    }
   }
  
  
  
  1.3       +9 -112    db-ojb/src/java/org/apache/ojb/broker/cache/MetaObjectJCSCacheImpl.java
  
  Index: MetaObjectJCSCacheImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/MetaObjectJCSCacheImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MetaObjectJCSCacheImpl.java	21 Nov 2002 09:33:27 -0000	1.2
  +++ MetaObjectJCSCacheImpl.java	15 Feb 2003 10:06:48 -0000	1.3
  @@ -67,7 +67,7 @@
    * @version $Id$
    */
   
  -public class MetaObjectJCSCacheImpl implements ObjectCache
  +public class MetaObjectJCSCacheImpl extends AbstractMetaCache
   {
       private Map cachesByClass = new HashMap();
   
  @@ -79,81 +79,6 @@
       }
   
       /**
  -     * Caches the given Object
  -     *
  -     * @param obj  The object to cache
  -     */
  -    public void cache(Object obj)
  -    {
  -        if (obj != null)
  -        {
  -            Identity oid = new Identity(obj);
  -            cache(oid, obj);
  -        }
  -    }
  -
  -    /**
  -     * Caches the given object using the given Identity as key
  -     *
  -     * @param oid  The Identity key
  -     * @param obj  The object o cache
  -     */
  -    public void cache(Identity oid, Object obj)
  -    {
  -        if (oid != null && obj != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                cache.cache(oid, obj);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Looks up the object from the cache
  -     *
  -     * @param oid  The Identity to look up the object for
  -     * @return     The object if found, otherwise null
  -     */
  -    public Object lookup(Identity oid)
  -    {
  -        Object ret = null;
  -        if (oid != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                ret = cache.lookup(oid);
  -            }
  -        }
  -        return ret;
  -    }
  -
  -    /**
  -     * Removes the given object from the cache
  -     *
  -     * @param obj  The object to remove
  -     */
  -    public void remove(Object obj)
  -    {
  -        if (obj != null)
  -        {
  -            if (obj instanceof Identity)
  -            {
  -                removeByOID((Identity) obj);
  -                return;
  -            }
  -
  -            ObjectCache cache = getCache(obj.getClass());
  -            if (cache != null)
  -            {
  -                cache.remove(obj);
  -            }
  -        }
  -    }
  -
  -    /**
        * Clears the cache
        */
       public void clear()
  @@ -169,46 +94,13 @@
           }
       }
   
  -   /**
  -     * Removes the object identified by the given Identity from the cache
  -     *
  -     * @param oid  The identity of the object to remove
  -     */
  -    private void removeByOID(Identity oid)
  -    {
  -        if (oid != null)
  -        {
  -            ObjectCache cache = getCache(oid.getObjectsClass());
  -            if (cache != null)
  -            {
  -                cache.remove(oid);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Sets the ObjectCache implementation for the given class name
  -     *
  -     * @param className  The name of the class to cache
  -     * @param cache      The ObjectCache to use for this class and subclasses
  -     */
  -    private void setClassCache(String className, ObjectCache cache)
  -    {
  -        cachesByClass.put(className, cache);
  -    }
  -
  -    private void setClassCache(Class objectClass, ObjectCache cache)
  -    {
  -        setClassCache(objectClass.getName(), cache);
  -    }
  -
       /**
        * Gets the cache for the given class
        *
        * @param objectClass  The class to look up the cache for
        * @return             The cache
        */
  -    private ObjectCache getCache(Class objectClass)
  +    private ObjectCache getCachePerClass(Class objectClass)
       {
           ObjectCache cache = (ObjectCache) cachesByClass.get(objectClass.getName());
           if (cache == null)
  @@ -218,8 +110,13 @@
                * null value, so create a new cache for this classtype
                */
               cache = new ObjectCacheJCSImpl(objectClass.getName());
  -            setClassCache(objectClass, cache);
  +            cachesByClass.put(objectClass.getName(), cache);
           }
           return cache;
  +    }
  +
  +    protected ObjectCache getCache(Identity oid)
  +    {
  +        return getCachePerClass(oid.getObjectsClass());
       }
   }
  
  
  
  1.5       +7 -9      db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCache.java
  
  Index: ObjectCache.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCache.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ObjectCache.java	21 Nov 2002 09:35:07 -0000	1.4
  +++ ObjectCache.java	15 Feb 2003 10:06:48 -0000	1.5
  @@ -79,11 +79,11 @@
   public interface ObjectCache
   {
   
  -    /**
  -     * Make object obj persistent to Objectcache.
  -     * compute objects identity and use it as key for the hashmap
  -     */
  -    public void cache(Object obj) throws ClassNotPersistenceCapableException;
  +//    /**
  +//     * Make object obj persistent to Objectcache.
  +//     * compute objects identity and use it as key for the hashmap
  +//     */
  +//    public void cache(Object obj) throws ClassNotPersistenceCapableException;
   
   
       /**
  @@ -103,12 +103,10 @@
        * removes an Object from the cache.
        * @param obj the Object (or the Identity of the object) to be removed.
        */
  -    public void remove(Object obj);
  +    public void remove(Identity oid);
   
       /**
        * clear the ObjectCache.
        */
       public void clear();
  -
  -
   }
  
  
  
  1.7       +10 -59    db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
  
  Index: ObjectCacheDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ObjectCacheDefaultImpl.java	13 Feb 2003 19:19:21 -0000	1.6
  +++ ObjectCacheDefaultImpl.java	15 Feb 2003 10:06:48 -0000	1.7
  @@ -54,16 +54,13 @@
    * <http://www.apache.org/>.
    */
   
  -import java.lang.ref.SoftReference;
  -import java.util.Hashtable;
  -
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  +import java.lang.ref.SoftReference;
  +import java.util.Hashtable;
  +
   /**
    * The ObjectCache stores all Objects loaded by the PersistenceBroker from a DB.
    * When the PersistenceBroker tries to get an Object by its Primary key values
  @@ -85,18 +82,15 @@
    */
   public class ObjectCacheDefaultImpl implements ObjectCache
   {
  -
       /**
        * the hashtable holding all cached object
        */
       protected Hashtable objectTable = null;
   
  -
       private long hitCount = 0;
       private long failCount = 0;
       private long gcCount = 0;
   
  -
       /**
        * public Default Constructor
        */
  @@ -106,43 +100,17 @@
       }
   
       /**
  -     * Get the default Broker
  -     * @return PersistenceBroker
  -     */
  -    private PersistenceBroker getBroker()
  -    {
  -        return PersistenceBrokerFactory.defaultPersistenceBroker();
  -    }
  -    
  -    /**
  -     * Make object obj persistent to Objectcache.
  -     * compute objects identity and use it as key for the hashmap
  -     */
  -    public void cache(Object obj) throws ClassNotPersistenceCapableException
  -    {
  -        Identity oid = new Identity(obj, getBroker());
  -        this.cache(oid, obj);
  -    }
  -
  -    /**
  -     *
  -     * clear ObjectCache. I.e. remove all entries for classes and objects.
  -     *
  +     * Clear ObjectCache. I.e. remove all entries for classes and objects.
        */
       public void clear()
       {
           objectTable.clear();
       }
   
  -
       /**
  -     *
  -     * makes object persistent to the Objectcache.
  -     *
  +     * Makes object persistent to the Objectcache.
        * I'm using soft-references to allow gc reclaim unused objects
  -     *
        * even if they are still cached.
  -     *
        */
       public void cache(Identity oid, Object obj)
       {
  @@ -153,13 +121,9 @@
           }
       }
   
  -
       /**
  -     *
        * Lookup object with Identity oid in objectTable.
  -     *
  -     * returns null if no matching id is found
  -     *
  +     * Returns null if no matching id is found
        */
       public Object lookup(Identity oid)
       {
  @@ -183,24 +147,13 @@
       }
   
       /**
  -     *
  -     * removes an Object from the cache.
  -     *
  +     * Removes an Object from the cache.
        */
  -    public void remove(Object obj)
  +    public void remove(Identity oid)
       {
  -        if (obj != null)
  +        if (oid != null)
           {
  -            String oidString = null;
  -            if (obj instanceof Identity)
  -            {
  -             	oidString = obj.toString();   
  -            }
  -            else 
  -            {
  -                oidString = new Identity(obj,getBroker()).toString();
  -            }
  -            objectTable.remove(oidString);
  +            objectTable.remove(oid.toString());
           }
       }
   
  @@ -212,6 +165,4 @@
           logger.info("failures:  " + failCount);
           logger.info("reclaimed: " + gcCount);
       }
  -
  -
   }
  
  
  
  1.4       +36 -38    db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheEmptyImpl.java
  
  Index: ObjectCacheEmptyImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheEmptyImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ObjectCacheEmptyImpl.java	21 Nov 2002 09:36:26 -0000	1.3
  +++ ObjectCacheEmptyImpl.java	15 Feb 2003 10:06:48 -0000	1.4
  @@ -1,4 +1,5 @@
   package org.apache.ojb.broker.cache;
  +
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -52,49 +53,46 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
   
   /**
  - * this implementation of ObjectCache does not do anything.
  + * This implementation of ObjectCache does not do anything.
    * It can be used in situations where caching is not possible.
  - * 
  + *
    * @author Thomas Mahler
    * @version $Id$
  - * 
  + *
    */
  -public class ObjectCacheEmptyImpl implements ObjectCache {
  -
  -  /**
  -   * @see org.apache.ojb.broker.cache.ObjectCache#cache(Object)
  -   */
  -  public void cache(Object arg0) throws ClassNotPersistenceCapableException {
  -  }
  -
  -  /**
  -   * @see org.apache.ojb.broker.cache.ObjectCache#cache(Identity, Object)
  -   */
  -  public void cache(Identity arg0, Object arg1) {
  -  }
  -
  -  /**
  -   * @see org.apache.ojb.broker.cache.ObjectCache#lookup(Identity)
  -   */
  -  public Object lookup(Identity arg0) {
  -    return null;
  -  }
  -
  -  /**
  -   * @see org.apache.ojb.broker.cache.ObjectCache#remove(Object)
  -   */
  -  public void remove(Object arg0) {
  -  }
  -
  -  /**
  -   * @see org.apache.ojb.broker.cache.ObjectCache#clear()
  -   */
  -  public void clear() {
  -  }
  -
  +public class ObjectCacheEmptyImpl implements ObjectCache
  +{
  +    /**
  +     * @see org.apache.ojb.broker.cache.ObjectCache#cache(Identity, Object)
  +     */
  +    public void cache(Identity arg0, Object arg1)
  +    {
  +    }
  +
  +    /**
  +     * @see org.apache.ojb.broker.cache.ObjectCache#lookup(Identity)
  +     */
  +    public Object lookup(Identity arg0)
  +    {
  +        return null;
  +    }
  +
  +    /**
  +     * @see org.apache.ojb.broker.cache.ObjectCache#remove(Object)
  +     */
  +    public void remove(Identity oid)
  +    {
  +    }
  +
  +    /**
  +     * @see org.apache.ojb.broker.cache.ObjectCache#clear()
  +     */
  +    public void clear()
  +    {
  +    }
   }
   
  
  
  
  1.5       +3 -22     db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheJCSImpl.java
  
  Index: ObjectCacheJCSImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheJCSImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ObjectCacheJCSImpl.java	21 Nov 2002 09:37:29 -0000	1.4
  +++ ObjectCacheJCSImpl.java	15 Feb 2003 10:06:48 -0000	1.5
  @@ -95,24 +95,6 @@
       }
   
       /**
  -     * Make object obj persistent to Objectcache.
  -     * compute objects identity and use it as key for the hashmap
  -     */
  -    public void cache(Object obj) throws ClassNotPersistenceCapableException
  -    {
  -        ensureOpen();
  -        try
  -        {
  -            Identity oid = new Identity(obj);
  -            m_region.put(oid, obj);
  -        }
  -        catch (org.apache.jcs.access.exception.CacheException e)
  -        {
  -            throw new RuntimeCacheException(e.getMessage());
  -        }
  -    }
  -
  -    /**
        * makes object obj persistent to the Objectcache under the key oid.
        */
       public void cache(Identity oid, Object obj)
  @@ -142,12 +124,12 @@
        * removes an Object from the cache.
        * @param obj the Object (or the Identity of the object) to be removed.
        */
  -    public void remove(Object obj)
  +    public void remove(Identity oid)
       {
           ensureOpen();
           try
           {
  -            m_region.remove(obj);
  +            m_region.remove(oid);
           }
           catch (CacheException e)
           {
  @@ -182,5 +164,4 @@
               }
           }
       }
  -
   }
  
  
  
  1.2       +23 -51    db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCachePerBrokerImpl.java
  
  Index: ObjectCachePerBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCachePerBrokerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectCachePerBrokerImpl.java	9 Feb 2003 20:13:42 -0000	1.1
  +++ ObjectCachePerBrokerImpl.java	15 Feb 2003 10:06:48 -0000	1.2
  @@ -65,79 +65,51 @@
    * This cache implementation allows to have dedicated caches per broker.
    * All calls are delegated to the cache associated with the currentBroker.
    * The Broker lookup is done with the PersistenceBrokerThreadMapping.
  + *
  + *
    * @author Thomas Mahler
    */
  -public class ObjectCachePerBrokerImpl implements ObjectCache
  +public class ObjectCachePerBrokerImpl extends AbstractMetaCache
   {
   	/**
   	 * the map holding all broker caches
   	 */
   	private HashMap brokerMap;
  -	
  +
  +    /**
  +     * Constructor for ObjectCachePerBrokerImpl.
  +     */
  +    public ObjectCachePerBrokerImpl()
  +    {
  +        super();
  +        brokerMap = new HashMap();
  +    }
  +
   	/**
   	 * lookup the currently active broker from the PersistenceBrokerThreadMapping
   	 */
  -	protected synchronized ObjectCache getCacheForCurrentBroker()
  +	protected synchronized ObjectCache getCache(Identity oid)
   	{
  -		PersistenceBroker currentBroker = PersistenceBrokerThreadMapping.currentDefaultPersistenceBroker();
		
  -		PBKey key = currentBroker.getPBKey();
  -		
  -		ObjectCache result = (ObjectCache) brokerMap.get(key);
  +		PersistenceBroker currentBroker = PersistenceBrokerThreadMapping.currentDefaultPersistenceBroker();
  +        /*
  +        TODO: Don't know if my changes make sense, please check my code.
  +        I think this cache doesn't work as desired, because currentDefaultPersistenceBroker()
  +        is not 'threadsafe'.
  +        */
  +		ObjectCache result = (ObjectCache) brokerMap.get(currentBroker);
   		if (result == null)
   		{
   			result = new ObjectCacheDefaultImpl();
  -			brokerMap.put(key, result);	
  +			brokerMap.put(currentBroker, result);
   		}
   		return result;
   	}
  -	
  -    /**
  -     * Constructor for ObjectCachePerBrokerImpl.
  -     */
  -    public ObjectCachePerBrokerImpl()
  -    {
  -        super();
  -        brokerMap = new HashMap();
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.cache.ObjectCache#cache(Object)
  -     */
  -    public void cache(Object obj) throws ClassNotPersistenceCapableException
  -    {
  -    	getCacheForCurrentBroker().cache(obj);
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.cache.ObjectCache#cache(Identity, Object)
  -     */
  -    public void cache(Identity oid, Object obj)
  -    {
  -    	getCacheForCurrentBroker().cache(oid, obj);
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.cache.ObjectCache#lookup(Identity)
  -     */
  -    public Object lookup(Identity oid)
  -    {
  -        return getCacheForCurrentBroker().lookup(oid);
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.cache.ObjectCache#remove(Object)
  -     */
  -    public void remove(Object obj)
  -    {
  -    	getCacheForCurrentBroker().remove(obj);
  -    }
   
       /**
        * @see org.apache.ojb.broker.cache.ObjectCache#clear()
        */
       public void clear()
       {
  -    	getCacheForCurrentBroker().clear();
  +    	brokerMap.clear();
       }
  -
   }
  
  
  
  1.4       +6 -34     db-ojb/src/java/org/apache/ojb/broker/cache/PermanentObjectCacheImpl.java
  
  Index: PermanentObjectCacheImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/PermanentObjectCacheImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PermanentObjectCacheImpl.java	21 Nov 2002 09:38:14 -0000	1.3
  +++ PermanentObjectCacheImpl.java	15 Feb 2003 10:06:48 -0000	1.4
  @@ -74,28 +74,11 @@
    */
   public class PermanentObjectCacheImpl implements ObjectCache
   {
  -
       /**
        * holds all cached object identities
        */
       protected Map cachedObjects = new HashMap();
   
  -
  -    /**
  -     * Caches the given object
  -     *
  -     * @param obj                                   The object to cache
  -     */
  -    public void cache(Object obj)
  -    {
  -        if (obj != null)
  -        {
  -            Identity oid = new Identity(obj);
  -            cache(oid, obj);
  -        }
  -    }
  -
  -
       /**
        * Clears the cache
        */
  @@ -104,12 +87,11 @@
           cachedObjects.clear();
       }
   
  -
       /**
        * Caches the given object
        *
  -     * @param oid                                   The identity of the given object to
cache
  -     * @param obj                                   The object to cache
  +     * @param oid  The identity of the given object to cache
  +     * @param obj  The object to cache
        */
       public void cache(Identity oid, Object obj)
       {
  @@ -119,7 +101,6 @@
           }
       }
   
  -
       /**
        * Looks up the cache for an object that matches the given identity
        *
  @@ -132,25 +113,16 @@
           return obj;
       }
   
  -
       /**
        * Description of the Method
        *
        * @param obj  Description of Parameter
        */
  -    public void remove(Object obj)
  +    public void remove(Identity oid)
       {
  -        if (obj != null)
  +        if (oid != null)
           {
  -        	if (obj instanceof Identity)
  -        	{
  -        	 	cachedObjects.remove(obj.toString());   
  -        	}
  -        	else
  -        	{	
  -        	    cachedObjects.remove(new Identity(obj).toString());
  -        	}
  +            cachedObjects.remove(oid.toString());
           }
  -        
       }
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/cache/AbstractMetaCache.java
  
  Index: AbstractMetaCache.java
  ===================================================================
  package org.apache.ojb.broker.cache;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.broker.Identity;
  
  /**
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: AbstractMetaCache.java,v 1.1 2003/02/15 10:06:48 arminw Exp $
   */
  public abstract class AbstractMetaCache implements ObjectCache
  {
  
      protected abstract ObjectCache getCache(Identity oid);
  
      /**
       * Caches the given object using the given Identity as key
       *
       * @param oid  The Identity key
       * @param obj  The object o cache
       */
      public void cache(Identity oid, Object obj)
      {
          if (oid != null && obj != null)
          {
              ObjectCache cache = getCache(oid);
              if (cache != null)
              {
                  cache.cache(oid, obj);
              }
          }
      }
  
      /**
       * Looks up the object from the cache
       *
       * @param oid  The Identity to look up the object for
       * @return     The object if found, otherwise null
       */
      public Object lookup(Identity oid)
      {
          Object ret = null;
          if (oid != null)
          {
              ObjectCache cache = getCache(oid);
              if (cache != null)
              {
                  ret = cache.lookup(oid);
              }
          }
          return ret;
      }
  
      /**
       * Removes the given object from the cache
       *
       * @param obj  The object to remove
       */
      public void remove(Identity oid)
      {
          if (oid == null) return;
  
          ObjectCache cache = getCache(oid);
          if (cache != null)
          {
              cache.remove(oid);
          }
      }
  }
  
  
  
  1.2       +18 -29    db-ojb/src/java/org/apache/ojb/otm/core/RequestContext.java
  
  Index: RequestContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/RequestContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestContext.java	1 Feb 2003 18:39:56 -0000	1.1
  +++ RequestContext.java	15 Feb 2003 10:06:48 -0000	1.2
  @@ -65,9 +65,9 @@
    *
    * Establishes the context for an OTM object request from the kernel. This is used to pass
down
    * contextual information to OTM core, when accessed through the ObjectCache of the kernel.
  - * 
  + *
    * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
  - * 
  + *
    */
   public class RequestContext
       implements ObjectCache
  @@ -75,20 +75,20 @@
       private BaseConnection _connection;
       private int _requestedLockType;
       private boolean _inUse;
  -    
  +
       public RequestContext (BaseConnection connection)
       {
           _connection = connection;
           _inUse = false;
       }
  -    
  -    
  +
  +
   	/**
  -     * 
  +     *
   	 * Returns the connection.
  -     * 
  +     *
   	 * @return the connection in context
  -     * 
  +     *
   	 */
   	public BaseConnection getConnection ()
   	{
  @@ -96,21 +96,21 @@
   	}
   
   	/**
  -     * 
  +     *
   	 * Returns the requestedLockType.
  -     * 
  +     *
   	 * @return the requested Lock type
  -     * 
  +     *
   	 */
   	public int getRequestedLockType ()
   	{
   		return _requestedLockType;
   	}
  -    
  +
       /**
  -     * 
  +     *
        * Establish that the RequestContext is in use.
  -     * 
  +     *
        * @param requestedLockType The requestedLockType to set
        */
       public void establishContext (int requestedLockType)
  @@ -118,7 +118,7 @@
           _requestedLockType = requestedLockType;
           _inUse = true;
       }
  -    
  +
       public void releaseContext ()
       {
           _inUse = false;
  @@ -128,8 +128,8 @@
       {
           return _inUse;
       }
  -    
  -    
  +
  +
       //////////////////////////////////////////////
       // ObjectCache protocol
       //////////////////////////////////////////////
  @@ -152,16 +152,6 @@
   	}
   
   	/**
  -	 * @see org.apache.ojb.broker.cache.ObjectCache#cache(Object)
  -	 */
  -	public void cache (Object obj) throws ClassNotPersistenceCapableException
  -	{
  -        OTMKit kit = OTMKit.getInstance();
  -        Identity oid = kit.getIdentity(obj);
  -        cache(oid, obj);
  -	}
  -
  -	/**
   	 * @see org.apache.ojb.broker.cache.ObjectCache#clear()
   	 */
   	public void clear ()
  @@ -181,11 +171,10 @@
   	/**
   	 * @see org.apache.ojb.broker.cache.ObjectCache#remove(Object)
   	 */
  -	public void remove (Object obj)
  +	public void remove (Identity oid)
   	{
           // xxx rrajah: Do I need to support this???
           throw new UnsupportedOperationException(
               "TODO rrajah: Do I need to support RequestContext.remove");
   	}
  -
   }
  
  
  

Mime
View raw message