You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2004/10/14 18:58:19 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer MtoNCollectionPrefetcher.java
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
* <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)
{
@@ -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