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/core PersistenceBrokerImpl.java
Date Wed, 28 Jan 2004 23:49:32 GMT
arminw      2004/01/28 15:49:32

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Log:
  - change behaviour of 1:1 reference handling on store
  of new objects.
  When the main object have populated FK fields, but
  the reference object was null on isert, in old version
  PB replace FK by null. I change this to accept populated FK
  fields without reference object (only for store of new objects).
  
  - replace all Vector class arguments by List interface
  
  Revision  Changes    Path
  1.64      +50 -38    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.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- PersistenceBrokerImpl.java	9 Jan 2004 19:54:58 -0000	1.63
  +++ PersistenceBrokerImpl.java	28 Jan 2004 23:49:32 -0000	1.64
  @@ -61,7 +61,6 @@
   import java.util.Enumeration;
   import java.util.Iterator;
   import java.util.List;
  -import java.util.Vector;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
  @@ -200,7 +199,6 @@
           referencesBroker = new QueryReferenceBroker(this);
       }
   
  -
       public SqlGenerator serviceSqlGenerator()
       {
           return this.sqlGenerator;
  @@ -558,13 +556,13 @@
        * the member field containing the object reference if NOT null.
        *
        * @param obj Object which we will delete references for
  -     * @param vecRds vector of ObjectRederenceDescriptors
  +     * @param listRds list of ObjectRederenceDescriptors
        * @throws PersistenceBrokerException if some goes wrong - please see the error message
for details
        */
  -    private void deleteReferences(Object obj, Vector vecRds) throws PersistenceBrokerException
  +    private void deleteReferences(Object obj, List listRds) throws PersistenceBrokerException
       {
           // get all members of obj that are references and delete them
  -        Iterator i = vecRds.iterator();
  +        Iterator i = listRds.iterator();
           while (i.hasNext())
           {
               ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
  @@ -588,18 +586,18 @@
        * the member field containing the object reference if NOT null.
        *
        * @param obj Object which we will delete collections for
  -     * @param vecCds vector of ObjectReferenceDescriptors
  +     * @param listCds list of ObjectReferenceDescriptors
        * @throws PersistenceBrokerException if some goes wrong - please see the error message
for details
        */
  -    private void deleteCollections(Object obj, Vector vecCds) throws PersistenceBrokerException
  +    private void deleteCollections(Object obj, List listCds) throws PersistenceBrokerException
       {
           // get all members of obj that are collections and delete all their elements
  -        Iterator i = vecCds.iterator();
  -        
  +        Iterator i = listCds.iterator();
  +
           while (i.hasNext())
           {
               CollectionDescriptor cds = (CollectionDescriptor) i.next();
  -            
  +
               // if this is a m:n mapped table, remove entries from association table
               if (cds.isMtoNRelation())
               {
  @@ -613,7 +611,7 @@
               if (cds.getCascadeDelete())
               {
                   Iterator colIterator = null;
  -                
  +
                   try
                   {
                       Object col = cds.getPersistentField().get(obj);
  @@ -689,24 +687,25 @@
        * the member field containing the object reference is NOT null.
        *
        * @param obj Object which we will store references for
  -     * @param vecRds - Vector with all ObjectReferenceDescriptors that should be stored
  +     * @param listRds - List with all ObjectReferenceDescriptors that should be stored
        */
  -    private void storeReferences(Object obj, Vector vecRds)
  +    private void storeReferences(Object obj, List listRds)
       {
           // get all members of obj that are references and store them
  -        Iterator i = vecRds.iterator();
  +        Iterator i = listRds.iterator();
           while (i.hasNext())
           {
               ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
  -            Object ref = rds.getPersistentField().get(obj);
               if (rds.getCascadeStore())
               {
  +                Object ref = rds.getPersistentField().get(obj);
                   store(ref);
               }
               else
               {
  -                if(logger.isEnabledFor(Logger.INFO)) logger.info("Cascade store for this
reference-descriptor (" + rds.getAttributeName()
  -                        +") was set to false.");
  +                if(logger.isEnabledFor(Logger.INFO))
  +                    logger.info("Cascade store for this reference-descriptor ("
  +                            + rds.getAttributeName() +") was set to false.");
               }
           }
       }
  @@ -718,7 +717,7 @@
        * @param ref referenced object or proxy
        * @param rds
        */
  -    private void assertFkAssignment(Object obj, Object ref, ObjectReferenceDescriptor rds)
  +    private void assertFkAssignment(Object obj, Object ref, ObjectReferenceDescriptor rds,
boolean insert)
       {
           // BRJ: ensure real object
           Object realObj = ProxyHelper.getRealObject(obj);
  @@ -734,23 +733,36 @@
   
           // MBAIRD: we have 'disassociated' this object from the referenced object,
           // the object representing the ord is now null, so set the fk to null.
  +        // arminw: if an insert was done and ref object was null, we should allow
  +        // to pass FK fields of main object (maybe only the FK fields are set)
           if (ref == null)
           {
  -            refPkValues = null;
  +            if(!insert)
  +            {
  +                refPkValues = null;
  +                for (int i = 0; i < objFkFields.length; i++)
  +                {
  +                    objFkFields[i].getPersistentField().set(realObj, refPkValues != null
? refPkValues[i].getValue(): null);
  +                }
  +            }
  +            else
  +            {
  +                // We do nothing on insert, maybe only the FK fields of main object are
set
  +            }
           }
           else
           {
               // BRJ: ref may be Proxy
               Class refClass = ProxyHelper.getRealClass(ref);
               ClassDescriptor refCld = getClassDescriptor(refClass);
  -
               refPkValues = brokerHelper.getKeyValues(refCld, ref, false);
  +            for (int i = 0; i < objFkFields.length; i++)
  +            {
  +                objFkFields[i].getPersistentField().set(realObj, refPkValues != null ?
refPkValues[i].getValue(): null);
  +            }
           }
   
  -        for (int i = 0; i < objFkFields.length; i++)
  -        {
  -            objFkFields[i].getPersistentField().set(realObj, refPkValues != null ? refPkValues[i].getValue():
null);
  -        }
  +
       }
   
       /**
  @@ -760,13 +772,13 @@
        * the member field containing the object reference is NOT null.
        *
        * @param obj Object which we will store collections for
  -     * @param vecCds vector of ObjectRederenceDescriptors
  +     * @param listCds list of ObjectRederenceDescriptors
        * @throws PersistenceBrokerException if some goes wrong - please see the error message
for details
        */
  -    private void storeCollections(Object obj, Vector vecCds, boolean insert) throws PersistenceBrokerException
  +    private void storeCollections(Object obj, List listCds, boolean insert) throws PersistenceBrokerException
       {
           // get all members of obj that are collections and store all their elements
  -        Iterator i = vecCds.iterator();
  +        Iterator i = listCds.iterator();
   
           while (i.hasNext())
           {
  @@ -800,7 +812,7 @@
                       else
                       {
                           currentMtoNKeys = mtoNBroker.getMtoNImplementor(cds, obj);
  -                        
  +
                           if (col.getClass().isArray())
                           {
                               mtoNBroker.deleteMtoNImplementor(cds, obj, Arrays.asList((Object[])col),
currentMtoNKeys);
  @@ -841,7 +853,7 @@
                           {
                               // BRJ: do not assign fk if not required
                               // to avoid materialization of proxy
  -                            assertFkAssignment(otherObj, obj, cds);
  +                            assertFkAssignment(otherObj, obj, cds, insert);
                               store(otherObj);
                           }
                       }
  @@ -856,7 +868,7 @@
           }
       }
   
  -    
  +
       /**
        * Answer the Iterator for Collection or Array
        * @param cds
  @@ -1221,8 +1233,8 @@
       /**
        * returns an Enumeration of PrimaryKey Objects for objects of class DataClass.
        * The Elements returned come from a SELECT ... WHERE Statement
  -     * that is defined by the fields and their coresponding values of vecFields
  -     * and vecValues.
  +     * that is defined by the fields and their coresponding values of listFields
  +     * and listValues.
        * Useful for EJB Finder Methods...
        * @param primaryKeyClass the pk class for the searched objects
        * @param query the query
  @@ -1325,7 +1337,7 @@
        */
       private void storeToDb(Object obj, ClassDescriptor cld, Identity oid, boolean insert)
       {
  -        Vector ords = cld.getObjectReferenceDescriptors();
  +        List ords = cld.getObjectReferenceDescriptors();
   
           if (ords.size() > 0)
           {
  @@ -1333,7 +1345,7 @@
               storeReferences(obj, ords);
   
               // 2. assign fk of references
  -            assignReferenceFKs(obj, ords);
  +            assignReferenceFKs(obj, ords, insert);
           }
   
           Object[] pkValues = oid.getPrimaryKeyValues();
  @@ -1437,15 +1449,15 @@
        * 	assigns all foreign key attributes of the Object obj.
        *  used during store(obj, boolean);
        */
  -    private void assignReferenceFKs(Object obj, Vector vecRds) throws PersistenceBrokerException
  +    private void assignReferenceFKs(Object obj, List listRds, boolean insert) throws PersistenceBrokerException
       {
           // get all members of obj that are references and assign FKs
  -        Iterator i = vecRds.iterator();
  +        Iterator i = listRds.iterator();
           while (i.hasNext())
           {
               ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
               Object ref = rds.getPersistentField().get(obj);
  -            assertFkAssignment(obj, ref, rds);
  +            assertFkAssignment(obj, ref, rds, insert);
           }
       }
   
  
  
  

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