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/util BrokerHelper.java
Date Thu, 24 Jun 2004 15:22:57 GMT
arminw      2004/06/24 08:22:57

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
  Log:
  move helper method to BrokerHelper
  
  Revision  Changes    Path
  1.83      +6 -39     db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- PersistenceBrokerImpl.java	1 Jun 2004 20:19:32 -0000	1.82
  +++ PersistenceBrokerImpl.java	24 Jun 2004 15:22:57 -0000	1.83
  @@ -26,7 +26,6 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.MtoNImplementor;
  -import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PBState;
   import org.apache.ojb.broker.PersistenceBrokerException;
  @@ -61,7 +60,6 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.query.QueryBySQL;
  -import org.apache.ojb.broker.util.ArrayIterator;
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.IdentityArrayList;
   import org.apache.ojb.broker.util.ObjectModification;
  @@ -645,7 +643,7 @@
                       Object col = cds.getPersistentField().get(obj);
                       if (col != null)
                       {
  -                        Iterator colIterator = getCollectionIterator(cds, col);
  +                        Iterator colIterator = BrokerHelper.getCollectionIterator(col);
                           while (colIterator.hasNext())
                           {
                               doDelete(colIterator.next());
  @@ -847,7 +845,7 @@
               if we store an object with m:n reference and no references could be
               found, we remove all entires of given object in indirection table
               */
  -            Iterator referencedObjectsIterator = getCollectionIterator(cod, referencedObjects);
  +            Iterator referencedObjectsIterator = BrokerHelper.getCollectionIterator(referencedObjects);
   
               if(!referencedObjectsIterator.hasNext())
               {
  @@ -869,7 +867,7 @@
                       mtoNBroker.deleteMtoNImplementor(cod, obj, referencedObjectsIterator,
existingMtoNKeys);
                   }
                   // we can't reuse iterator
  -                referencedObjectsIterator = getCollectionIterator(cod, referencedObjects);
  +                referencedObjectsIterator = BrokerHelper.getCollectionIterator(referencedObjects);
                   while (referencedObjectsIterator.hasNext())
                   {
                       Object refObj = referencedObjectsIterator.next();
  @@ -921,7 +919,7 @@
           if(insert || !(referencedObjects instanceof CollectionProxyDefaultImpl
                           && !((CollectionProxyDefaultImpl) referencedObjects).isLoaded()))
           {
  -            Iterator it = getCollectionIterator(cod, referencedObjects);
  +            Iterator it = serviceBrokerHelper().getCollectionIterator(referencedObjects);
               Object refObj;
               while(it.hasNext())
               {
  @@ -1089,7 +1087,7 @@
               Object collectionObject = col.getPersistentField().get(obj);
               if (collectionObject != null)
               {
  -                Iterator colIterator = getCollectionIterator(col, collectionObject);
  +                Iterator colIterator = BrokerHelper.getCollectionIterator(collectionObject);
                   ClassDescriptor cld = null;
                   while (colIterator.hasNext())
                   {
  @@ -1100,37 +1098,6 @@
               }
           }
       }
  -
  -    /**
  -     * Answer the Iterator for Collection or Array.
  -     * @param cds {@link CollectionDescriptor} for object argument
  -     * @param collectionOrArray a none null object of type {@link Collection},
  -     * Array or {@link ManageableCollection}.
  -     */
  -    private Iterator getCollectionIterator(CollectionDescriptor cds, Object collectionOrArray)
  -    {
  -        Iterator colIterator;
  -        if (collectionOrArray instanceof ManageableCollection)
  -        {
  -            colIterator = ((ManageableCollection) collectionOrArray).ojbIterator();
  -        }
  -        else if (collectionOrArray instanceof Collection)
  -        {
  -            colIterator = ((Collection) collectionOrArray).iterator();
  -        }
  -        else if (collectionOrArray.getClass().isArray())
  -        {
  -            colIterator = new ArrayIterator(collectionOrArray);
  -        }
  -        else
  -        {
  -            String fieldName = cds.getClassDescriptor().getClassNameOfObject() + "." +
cds.getAttributeName();
  -            throw new OJBRuntimeException( "Field '" + fieldName + "' " + collectionOrArray.getClass()
  -                + " can not be managed by OJB. Use Array, Collection or ManageableCollection
instead!");
  -        }
  -        return colIterator;
  -    }
  -
   
       /**
        * retrieve all References (also Collection-attributes) of a given instance.
  
  
  
  1.56      +33 -1     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- BrokerHelper.java	19 Jun 2004 09:21:38 -0000	1.55
  +++ BrokerHelper.java	24 Jun 2004 15:22:57 -0000	1.56
  @@ -22,11 +22,14 @@
   import java.util.Map;
   import java.util.StringTokenizer;
   import java.util.WeakHashMap;
  +import java.util.Collection;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
   import org.apache.ojb.broker.accesslayer.sql.SqlExistStatement;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  @@ -813,5 +816,34 @@
               }
           }
           return match;
  +    }
  +
  +    /**
  +     * Answer the Iterator for Collection or Array.
  +     * @param collectionOrArray a none null object of type {@link java.util.Collection},
  +     * Array or {@link org.apache.ojb.broker.ManageableCollection}.
  +     * @return Iterator able to handle given collection object
  +     */
  +    public static Iterator getCollectionIterator(Object collectionOrArray)
  +    {
  +        Iterator colIterator;
  +        if (collectionOrArray instanceof ManageableCollection)
  +        {
  +            colIterator = ((ManageableCollection) collectionOrArray).ojbIterator();
  +        }
  +        else if (collectionOrArray instanceof Collection)
  +        {
  +            colIterator = ((Collection) collectionOrArray).iterator();
  +        }
  +        else if (collectionOrArray.getClass().isArray())
  +        {
  +            colIterator = new ArrayIterator(collectionOrArray);
  +        }
  +        else
  +        {
  +            throw new OJBRuntimeException( "Given object collection of type " + collectionOrArray.getClass()
  +                + " can not be managed by OJB. Use Array, Collection or ManageableCollection
instead!");
  +        }
  +        return colIterator;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message