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/broker/accesslayer RsIterator.java
Date Wed, 19 Feb 2003 22:10:18 GMT
arminw      2003/02/19 14:10:18

  Modified:    src/java/org/apache/ojb/soda QueryImpl.java
                        ObjectSetImpl.java ObjectContainerImpl.java
               src/java/org/apache/ojb/broker
                        PersistenceBrokerListener.java
                        PersistenceBroker.java
               src/java/org/apache/ojb/broker/ta
                        PersistenceBrokerFactoryIF.java
                        PersistenceBrokerFactoryDefaultImpl.java
               src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
                        PersistenceBrokerAbstractImpl.java
                        DelegatingPersistenceBroker.java
               src/java/org/apache/ojb/broker/server
                        PersistenceBrokerClient.java
                        PersistenceBrokerBean.java
               src/java/org/apache/ojb/broker/cache
                        ObjectCachePerBrokerImpl.java
                        ObjectCacheJCSImpl.java ObjectCacheFactory.java
                        ObjectCacheEmptyImpl.java
                        ObjectCacheDefaultImpl.java
                        MetaObjectJCSCacheImpl.java
                        MetaObjectCacheImpl.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
  Log:
  - improve cache package, now every PB instance
  get its own ObjectCache instance (no singleton)
  as well as the other services.
  
  - add method serviceObjectCache to PB-api
  
  - rename ObjectCacheFactory#getObjectCache to
  createObjectCache
  
  - move PB thread mapping completely to PBF
  
  - improve SODA query not using defaultPB
  
  - add method #activePersistenceBroker (proposed by Jakob)
  to PersistenceBrokerFactoryIF for internally tracing
  of PB instances
  
  Revision  Changes    Path
  1.4       +6 -4      db-ojb/src/java/org/apache/ojb/soda/QueryImpl.java
  
  Index: QueryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/soda/QueryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- QueryImpl.java	28 Dec 2002 11:28:00 -0000	1.3
  +++ QueryImpl.java	19 Feb 2003 22:10:13 -0000	1.4
  @@ -60,24 +60,26 @@
   import org.odbms.ObjectSet;
   import org.odbms.Query;
   import org.apache.ojb.broker.OJBRuntimeException;
  +import org.apache.ojb.broker.PersistenceBroker;
   
   /**
  - * @version 	1.0
    * @author Thomas Mahler
  + * @version $Id$
    */
   public class QueryImpl implements Query, Serializable
   {
   
   	private org.apache.ojb.broker.query.Query ojbQuery = null;
  -
   	private int limitCount = -1;
  +    private PersistenceBroker broker;
   
       /**
        * Constructor for QueryImpl.
        */
  -    public QueryImpl()
  +    public QueryImpl(PersistenceBroker broker)
       {
           super();
  +        this.broker = broker;
       }
   
       /**
  @@ -110,7 +112,7 @@
   
           if (ojbQuery != null)
           {
  -            return new ObjectSetImpl(ojbQuery, limitCount);
  +            return new ObjectSetImpl(broker, ojbQuery, limitCount);
           }
           else throw new OJBRuntimeException("internal ojbQuery not filled. Can't execute this query yet!");
       }
  
  
  
  1.4       +24 -33    db-ojb/src/java/org/apache/ojb/soda/ObjectSetImpl.java
  
  Index: ObjectSetImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/soda/ObjectSetImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ObjectSetImpl.java	26 Jul 2002 21:56:11 -0000	1.3
  +++ ObjectSetImpl.java	19 Feb 2003 22:10:13 -0000	1.4
  @@ -62,63 +62,55 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.accesslayer.RsIterator;
   import org.apache.ojb.broker.server.RsIteratorStub;
   import org.odbms.ObjectSet;
   
   /**
  - * @version 	1.0
  - * @author
  + * @version $Id$
    */
   public class ObjectSetImpl implements ObjectSet
   {
       protected Iterator ojbIterator;
  -
  -    protected PersistenceBroker ojbBroker;
  -
       protected int length;
  -
       protected Vector elements;
  -
       protected int position;
  -
       protected int scrolled;
  -
       protected boolean resultSetClosed;
   
       /**
        * Constructor for ObjectSetImpl. Builds up an ObjectSet from an OJB Query object
        */
  -    public ObjectSetImpl(org.apache.ojb.broker.query.Query query, int limit)
  +    public ObjectSetImpl(PersistenceBroker broker, Query query, int limit)
       {
           super();
  -		try
  -		{
  -			ojbBroker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -		}
  -		catch (PBFactoryException e)
  -		{
  -			throw new PersistenceBrokerException(e);
  -		}
           position = 0;
           scrolled = 0;
  -        length = ojbBroker.getCount(query);
  -        if (limit >= 0)
  -        {
  -        	length = Math.min(length,limit);
  -        }
  -        elements = new Vector(length);
  -        
  +
  +        // avoid double query
  +//        length = broker.getCount(query);
  +//        if (limit >= 0)
  +//        {
  +//        	length = Math.min(length,limit);
  +//        }
  +//        elements = new Vector(length);
  +
           // thma:
           // unfortunately Iterators are currently not extent-ware
           // we have to use getCollectionBy Query () thus!
           //ojbIterator = ojbBroker.getIteratorByQuery(query);
  -        
  -        Collection col = ojbBroker.getCollectionByQuery(query);
  +        Collection col = broker.getCollectionByQuery(query);
           ojbIterator = col.iterator();
  -        
  +
  +        length = col.size();
  +        if (limit >= 0)
  +        {
  +        	length = Math.min(length,limit);
  +        }
  +        elements = new Vector(length);
  +
           setResultSetClosed(false);
  -        ojbBroker.close();
       }
   
       /*
  @@ -130,12 +122,12 @@
           {
               if (position < scrolled)
               {
  -             	return true;   
  +             	return true;
               }
               else
               {
                   boolean result = ojbIterator.hasNext();
  -             	return result;  
  +             	return result;
               }
           }
           else
  @@ -143,7 +135,7 @@
   			releaseJdbcResources();
               return false;
           }
  -        
  +
       }
   
       protected void releaseJdbcResources()
  @@ -215,5 +207,4 @@
       {
           this.resultSetClosed = resultSetClosed;
       }
  -
   }
  
  
  
  1.3       +27 -31    db-ojb/src/java/org/apache/ojb/soda/ObjectContainerImpl.java
  
  Index: ObjectContainerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/soda/ObjectContainerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectContainerImpl.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ ObjectContainerImpl.java	19 Feb 2003 22:10:13 -0000	1.3
  @@ -53,36 +53,32 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
  -import org.odbms.ObjectContainer;
  -import org.odbms.Query;
  -
  -/**
  - * @version 	1.0
  - * @author Thomas Mahler
  - */
  -public class ObjectContainerImpl implements ObjectContainer
  -{
  -
  -	private static ObjectContainer instance = null;
  -
  -	public static ObjectContainer getInstance()
  -	{
  -	    if (instance == null)
  -	    {
  -	     	instance = new ObjectContainerImpl();   
  -	    }
  -	    return instance;
  +
  +import org.odbms.ObjectContainer;
  +import org.odbms.Query;
  +import org.apache.ojb.broker.PersistenceBroker;
  +/**
  + * @author Thomas Mahler
  + * @version $Id$
  + */
  +public class ObjectContainerImpl implements ObjectContainer
  +{
  +    private PersistenceBroker broker;
  +
  +    private ObjectContainerImpl(PersistenceBroker broker)
  +    {
  +        this.broker = broker;
  +    }
  +
  +    public static ObjectContainer getInstance(PersistenceBroker broker)
  +	{
  +	    return new ObjectContainerImpl(broker);
   	}
  -	
  -
  -
  -    /*
  -     * @see ObjectContainer#query()
  -     */
  -    public Query query()
  -    {
  -        return new QueryImpl();
  -    }
  -
  +    /*
  +     * @see ObjectContainer#query()
  +     */
  +    public Query query()
  +    {
  +        return new QueryImpl(broker);
  +    }
   }
  
  
  
  1.6       +6 -1      db-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerListener.java
  
  Index: PersistenceBrokerListener.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerListener.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PersistenceBrokerListener.java	31 Jan 2003 17:55:55 -0000	1.5
  +++ PersistenceBrokerListener.java	19 Feb 2003 22:10:15 -0000	1.6
  @@ -94,4 +94,9 @@
        * @throws PersistenceBrokerException
        */
       public void afterLookup(Object instance) throws PersistenceBrokerException;
  +
  +    /**
  +     * Called before the PersistenceBroker was closed (returned to pool).
  +     */
  +    public void beforeClose() throws PersistenceBrokerException;
   }
  
  
  
  1.18      +45 -82    db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java
  
  Index: PersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PersistenceBroker.java	15 Jan 2003 10:43:30 -0000	1.17
  +++ PersistenceBroker.java	19 Feb 2003 22:10:15 -0000	1.18
  @@ -69,6 +69,7 @@
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.configuration.Configurable;
   import org.apache.ojb.broker.util.sequence.SequenceManager;
  +import org.apache.ojb.broker.cache.ObjectCache;
   import org.odbms.ObjectContainer;
   
   /**
  @@ -87,6 +88,7 @@
       public static final int EVENT_BEFORE_DELETE = 3;
       public static final int EVENT_AFTER_DELETE = 4;
       public static final int EVENT_AFTER_LOOKUP = 5;
  +    public static final int EVENT_BEFORE_CLOSE = 6;
   
       // *************************************************************************
       // Services handled by the PersistenceBroker
  @@ -123,6 +125,12 @@
        */
       public BrokerHelper serviceBrokerHelper();
   
  +    /**
  +     * Returns the {@link org.apache.ojb.briker.cache.ObjectCache} instance associated
  +     * with this broker.
  +     */
  +    public ObjectCache serviceObjectCache();
  +
   
   
   
  @@ -137,27 +145,59 @@
        * @param instance the object being manipulated by the PersistenceBroker
        * @param eventId the id of the event. Should be one of
        *  EVENT_BEFORE_STORE, EVENT_AFTER_STORE, EVENT_BEFORE_DELETE,
  -     *  EVENT_AFTER_DELETE, EVENT_AFTER_LOOKUP;
  +     *  EVENT_AFTER_DELETE, EVENT_AFTER_LOOKUP, EVENT_BEFORE_CLOSE;
        */
       public void fireBrokerEvent(Object instance, int eventId);
   
       /**
  -     * Adds a listener to this PersistenceBroker instance
  -     * @param listener
  +     * Adds a temporary {@link org.apache.ojb.broker.PersistenceBrokerListener}
  +     * to this PersistenceBroker instance - when PersistenceBroker.close() was
  +     * called the listener was removed.
  +     *
  +     * @param listener The listener to add
  +     * @see #addListener(PersistenceBrokerListener listener, boolean permanent)
        */
       public void addListener(PersistenceBrokerListener listener) throws PersistenceBrokerException;;
   
       /**
  +     * Adds a permanent {@link org.apache.ojb.broker.PersistenceBrokerListener}
  +     * to this PersistenceBroker instance if parameter <code>permanent</code>
  +     * was <code>true</code>. This means the listener will be
  +     * hold the whole life time of the broker.
  +     * <br/>
  +     * <b>NOTE:</b> Handle carefully when using this method, keep in mind you don't
  +     * know which instance was returned next time from the pool, with a permanent
  +     * listener or without! To garantee that any pooled broker instance use the permanent
  +     * listener, best way is to implement your own
  +     * {@link org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF} or extend the default
  +     * implementation and override
  +     * {@link PersistenceBrokerFactoryDefaultImpl#createNewBrokerInstance(PBKey key)} and
  +     * add the listener.
  +     */
  +    public void addListener(PersistenceBrokerListener listener, boolean permanent) throws PersistenceBrokerException;;
  +
  +    /**
        * Removes a listener from this PersistenceBroker instance
        * @param listener
        */
       public void removeListener(PersistenceBrokerListener listener) throws PersistenceBrokerException;;
   
       /**
  -     * Removes all listeners from this PersistenceBroker instance
  +     * Removes all temporary listeners from this PersistenceBroker instance
  +     * - Handle with care!
        */
       public void removeAllListeners() throws PersistenceBrokerException;
   
  +    /**
  +     * If parameter <code>permanet</code> was <code>true</code> all permanent and temporary listeners
  +     * will be removed from this PersistenceBroker instance.
  +     * <br/>
  +     * <b>NOTE:</b> Handle with care!
  +     *
  +     * @see #removeListener(PersistenceBrokerListener listener)
  +     */
  +    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException;
  +
   
   
   
  @@ -406,81 +446,4 @@
        */
       public Enumeration getPKEnumerationByQuery(Class PrimaryKeyClass, Query query)
               throws PersistenceBrokerException;
  -
  -
  -
  -
  -//    /**
  -//     * adds a new or replaces an existing ClassDescriptor to the DescriptorRepository.
  -//     */
  -//    public void setClassDescriptor(ClassDescriptor modifiedOrNewDescriptor) throws PersistenceBrokerException;
  -
  -
  -//    /**
  -//     * Returns a unique int value for the given field attribute.
  -//     * The returned int value is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     *
  -//     * @deprecated use {@link #getUniqueId(FieldDescriptor field)} instead
  -//     */
  -//    public int getUniqueId(Class extent, String attribute) throws PersistenceBrokerException;
  -//
  -//    /**
  -//     * Returns a unique long value for the given field attribute.
  -//     * The returned long value is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     *
  -//     * @deprecated use {@link #getUniqueLong(FieldDescriptor field)} instead
  -//     */
  -//    public long getUniqueLong(Class extent, String attribute) throws PersistenceBrokerException;
  -//
  -//
  -//    /**
  -//     * Returns a unique String for the given field attribute.
  -//     * The returned String is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     *
  -//     * @deprecated use {@link #getUniqueString(FieldDescriptor field)} instead
  -//     */
  -//    public String getUniqueString(Class extent, String attribute) throws PersistenceBrokerException;
  -//
  -//    /**
  -//     * Returns a unique object for the given field attribute.
  -//     * The returned object is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     *
  -//     * @deprecated use {@link #getUniqueObject(FieldDescriptor field)} instead
  -//     */
  -//    public Object getUniqueObject(Class extent, String attribute) throws PersistenceBrokerException;
  -//
  -//
  -//    /**
  -//     * Returns a unique int value for the given field attribute.
  -//     * The returned int value is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     */
  -//    public int getUniqueId(FieldDescriptor field) throws PersistenceBrokerException;
  -//
  -//    /**
  -//     * Returns a unique long value for the given field attribute.
  -//     * The returned long value is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     */
  -//    public long getUniqueLong(FieldDescriptor field) throws PersistenceBrokerException;
  -//
  -//
  -//    /**
  -//     * Returns a unique String for the given field attribute.
  -//     * The returned String is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     */
  -//    public String getUniqueString(FieldDescriptor field) throws PersistenceBrokerException;
  -//
  -//    /**
  -//     * Returns a unique object for the given field attribute.
  -//     * The returned object is unique accross all tables in the extent
  -//     * of class the field belongs to.
  -//     */
  -//    public Object getUniqueObject(FieldDescriptor field) throws PersistenceBrokerException;
  -
   }
  
  
  
  1.13      +8 -1      db-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryIF.java
  
  Index: PersistenceBrokerFactoryIF.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryIF.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PersistenceBrokerFactoryIF.java	9 Jan 2003 17:08:45 -0000	1.12
  +++ PersistenceBrokerFactoryIF.java	19 Feb 2003 22:10:16 -0000	1.13
  @@ -114,4 +114,11 @@
        * each broker instance is closed before release.
        */
       public void releaseAllInstances();
  +
  +    /**
  +     * Returns the total number of
  +     * active {@link org.apache.ojb.broker.PersistenceBroker}
  +     * instances.
  +     */
  +    public int activePersistenceBroker();
   }
  
  
  
  1.37      +11 -5     db-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java
  
  Index: PersistenceBrokerFactoryDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- PersistenceBrokerFactoryDefaultImpl.java	11 Feb 2003 09:41:55 -0000	1.36
  +++ PersistenceBrokerFactoryDefaultImpl.java	19 Feb 2003 22:10:16 -0000	1.37
  @@ -250,7 +250,6 @@
                   throw new PBFactoryException("Borrow broker from pool failed", e);
               }
           }
  -        PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(pbKey, broker);
           return broker;
       }
   
  @@ -339,6 +338,11 @@
           }
       }
   
  +    public int activePersistenceBroker()
  +    {
  +        return brokerPool.getNumActive();
  +    }
  +
       /**
        * Create the {@link org.apache.commons.pool.KeyedObjectPool}, pooling
        * the {@link org.apache.ojb.broker.PersistenceBroker} instances - override this method to
  @@ -406,8 +410,8 @@
            */
           public boolean validateObject(Object key, Object obj)
           {
  -            //here we could validate the PB instance
  -            //if corresponding configuration properties are set
  +            // here we could validate the PB instance
  +            // if corresponding configuration properties are set
               if (((PersistenceBroker) obj).isInTransaction())
               {
                   log.error("Illegal broker state! This broker instance was already in transaction.");
  @@ -422,6 +426,7 @@
           public void activateObject(Object key, Object obj) throws Exception
           {
               ((PBState) obj).setClosed(false);
  +            PersistenceBrokerThreadMapping.setCurrentPersistenceBroker((PBKey) key, (PersistenceBroker) obj);
           }
   
           /**
  @@ -429,7 +434,8 @@
            */
           public void passivateObject(Object key, Object obj) throws Exception
           {
  -            //this maybe already done before
  +            PersistenceBrokerThreadMapping.unsetCurrentPersistenceBroker((PBKey) key, (PersistenceBroker) obj);
  +            // this maybe already done before
               ((PBState) obj).setClosed(true);
           }
       }
  
  
  
  1.133     +22 -17    db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.132
  retrieving revision 1.133
  diff -u -r1.132 -r1.133
  --- PersistenceBrokerImpl.java	18 Feb 2003 18:23:51 -0000	1.132
  +++ PersistenceBrokerImpl.java	19 Feb 2003 22:10:16 -0000	1.133
  @@ -205,7 +205,7 @@
           */
           brokerHelper = new BrokerHelper(this);
           connectionManager = ConnectionManagerFactory.getInstance().createConnectionManager(this);
  -        objectCache = ObjectCacheFactory.getInstance().getObjectCache();
  +        objectCache = ObjectCacheFactory.getInstance().createObjectCache(this);
           sequenceManager = SequenceManagerFactory.getSequenceManager(this);
           dbAccess = JdbcAccessFactory.getInstance().createJdbcAccess(this);
           statementManager = StatementManagerFactory.getInstance().createStatementManager(this);
  @@ -247,6 +247,11 @@
           return this.brokerHelper;
       }
   
  +    public ObjectCache serviceObjectCache()
  +    {
  +        return this.objectCache;
  +    }
  +
       public boolean isClosed()
       {
           return this.isClosed;
  @@ -321,6 +326,8 @@
           }
           try
           {
  +            fireBrokerEvent(null, EVENT_BEFORE_CLOSE);
  +            clearRegistrationLists();
               if (connectionManager != null)
               {
                   connectionManager.releaseConnection();
  @@ -333,7 +340,6 @@
           {
               this.setClosed(true);
           }
  -        PersistenceBrokerThreadMapping.unsetCurrentPersistenceBroker(this.pbKey, this);
           return true;
       }
   
  @@ -347,7 +353,7 @@
       {
           if (!this.connectionManager.isInLocalTransaction())
           {
  -            throw new TransactionNotInProgressException();
  +            throw new TransactionNotInProgressException("ConnectionManager is NOT in transaction");
           }
   		clearRegistrationLists();
           this.connectionManager.localRollback();
  @@ -364,7 +370,7 @@
       {
           if (this.connectionManager.isInLocalTransaction())
           {
  -            throw new TransactionInProgressException();
  +            throw new TransactionInProgressException("ConnectionManager is already in transaction");
           }
           this.connectionManager.localBegin();
       }
  @@ -382,7 +388,7 @@
       {
           if (!this.connectionManager.isInLocalTransaction())
           {
  -            throw new TransactionNotInProgressException();
  +            throw new TransactionNotInProgressException("ConnectionManager is NOT in transaction");
           }
   		clearRegistrationLists();
   
  @@ -1360,7 +1366,7 @@
   
       /**
        * retrieve a collection of type collectionClass matching the Query query
  -     * 
  +     *
        * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
        */
       public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
  @@ -1372,7 +1378,7 @@
       /**
        * retrieve a collection of type collectionClass matching the Query query
        * if lazy = true return a CollectionProxy
  -     * 
  +     *
        * @param collectionClass
        * @param query
        * @param lazy
  @@ -1413,17 +1419,17 @@
        * @return Class
        */
   	protected Class getCollectionProxyClass(Class collectionClass)
  -	{ 
  +	{
           if (m_collectionProxyClass != null)
           {
               return m_collectionProxyClass;
  -        }     
  -		
  +        }
  +
           if (List.class.isAssignableFrom(collectionClass))
   		{
   		    return ListProxy.class;
   		}
  -		
  +
           return CollectionProxy.class;
   	}
   
  @@ -1821,12 +1827,12 @@
   
   
               // cache object for symmetry with getObjectByXXX()
  -            
  +
               // Create a new Identity based on the current set of primary key values.
               Identity newOid = new Identity(obj, this, cld);
               // Add the object to the cache.
               objectCache.cache(newOid, obj);
  -            
  +
               // 4. store 1:n and m:n associations
               storeCollections(obj, cld.getCollectionDescriptors());
           }
  @@ -2016,8 +2022,7 @@
        */
       public void removeFromCache(Object obj) throws PersistenceBrokerException
       {
  -    	Identity oid = new Identity(obj, this);
  -        objectCache.remove(oid);
  +        objectCache.remove(new Identity(obj, this));
       }
   
       /**
  @@ -2296,7 +2301,7 @@
   	 */
       public org.odbms.Query query()
       {
  -        return new org.apache.ojb.soda.QueryImpl();
  +        return new org.apache.ojb.soda.QueryImpl(this);
       }
   
       /**
  
  
  
  1.7       +62 -20    db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerAbstractImpl.java
  
  Index: PersistenceBrokerAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerAbstractImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PersistenceBrokerAbstractImpl.java	24 Dec 2002 13:20:03 -0000	1.6
  +++ PersistenceBrokerAbstractImpl.java	19 Feb 2003 22:10:16 -0000	1.7
  @@ -60,6 +60,8 @@
   import java.util.List;
   import java.util.ArrayList;
   import java.util.Iterator;
  +import java.util.Map;
  +import java.util.HashMap;
   
   /**
    * Abstract Implementation of PersistenceBroker
  @@ -70,45 +72,82 @@
    */
   public abstract class PersistenceBrokerAbstractImpl implements PersistenceBroker
    {
  +    private static final Boolean TRUE = new Boolean("true");
  +    private static final Boolean FALSE = new Boolean("false");
       /**
  -     * A list of PersistenceBrokerListener instances
  +     * Map contains all temporary and permanent {@link org.apache.ojb.broker.PersistenceBrokerListener}
  +     * instances as keys, values are <code>Boolean true</code> for permanent and <code>Boolean false</code>
  +     * for temporary listener.
        */
  -    private List listenerList = new ArrayList();
  +    private Map listenerMap = newMap();
   
       /**
  -     * Adds a listener to the PersistenceBroker
  -     * @param listener
  +     * Returns a new map instance.
  +     */
  +    private Map newMap()
  +    {
  +        return new HashMap();
  +    }
  +
  +    /**
  +     * @see {@link org.apache.ojb.broker.PersistenceBroker#addListener(PersistenceBrokerListener listener)}
        */
       public void addListener(PersistenceBrokerListener listener) throws PersistenceBrokerException
       {
  -        listenerList.add(listener);
  +        listenerMap.put(listener, FALSE);
  +    }
  +
  +    /**
  +     * @see {@link org.apache.ojb.broker.PersistenceBroker#addListener(PersistenceBrokerListener listener, boolean permanent)}
  +     */
  +    public void addListener(PersistenceBrokerListener listener, boolean permanent) throws PersistenceBrokerException
  +    {
  +        listenerMap.put(listener, new Boolean(permanent));
       }
   
       /**
  -     * Removes a listener from the PersistenceBroker
  -     * @param listener
  +     * @see {@link org.apache.ojb.broker.PersistenceBroker#removeListener(PersistenceBrokerListener listener)}
        */
       public void removeListener(PersistenceBrokerListener listener) throws PersistenceBrokerException
       {
  -        listenerList.remove(listener);
  +        listenerMap.remove(listener);
  +    }
  +
  +    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  +    {
  +        if(permanent)
  +        {
  +            // all listener removed
  +            listenerMap.clear();
  +        }
  +        else
  +        {
  +            // we keep the permanent listener and remove the temporary
  +            Iterator it = listenerMap.keySet().iterator();
  +            Map replace = newMap();
  +            Object obj;
  +            while (it.hasNext())
  +            {
  +                obj = (Object) it.next();
  +                if(listenerMap.get(obj).equals(TRUE))
  +                {
  +                    replace.put(obj, TRUE);
  +                }
  +            }
  +            listenerMap = replace;
  +        }
       }
   
       /**
  -     * Removes all listeners from the PersistenceBroker
  +     * @see {@link org.apache.ojb.broker.PersistenceBroker#removeAllListeners()}
        */
       public void removeAllListeners() throws PersistenceBrokerException
       {
  -        listenerList.clear();
  +        removeAllListeners(false);
       }
  +
       /**
  -     * Performs appropriate callback on the instance object, if it implements
  -     * PersistenceBrokerAware, and then notifys all listeners of the
  -     * event
  -     *
  -     * @param instance the object being manipulated by the PersistenceBroker
  -     * @param eventId the id of the event. Should be one of
  -     *  EVENT_BEFORE_STORE, EVENT_AFTER_STORE, EVENT_BEFORE_DELETE,
  -     *  EVENT_AFTER_DELETE, EVENT_AFTER_LOOKUP;
  +     * @see {@link org.apache.ojb.broker.PersistenceBroker#fireBrokerEvent(Object instance, int eventId)}
        */
       public void fireBrokerEvent(Object instance, int eventId)
       {
  @@ -117,7 +156,7 @@
               performCallBack(eventId, (PersistenceBrokerAware) instance);
           }
   
  -        for (Iterator it = listenerList.iterator(); it.hasNext();)
  +        for (Iterator it = listenerMap.keySet().iterator(); it.hasNext();)
           {
               PersistenceBrokerListener listener = (PersistenceBrokerListener) it.next();
               notifiyListener(listener, eventId, instance);
  @@ -162,6 +201,9 @@
                   break;
               case EVENT_AFTER_LOOKUP:
                   listener.afterLookup(instance);
  +                break;
  +            case EVENT_BEFORE_CLOSE:
  +                listener.beforeClose();
                   break;
           }
       }
  
  
  
  1.9       +16 -0     db-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java
  
  Index: DelegatingPersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DelegatingPersistenceBroker.java	25 Jan 2003 09:35:49 -0000	1.8
  +++ DelegatingPersistenceBroker.java	19 Feb 2003 22:10:16 -0000	1.9
  @@ -14,6 +14,7 @@
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
  @@ -197,6 +198,16 @@
           getBroker().addListener(listener);
       }
   
  +    public void addListener(PersistenceBrokerListener listener, boolean permanent) throws PersistenceBrokerException
  +    {
  +        getBroker().addListener(listener, permanent);
  +    }
  +
  +    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  +    {
  +        getBroker().removeAllListeners(permanent);
  +    }
  +
       public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException
       {
           getBroker().retrieveReference(pInstance, pAttributeName);
  @@ -225,6 +236,11 @@
       public BrokerHelper serviceBrokerHelper()
       {
           return getBroker().serviceBrokerHelper();
  +    }
  +
  +    public ObjectCache serviceObjectCache()
  +    {
  +        return getBroker().serviceObjectCache();
       }
   
       public void fireBrokerEvent(Object instance, int eventId)
  
  
  
  1.22      +18 -1     db-ojb/src/java/org/apache/ojb/broker/server/PersistenceBrokerClient.java
  
  Index: PersistenceBrokerClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/server/PersistenceBrokerClient.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PersistenceBrokerClient.java	30 Jan 2003 15:16:51 -0000	1.21
  +++ PersistenceBrokerClient.java	19 Feb 2003 22:10:17 -0000	1.22
  @@ -60,6 +60,7 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerListener;
  +import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
  @@ -449,6 +450,12 @@
           throw new UnsupportedOperationException("Not implemented!!");
       }
   
  +    public ObjectCache serviceObjectCache()
  +    {
  +        /*@todo implementation*/
  +        throw new UnsupportedOperationException("Not implemented!!");
  +    }
  +
       public void fireBrokerEvent(Object instance, int eventId)
       {
           /*@todo implementation*/
  @@ -1071,6 +1078,16 @@
        * @param listener
        */
       public void addListener(PersistenceBrokerListener listener) throws PersistenceBrokerException
  +    {
  +        throw new PersistenceBrokerException("Not Implemented On Client");
  +    }
  +
  +    public void addListener(PersistenceBrokerListener listener, boolean permanent) throws PersistenceBrokerException
  +    {
  +        throw new PersistenceBrokerException("Not Implemented On Client");
  +    }
  +
  +    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
       {
           throw new PersistenceBrokerException("Not Implemented On Client");
       }
  
  
  
  1.10      +16 -0     db-ojb/src/java/org/apache/ojb/broker/server/PersistenceBrokerBean.java
  
  Index: PersistenceBrokerBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/server/PersistenceBrokerBean.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PersistenceBrokerBean.java	30 Jan 2003 15:16:51 -0000	1.9
  +++ PersistenceBrokerBean.java	19 Feb 2003 22:10:17 -0000	1.10
  @@ -75,6 +75,7 @@
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
  @@ -439,6 +440,11 @@
           return getBroker().serviceBrokerHelper();
       }
   
  +    public ObjectCache serviceObjectCache()
  +    {
  +        return getBroker().serviceObjectCache();
  +    }
  +
       public void fireBrokerEvent(Object instance, int eventId)
       {
           getBroker().fireBrokerEvent(instance, eventId);
  @@ -472,6 +478,16 @@
               throws PersistenceBrokerException
       {
           getBroker().addListener(listener);
  +    }
  +
  +    public void addListener(PersistenceBrokerListener listener, boolean permanent) throws PersistenceBrokerException
  +    {
  +        getBroker().addListener(listener, permanent);
  +    }
  +
  +    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  +    {
  +        getBroker().removeAllListeners(permanent);
       }
   
       /**
  
  
  
  1.3       +103 -45   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectCachePerBrokerImpl.java	15 Feb 2003 10:06:48 -0000	1.2
  +++ ObjectCachePerBrokerImpl.java	19 Feb 2003 22:10:17 -0000	1.3
  @@ -1,4 +1,5 @@
   package org.apache.ojb.broker.cache;
  +
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -53,63 +54,120 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.HashMap;
  -
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
  -import org.apache.ojb.broker.singlevm.PersistenceBrokerThreadMapping;
  +import org.apache.ojb.broker.PersistenceBrokerListener;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +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;
  +import java.util.HashMap;
  +import java.util.Map;
   
   /**
  - * This cache implementation allows to have dedicated caches per broker.
  + * This local 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.
  - *
  + * When the broker was closed (returned to pool) the cache was cleared.
    *
  - * @author Thomas Mahler
  + * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  + * @version $Id$
    */
  -public class ObjectCachePerBrokerImpl extends AbstractMetaCache
  +public class ObjectCachePerBrokerImpl implements ObjectCache, PersistenceBrokerListener
   {
  -	/**
  -	 * 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 getCache(Identity oid)
  -	{
  -		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(currentBroker, result);
  -		}
  -		return result;
  -	}
  +    /**
  +     * the hashtable holding all cached object
  +     */
  +    protected Map objectTable = null;
  +
  +    /**
  +     * public Default Constructor
  +     */
  +    public ObjectCachePerBrokerImpl(PersistenceBroker broker)
  +    {
  +        objectTable = new HashMap();
  +        // add this cache as permanent listener
  +        broker.addListener(this, true);
  +    }
   
       /**
  -     * @see org.apache.ojb.broker.cache.ObjectCache#clear()
  +     * Clear ObjectCache. I.e. remove all entries for classes and objects.
        */
       public void clear()
       {
  -    	brokerMap.clear();
  +        objectTable.clear();
  +    }
  +
  +    /**
  +     * 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)
  +    {
  +        if ((obj != null))
  +        {
  +            SoftReference ref = new SoftReference(obj);
  +            objectTable.put(oid.toString(), ref);
  +        }
  +    }
  +
  +    /**
  +     * Lookup object with Identity oid in objectTable.
  +     * Returns null if no matching id is found
  +     */
  +    public Object lookup(Identity oid)
  +    {
  +        Object obj = null;
  +        SoftReference ref = (SoftReference) objectTable.get(oid.toString());
  +        if (ref != null)
  +        {
  +            obj = ref.get();
  +            if (obj == null)
  +            {
  +                objectTable.remove(oid.toString());    // Soft-referenced Object reclaimed by GC
  +            }
  +        }
  +        return obj;
  +    }
  +
  +    /**
  +     * Removes an Object from the cache.
  +     */
  +    public void remove(Identity oid)
  +    {
  +        if (oid != null)
  +        {
  +            objectTable.remove(oid.toString());
  +        }
  +    }
  +
  +    /**
  +     * We clear the cache
  +     */
  +    public void beforeClose() throws PersistenceBrokerException
  +    {
  +        this.clear();
  +    }
  +
  +    public void afterLookup(Object instance) throws PersistenceBrokerException
  +    {
  +    }
  +
  +    public void afterDelete(Object instance) throws PersistenceBrokerException
  +    {
  +    }
  +
  +    public void beforeDelete(Object instance) throws PersistenceBrokerException
  +    {
  +    }
  +
  +    public void afterStore(Object instance) throws PersistenceBrokerException
  +    {
  +    }
  +
  +    public void beforeStore(Object instance) throws PersistenceBrokerException
  +    {
       }
   }
  
  
  
  1.6       +4 -5      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ObjectCacheJCSImpl.java	15 Feb 2003 10:06:48 -0000	1.5
  +++ ObjectCacheJCSImpl.java	19 Feb 2003 22:10:17 -0000	1.6
  @@ -56,9 +56,12 @@
   import org.apache.jcs.JCS;
   import org.apache.jcs.access.exception.CacheException;
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
   
   /**
  + * Cache used in conjunction with {@link MetaObjectJCSCacheImpl}.
  + *
    * @author Matthew Baird (mattbaird@yahoo.com);
    * @version $Id$
    */
  @@ -69,10 +72,6 @@
        * if no regionname is passed in, we use the default region.
        */
       private String m_regionName = "region.ObjectBridge";
  -
  -    public ObjectCacheJCSImpl()
  -    {
  -    }
   
       public ObjectCacheJCSImpl(String name)
       {
  
  
  
  1.10      +6 -4      db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheFactory.java
  
  Index: ObjectCacheFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ObjectCacheFactory.java	24 Dec 2002 13:05:36 -0000	1.9
  +++ ObjectCacheFactory.java	19 Feb 2003 22:10:17 -0000	1.10
  @@ -54,8 +54,10 @@
    * <http://www.apache.org/>.
    */
   import org.apache.ojb.broker.util.factory.ConfigurableFactory;
  +import org.apache.ojb.broker.PersistenceBroker;
   
   /**
  + * Factory for {@link ObjectCache} implementation classes.
    *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
  @@ -77,7 +79,7 @@
       	return INSTANCE;
       }
   
  -    public ObjectCache getObjectCache()
  +    public ObjectCache createObjectCache(PersistenceBroker broker)
       {
           if (CACHE == null)
           {
  @@ -85,11 +87,11 @@
               {
   				try
   				{
  -					CACHE = (ObjectCache) this.createNewInstance();
  +					CACHE = (ObjectCache) this.createNewInstance(PersistenceBroker.class, broker);
   				}
   				catch (Exception e)
   				{
  -					CACHE = new ObjectCacheDefaultImpl();
  +					CACHE = new ObjectCacheDefaultImpl(null);
   				}
               }
   
  
  
  
  1.5       +52 -5     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ObjectCacheEmptyImpl.java	15 Feb 2003 10:06:48 -0000	1.4
  +++ ObjectCacheEmptyImpl.java	19 Feb 2003 22:10:17 -0000	1.5
  @@ -55,30 +55,46 @@
    */
   
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerListener;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
  +import java.util.Map;
  +import java.util.HashMap;
   
   /**
    * This implementation of ObjectCache does not do anything.
    * It can be used in situations where caching is not possible.
  + * To support 'circular references' this implementation
  + * use a temporary map while store and delete operation.
    *
    * @author Thomas Mahler
    * @version $Id$
    *
    */
  -public class ObjectCacheEmptyImpl implements ObjectCache
  +public class ObjectCacheEmptyImpl implements ObjectCache, PersistenceBrokerListener
   {
  +    private Map tempMap = new HashMap();
  +
  +    public ObjectCacheEmptyImpl(PersistenceBroker broker)
  +    {
  +        broker.addListener(this, true);
  +    }
  +
       /**
        * @see org.apache.ojb.broker.cache.ObjectCache#cache(Identity, Object)
        */
  -    public void cache(Identity arg0, Object arg1)
  +    public void cache(Identity oid, Object obj)
       {
  +        tempMap.put(oid, obj);
       }
   
       /**
        * @see org.apache.ojb.broker.cache.ObjectCache#lookup(Identity)
        */
  -    public Object lookup(Identity arg0)
  +    public Object lookup(Identity oid)
       {
  -        return null;
  +        return tempMap.get(oid);
       }
   
       /**
  @@ -86,6 +102,7 @@
        */
       public void remove(Identity oid)
       {
  +        tempMap.remove(oid);
       }
   
       /**
  @@ -93,6 +110,36 @@
        */
       public void clear()
       {
  +        tempMap.clear();
  +    }
  +
  +    public void afterStore(Object instance) throws PersistenceBrokerException
  +    {
  +        clear();
  +    }
  +
  +    public void beforeStore(Object instance) throws PersistenceBrokerException
  +    {
  +
  +    }
  +
  +    public void beforeDelete(Object instance) throws PersistenceBrokerException
  +    {
  +
  +    }
  +
  +    public void afterDelete(Object instance) throws PersistenceBrokerException
  +    {
  +        clear();
  +    }
  +
  +    public void afterLookup(Object instance) throws PersistenceBrokerException
  +    {
  +    }
  +
  +    public void beforeClose() throws PersistenceBrokerException
  +    {
  +        clear();
       }
   }
   
  
  
  
  1.8       +21 -8     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ObjectCacheDefaultImpl.java	15 Feb 2003 10:06:48 -0000	1.7
  +++ ObjectCacheDefaultImpl.java	19 Feb 2003 22:10:17 -0000	1.8
  @@ -54,15 +54,20 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.commons.lang.SystemUtils;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   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;
  +import java.util.Map;
   
   /**
  - * The ObjectCache stores all Objects loaded by the PersistenceBroker from a DB.
  + * This global ObjectCache stores all Objects loaded by the PersistenceBroker from a DB.
    * When the PersistenceBroker tries to get an Object by its Primary key values
    * it first lookups the cache if the object has been already loaded and cached.
    *
  @@ -85,7 +90,7 @@
       /**
        * the hashtable holding all cached object
        */
  -    protected Hashtable objectTable = null;
  +    protected static Map objectTable = null;
   
       private long hitCount = 0;
       private long failCount = 0;
  @@ -94,7 +99,7 @@
       /**
        * public Default Constructor
        */
  -    public ObjectCacheDefaultImpl()
  +    public ObjectCacheDefaultImpl(PersistenceBroker broker)
       {
           objectTable = new Hashtable();
       }
  @@ -157,12 +162,20 @@
           }
       }
   
  +    public String toString()
  +    {
  +        String eol = SystemUtils.LINE_SEPARATOR;
  +        ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
  +        buf.append("OJB CACHE STATISTICS");
  +        buf.append("lookups", hitCount);
  +        buf.append("failures", failCount);
  +        buf.append("reclaimed", gcCount);
  +        return buf.toString();
  +    }
  +
       public void finalize()
       {
           Logger logger = LoggerFactory.getDefaultLogger();
  -        logger.info("OJB CACHE STATISTICS");
  -        logger.info("lookups:   " + hitCount);
  -        logger.info("failures:  " + failCount);
  -        logger.info("reclaimed: " + gcCount);
  +        logger.info(this.toString());
       }
   }
  
  
  
  1.4       +6 -3      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MetaObjectJCSCacheImpl.java	15 Feb 2003 10:06:48 -0000	1.3
  +++ MetaObjectJCSCacheImpl.java	19 Feb 2003 22:10:17 -0000	1.4
  @@ -55,13 +55,16 @@
    */
   
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   
   /**
  - * creates a JCS region for each classname.
  + * A global {@link ObjectCache} implementation using JCS region for
  + * each classname. More info see <a href="http://jakarta.apache.org/turbine/jcs/index.html">
  + * turbine-JCS</a>.
    *
    * @author  Matthew Baird  (mattbaird@yahoo.com)
    * @version $Id$
  @@ -74,7 +77,7 @@
       /**
        * Constructor for the MetaObjectCacheImpl object
        */
  -    public MetaObjectJCSCacheImpl()
  +    public MetaObjectJCSCacheImpl(PersistenceBroker broker)
       {
       }
   
  
  
  
  1.5       +6 -5      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MetaObjectCacheImpl.java	15 Feb 2003 10:06:48 -0000	1.4
  +++ MetaObjectCacheImpl.java	19 Feb 2003 22:10:17 -0000	1.5
  @@ -55,13 +55,14 @@
    */
   
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   
   /**
  - * This cache makes it possible to have separate cache implementations for
  + * This global cache makes it possible to have separate cache implementations for
    * each class. When an object is cached / looked up the MetaObjectCacheImpl
    * checks if a special ObjectCache has been set for this class. It recursively
    * looks up the superclasses of the given object to look for a special cache. If
  @@ -75,14 +76,14 @@
    */
   public class MetaObjectCacheImpl extends AbstractMetaCache
   {
  -    private Map cachesByClass = new HashMap();
  +    private static Map cachesByClass = new HashMap();
   
       /**
        * Constructor for the MetaObjectCacheImpl object
        */
  -    public MetaObjectCacheImpl()
  +    public MetaObjectCacheImpl(PersistenceBroker broker)
       {
  -        setClassCache(Object.class, new ObjectCacheDefaultImpl());
  +        setClassCache(Object.class, new ObjectCacheDefaultImpl(broker));
       }
   
       /**
  
  
  
  1.29      +3 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- RsIterator.java	2 Feb 2003 03:32:02 -0000	1.28
  +++ RsIterator.java	19 Feb 2003 22:10:17 -0000	1.29
  @@ -100,7 +100,7 @@
   {
       protected Logger logger = LoggerFactory.getLogger(this.getClass());
   
  -    protected static ObjectCache cache = ObjectCacheFactory.getInstance().getObjectCache();
  +    protected ObjectCache cache;
   
       /**
        * reference to the PersistenceBroker
  @@ -173,6 +173,7 @@
       {
           if (logger.isDebugEnabled()) logger.debug("RsIterator(" + query + ", " + mif + ")");
           m_rsAndStmt = broker.serviceJdbcAccess().executeQuery(query, mif);
  +        cache = broker.serviceObjectCache();
           m_row = new HashMap();
           m_query = query;
           m_broker = broker;
  
  
  

Mime
View raw message