db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core PersistenceBrokerImpl.java
Date Fri, 09 Jan 2004 19:56:49 GMT
brj         2004/01/09 11:56:49

  Modified:    src/java/org/apache/ojb/broker/core Tag: OJB_BRANCH_1_0
                        PersistenceBrokerImpl.java
  Log:
  refactoring: new method getCollectionIterator
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.60.2.4  +45 -46    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.60.2.3
  retrieving revision 1.60.2.4
  diff -u -r1.60.2.3 -r1.60.2.4
  --- PersistenceBrokerImpl.java	7 Jan 2004 13:02:05 -0000	1.60.2.3
  +++ PersistenceBrokerImpl.java	9 Jan 2004 19:56:49 -0000	1.60.2.4
  @@ -593,14 +593,13 @@
        */
       private void deleteCollections(Object obj, Vector vecCds) throws PersistenceBrokerException
       {
  -        // get all members of obj that are collections and
  -        // delete all their elements
  +        // get all members of obj that are collections and delete all their elements
           Iterator i = vecCds.iterator();
  -        Iterator colIterator = null;
  +        
           while (i.hasNext())
           {
               CollectionDescriptor cds = (CollectionDescriptor) i.next();
  -            colIterator = null;
  +            
               // if this is a m:n mapped table, remove entries from association table
               if (cds.isMtoNRelation())
               {
  @@ -613,30 +612,14 @@
                */
               if (cds.getCascadeDelete())
               {
  +                Iterator colIterator = null;
  +                
                   try
                   {
                       Object col = cds.getPersistentField().get(obj);
                       if (col != null)
                       {
  -
  -                        if (col instanceof ManageableCollection)
  -                        {
  -                            colIterator = ((ManageableCollection) col).ojbIterator();
  -                        }
  -                        else if (col instanceof Collection)
  -                        {
  -                            colIterator = ((Collection) col).iterator();
  -                        }
  -                        else if (col.getClass().isArray())
  -                        {
  -                            colIterator = new ArrayIterator(col);
  -                        }
  -                        else
  -                        {
  -                            throw new OJBRuntimeException(
  -                                    col.getClass()
  -                                    + " can not be managed by OJB, use Array, Collection
or ManageableCollection instead !");
  -                        }
  +                        colIterator = getCollectionIterator(cds, col);
                           while (colIterator.hasNext())
                           {
                               doDelete(colIterator.next());
  @@ -829,28 +812,7 @@
                       }
                   }
   
  -
  -                Iterator colIterator;
  -                if (col instanceof ManageableCollection)
  -                {
  -                    colIterator = ((ManageableCollection) col).ojbIterator();
  -                }
  -                else if (col instanceof Collection)
  -                {
  -                    colIterator = ((Collection) col).iterator();
  -                }
  -                else if (col.getClass().isArray())
  -                {
  -                    colIterator = new ArrayIterator(col);
  -                }
  -                else
  -                {
  -                    String fieldName = cds.getClassDescriptor().getClassNameOfObject()
+ "." + cds.getAttributeName();
  -                    throw new OJBRuntimeException("When storing " + fieldName + ": " +
  -                            col.getClass()
  -                            + " can not be managed by OJB. Use Array, Collection or ManageableCollection
instead !");
  -                }
  -
  +                Iterator colIterator = getCollectionIterator(cds, col);
                   while (colIterator.hasNext())
                   {
                       Object otherObj = colIterator.next();
  @@ -893,6 +855,43 @@
               }
           }
       }
  +
  +    
  +    /**
  +     * Answer the Iterator for Collection or Array
  +     * @param cds
  +     * @param collectionOrArray
  +     * @return
  +     */
  +    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.
  
  
  

---------------------------------------------------------------------
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