Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 24889 invoked from network); 14 Oct 2004 16:58:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 14 Oct 2004 16:58:36 -0000 Received: (qmail 77512 invoked by uid 500); 14 Oct 2004 16:58:23 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 77382 invoked by uid 500); 14 Oct 2004 16:58:22 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 77329 invoked by uid 500); 14 Oct 2004 16:58:22 -0000 Received: (qmail 77267 invoked by uid 99); 14 Oct 2004 16:58:21 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 14 Oct 2004 09:58:20 -0700 Received: (qmail 24690 invoked by uid 1513); 14 Oct 2004 16:58:19 -0000 Date: 14 Oct 2004 16:58:19 -0000 Message-ID: <20041014165819.24689.qmail@minotaur.apache.org> From: brj@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer MtoNCollectionPrefetcher.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N brj 2004/10/14 09:58:19 Modified: src/java/org/apache/ojb/broker/accesslayer Tag: OJB_1_0_RELEASE MtoNCollectionPrefetcher.java Log: fixed bug OJB296 Revision Changes Path No revision No revision 1.12.2.1 +49 -3 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.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- MtoNCollectionPrefetcher.java 11 Jun 2004 18:49:09 -0000 1.12 +++ MtoNCollectionPrefetcher.java 14 Oct 2004 16:58:19 -0000 1.12.2.1 @@ -26,6 +26,7 @@ import org.apache.ojb.broker.Identity; 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; @@ -353,14 +354,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 *

* 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.
- * 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} + *

+ * 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) { @@ -372,6 +412,8 @@ 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();) @@ -398,6 +440,10 @@ Object[] mToN = (Object[]) it.next(); 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 = new Identity(null, ownerTopLevelClass, ownerPk); Identity childId = new Identity(null, childTopLevelClass, childPk); --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org