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/singlevm PersistenceBrokerImpl.java
Date Wed, 09 Apr 2003 08:57:49 GMT
arminw      2003/04/09 01:57:49

  Modified:    src/test/org/apache/ojb/broker ArticleCollection.java
               src/java/org/apache/ojb/odmg/collections DListImpl.java
               src/java/org/apache/ojb/broker ManageableCollection.java
               src/java/org/apache/ojb/broker/util/collections
                        RemovalAwareCollection.java ManageableVector.java
                        ManageableHashSet.java ManageableArrayList.java
               src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  add new method 'afterStore(...)' to interface
  ManageableCollection for building 'removal aware'
  collections
  
  Revision  Changes    Path
  1.3       +4 -0      db-ojb/src/test/org/apache/ojb/broker/ArticleCollection.java
  
  Index: ArticleCollection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ArticleCollection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArticleCollection.java	8 Apr 2003 20:19:27 -0000	1.2
  +++ ArticleCollection.java	9 Apr 2003 08:57:48 -0000	1.3
  @@ -58,6 +58,10 @@
           return elements.iterator();
       }
   
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +    {
  +    }
  +
       public int size()
       {
           return elements.size();
  
  
  
  1.21      +4 -0      db-ojb/src/java/org/apache/ojb/odmg/collections/DListImpl.java
  
  Index: DListImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/collections/DListImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DListImpl.java	8 Apr 2003 20:19:28 -0000	1.20
  +++ DListImpl.java	9 Apr 2003 08:57:48 -0000	1.21
  @@ -559,6 +559,10 @@
           }
       }
   
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +    {
  +    }
  +
       /**
        * returns an Iterator over all elements in the collection. Used during store and delete
Operations.
        * If the implementor does not return an iterator over ALL elements, OJB cannot store
and delete all elements properly.
  
  
  
  1.4       +7 -1      db-ojb/src/java/org/apache/ojb/broker/ManageableCollection.java
  
  Index: ManageableCollection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ManageableCollection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManageableCollection.java	13 Sep 2002 16:10:31 -0000	1.3
  +++ ManageableCollection.java	9 Apr 2003 08:57:48 -0000	1.4
  @@ -88,4 +88,10 @@
        *
        */
       Iterator ojbIterator();
  +
  +    /**
  +     * A callback method to implement 'removal-aware' (track removed objects and delete
  +     * them by its own) collection implementations.
  +     */
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException;
   }
  
  
  
  1.2       +40 -73    db-ojb/src/java/org/apache/ojb/broker/util/collections/RemovalAwareCollection.java
  
  Index: RemovalAwareCollection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/RemovalAwareCollection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RemovalAwareCollection.java	6 Apr 2003 14:54:59 -0000	1.1
  +++ RemovalAwareCollection.java	9 Apr 2003 08:57:48 -0000	1.2
  @@ -1,12 +1,11 @@
   package org.apache.ojb.broker.util.collections;
   
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
   import java.util.Iterator;
   import java.util.Vector;
   
  -import org.apache.ojb.broker.PersistenceBrokerAware;
  -import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -
   /**
    * This is a collection that tracks removal and addition of elements.
    * This tracking allow the PersistenceBroker to delete elements from
  @@ -16,55 +15,26 @@
    * collections!
    * @author Thomas Mahler
    */
  -public class RemovalAwareCollection extends ManageableVector implements PersistenceBrokerAware
  +public class RemovalAwareCollection extends ManageableVector
   {
  -	private Vector allObjectsToBeRemoved = new Vector();
  -
  -    /**
  -     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterDelete()
  -     */
  -    public void afterDelete() throws PersistenceBrokerException
  -    {
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterLookup()
  -     */
  -    public void afterLookup() throws PersistenceBrokerException
  -    {
  -    }
  +    private Vector allObjectsToBeRemoved = new Vector();
   
       /**
  -     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterStore()
  -     * @todo: once a PB instance is available as a callback parameter we should use it!
  +     * @see org.apache.ojb.broker.ManageableCollection#afterStore(PersistenceBroker broker)
        */
  -    public void afterStore() throws PersistenceBrokerException
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
       {
  -    	// make sure allObjectsToBeRemoved does not contain
  -    	// any instances that got re-added to the list
  -    	allObjectsToBeRemoved.removeAll(this);
  -    		
  -    	Iterator iter = allObjectsToBeRemoved.iterator();
  -    	while (iter.hasNext())
  -    	{
  -    		// @todo: once a PB instance is available as a callback parameter we should use it!
  -    		PersistenceBrokerFactory.defaultPersistenceBroker().delete(iter.next());	
  -    	}
  -    	allObjectsToBeRemoved.clear();    	
  -    }
  +        // make sure allObjectsToBeRemoved does not contain
  +        // any instances that got re-added to the list
  +        allObjectsToBeRemoved.removeAll(this);
   
  -    /**
  -     * @see org.apache.ojb.broker.PersistenceBrokerAware#beforeDelete()
  -     */
  -    public void beforeDelete() throws PersistenceBrokerException
  -    {
  -    }
  -
  -    /**
  -     * @see org.apache.ojb.broker.PersistenceBrokerAware#beforeStore()
  -     */
  -    public void beforeStore() throws PersistenceBrokerException
  -    {
  +        Iterator iter = allObjectsToBeRemoved.iterator();
  +        while (iter.hasNext())
  +        {
  +            // @todo: once a PB instance is available as a callback parameter we should
use it!
  +            broker.delete(iter.next());
  +        }
  +        allObjectsToBeRemoved.clear();
       }
   
       /**
  @@ -72,22 +42,19 @@
        */
       public Object remove(int index)
       {
  -    	Object toBeRemoved = super.remove(index);
  -    	registerForDeletion(toBeRemoved);    	
  +        Object toBeRemoved = super.remove(index);
  +        registerForDeletion(toBeRemoved);
           return toBeRemoved;
       }
  -    
  -    
  -    
  -
  -	protected void registerForDeletion(Object toBeRemoved)
  -	{
  -		//only add objects once to avoid double deletions
  -		if (! allObjectsToBeRemoved.contains(toBeRemoved))
  -		{
  -			this.allObjectsToBeRemoved.add(toBeRemoved);	
  -		}
  -	}
  +
  +    protected void registerForDeletion(Object toBeRemoved)
  +    {
  +        //only add objects once to avoid double deletions
  +        if (!allObjectsToBeRemoved.contains(toBeRemoved))
  +        {
  +            this.allObjectsToBeRemoved.add(toBeRemoved);
  +        }
  +    }
   
       /**
        * @see java.util.Collection#remove(Object)
  @@ -95,8 +62,8 @@
       public boolean remove(Object o)
       {
           boolean result = super.remove(o);
  -    	registerForDeletion(o);    	
  -        return result;        
  +        registerForDeletion(o);
  +        return result;
       }
   
       /**
  @@ -104,10 +71,10 @@
        */
       public synchronized void removeAllElements()
       {
  -		for (int i = 0; i < this.size(); i++)
  -		{
  -			registerForDeletion(this.get(i));	
  -		}
  +        for (int i = 0; i < this.size(); i++)
  +        {
  +            registerForDeletion(this.get(i));
  +        }
           super.removeAllElements();
       }
   
  @@ -117,8 +84,8 @@
        */
       public synchronized void removeElementAt(int index)
       {
  -    	Object toBeDeleted = this.get(index);
  -    	registerForDeletion(toBeDeleted);
  +        Object toBeDeleted = this.get(index);
  +        registerForDeletion(toBeDeleted);
           super.removeElementAt(index);
       }
   
  @@ -127,10 +94,10 @@
        */
       protected void removeRange(int fromIndex, int toIndex)
       {
  -		for (int i = fromIndex; i < toIndex; i++)
  -		{
  -			registerForDeletion(this.get(i));	
  -		}
  +        for (int i = fromIndex; i < toIndex; i++)
  +        {
  +            registerForDeletion(this.get(i));
  +        }
           super.removeRange(fromIndex, toIndex);
       }
   
  
  
  
  1.4       +10 -4     db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableVector.java
  
  Index: ManageableVector.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableVector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManageableVector.java	21 Sep 2002 16:01:10 -0000	1.3
  +++ ManageableVector.java	9 Apr 2003 08:57:48 -0000	1.4
  @@ -54,16 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
   import java.util.Iterator;
   import java.util.Vector;
   
  -import org.apache.ojb.broker.ManageableCollection;
  -
   /**
    * is a utility class. provides a Vector that addionally implements
    * the ManageableCollection interface. This class may be used
    * as a type for collection attributes.
  - * 
  + *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  @@ -86,6 +88,10 @@
       public void ojbAddAll(ManageableCollection otherCollection)
       {
           this.addAll((ManageableVector) otherCollection);
  +    }
  +
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +    {
       }
   
       /**
  
  
  
  1.4       +10 -4     db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableHashSet.java
  
  Index: ManageableHashSet.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableHashSet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManageableHashSet.java	21 Sep 2002 16:01:10 -0000	1.3
  +++ ManageableHashSet.java	9 Apr 2003 08:57:48 -0000	1.4
  @@ -54,16 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
   import java.util.HashSet;
   import java.util.Iterator;
   
  -import org.apache.ojb.broker.ManageableCollection;
  -
   /**
    * is a utility class. provides a HashSet that addionally implements
    * the ManageableCollection interface. This class may be used
    * as a type for collection attributes.
  - * 
  + *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  @@ -86,6 +88,10 @@
       public void ojbAddAll(ManageableCollection otherCollection)
       {
           super.addAll((ManageableHashSet) otherCollection);
  +    }
  +
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +    {
       }
   
       /**
  
  
  
  1.4       +10 -4     db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableArrayList.java
  
  Index: ManageableArrayList.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/ManageableArrayList.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManageableArrayList.java	21 Sep 2002 16:01:10 -0000	1.3
  +++ ManageableArrayList.java	9 Apr 2003 08:57:48 -0000	1.4
  @@ -54,16 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
   import java.util.ArrayList;
   import java.util.Iterator;
   
  -import org.apache.ojb.broker.ManageableCollection;
  -
   /**
    * is a utility class. provides an ArrayList that addionally implements
    * the ManageableCollection interface. This class may be used
    * as a type for collection attributes.
  - * 
  + *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  @@ -86,6 +88,10 @@
       public void ojbAddAll(ManageableCollection otherCollection)
       {
           this.addAll((ManageableArrayList) otherCollection);
  +    }
  +
  +    public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
  +    {
       }
   
       /**
  
  
  
  1.152     +13 -13    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.151
  retrieving revision 1.152
  diff -u -r1.151 -r1.152
  --- PersistenceBrokerImpl.java	6 Apr 2003 14:54:59 -0000	1.151
  +++ PersistenceBrokerImpl.java	9 Apr 2003 08:57:49 -0000	1.152
  @@ -792,10 +792,10 @@
                           storeCollectionObject(cds, otherObj);
                       }
                   }
  -                // invoke event on collection
  -                if (col instanceof PersistenceBrokerAware)
  +                // invoke callback on collection
  +                if (col instanceof ManageableCollection)
                   {
  -                	((PersistenceBrokerAware) col).afterStore();	
  +                    ((ManageableCollection) col).afterStore(this);
                   }
               }
           }
  @@ -1048,7 +1048,7 @@
               Class collectionClass = cds.getCollectionClass();
               PersistentField collectionField = cds.getPersistentField();
   			Query fkQuery = getFKQuery(obj, cld, cds);
  -            
  +
               if (collectionClass == null)
               {
                   Collection result = getCollectionByQuery(fkQuery, cds.isLazy());
  @@ -1080,9 +1080,9 @@
       }
   
       /**
  -     * Answer the foreign key query to retrieve the collection 
  -     * defined by CollectionDescriptor  
  -     * 
  +     * Answer the foreign key query to retrieve the collection
  +     * defined by CollectionDescriptor
  +     *
        * @param obj
        * @param cld
        * @param cds
  @@ -1092,7 +1092,7 @@
   	{
   		Query fkQuery = null;
   		QueryByCriteria fkQueryCrit = null;
  -		
  +
   		if (cds.isMtoNRelation())
   		{
   		    fkQueryCrit = getFKQueryMtoN(obj, cld, cds);
  @@ -1101,7 +1101,7 @@
   		{
   		    fkQueryCrit = getFKQuery1toN(obj, cld, cds);
   		}
  -		
  +
   		// check if collection must be ordered
   		if (!cds.getOrderBy().isEmpty())
   		{
  @@ -1111,7 +1111,7 @@
   		        fkQueryCrit.addOrderBy((FieldHelper)iter.next());
   		    }
   		}
  -		
  +
   		// BRJ: customize the query
   		if (cds.getQueryCustomizer() != null)
   		{
  @@ -1121,7 +1121,7 @@
   		{
   		    fkQuery = fkQueryCrit;
   		}
  -        
  +
   		return fkQuery;
   	}
   
  @@ -1409,7 +1409,7 @@
   					Class paramType[] = { PBKey.class, Class.class, Query.class };
   					Object param[] = { getPBKey(), collectionClass, query };
   					Class proxyClass = getCollectionProxyClass(collectionClass);
  -			
  +
   					result = (ManageableCollection) proxyClass.getConstructor(paramType).newInstance(param);
   				}
   				else
  
  
  

Mime
View raw message