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/accesslayer MtoNCollectionPrefetcher.java
Date Thu, 14 Oct 2004 16:58:35 GMT
brj         2004/10/14 09:58:35

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        MtoNCollectionPrefetcher.java
  Log:
  fixed bug OJB296
  
  Revision  Changes    Path
  1.14      +51 -4     db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
  
  Index: MtoNCollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MtoNCollectionPrefetcher.java	11 Aug 2004 18:57:16 -0000	1.13
  +++ MtoNCollectionPrefetcher.java	14 Oct 2004 16:58:35 -0000	1.14
  @@ -27,6 +27,7 @@
   import org.apache.ojb.broker.IdentityFactory;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -48,7 +49,7 @@
    */
   public class MtoNCollectionPrefetcher extends CollectionPrefetcher
   {
  -
  +                         
       /**
        * @param aBroker the PersistenceBroker
        * @param anOrd the CollectionDescriptor
  @@ -356,14 +357,53 @@
       }
   
       /**
  +     * Answer the FieldConversions for the PkFields 
  +     * @param cld
  +     * @return the pk FieldConversions
  +     */
  +    private FieldConversion[] getPkFieldConversion(ClassDescriptor cld)
  +    {
  +        FieldDescriptor[] pks = cld.getPkFields();
  +        FieldConversion[] fc = new FieldConversion[pks.length]; 
  +        
  +        for (int i= 0; i < pks.length; i++)
  +        {
  +            fc[i] = pks[i].getFieldConversion();
  +        }
  +        
  +        return fc;
  +    }
  +    
  +    /**
  +     * Convert the Values using the FieldConversion.sqlToJava
  +     * @param fcs
  +     * @param values
  +     * @return
  +     */
  +    private Object[] convert(FieldConversion[] fcs, Object[] values)
  +    {
  +        Object[] convertedValues = new Object[values.length];
  +        
  +        for (int i= 0; i < values.length; i++)
  +        {
  +            convertedValues[i] = fcs[i].sqlToJava(values[i]);
  +        }
  +
  +        return convertedValues;
  +    }
  +    
  +    /**
        * associate the batched Children with their owner object loop over children
        * <br><br>
        * BRJ: There is a potential problem with the type of the pks used to build the Identities.
        * When creating an Identity for the owner, the type of pk is defined by the instvars

        * representing the pk. When creating the Identity based on the mToNImplementor the
        * type of the pk is defined by the jdbc-type of field-descriptor of the referenced
class.
  -     * This type mismatch results in Identities not being equal. <br>
  -     * Integer[] {10,20,30} is not equal Long[] {10,20,30}
  +     * This type mismatch results in Identities not being equal.
  +     * Integer[] {10,20,30} is not equal Long[] {10,20,30} 
  +     * <br><br>
  +     * This problem is documented in defect OJB296. 
  +     * The conversion of the keys of the mToNImplementor should solve this problem.
        */
       protected void associateBatched(Collection owners, Collection children, Collection
mToNImplementors)
       {
  @@ -376,7 +416,10 @@
           Class collectionClass = cds.getCollectionClass(); // this collection type will
be used:
           HashMap childMap = new HashMap();
           HashMap ownerIdsToLists = new HashMap();
  +        FieldConversion[] ownerFc = getPkFieldConversion(getOwnerClassDescriptor()); 
  +        FieldConversion[] childFc = getPkFieldConversion(getItemClassDescriptor());  
   
  +        
           // initialize the owner list map
           for (Iterator it = owners.iterator(); it.hasNext();)
           {
  @@ -403,6 +446,10 @@
               System.arraycopy(mToN, 0, ownerPk, 0, ownerPkLen);
               System.arraycopy(mToN, ownerPkLen, childPk, 0, childPkLen);
   
  +            // BRJ: apply the FieldConversions, OJB296
  +            ownerPk = convert(ownerFc, ownerPk);
  +            childPk = convert(childFc, childPk);
  +            
               Identity ownerId = idFactory.buildIdentity(null, ownerTopLevelClass, ownerPk);
               Identity childId = idFactory.buildIdentity(null, childTopLevelClass, childPk);
   
  
  
  

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