org.apache.ojb.broker.accesslayer
Class MtoNCollectionPrefetcher

java.lang.Object
  extended by org.apache.ojb.broker.accesslayer.BasePrefetcher
      extended by org.apache.ojb.broker.accesslayer.RelationshipPrefetcherImpl
          extended by org.apache.ojb.broker.accesslayer.CollectionPrefetcher
              extended by org.apache.ojb.broker.accesslayer.MtoNCollectionPrefetcher
All Implemented Interfaces:
RelationshipPrefetcher

public class MtoNCollectionPrefetcher
extends CollectionPrefetcher

Relationship Prefetcher for MtoN-Collections.

Version:
$Id: MtoNCollectionPrefetcher.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
Author:
Jakob Braeuchi

Field Summary
 
Fields inherited from class org.apache.ojb.broker.accesslayer.BasePrefetcher
IN_LIMIT, itemClassDesc, pkLimit
 
Constructor Summary
MtoNCollectionPrefetcher(PersistenceBrokerImpl aBroker, ObjectReferenceDescriptor anOrd)
           
 
Method Summary
protected  void associateBatched(Collection owners, Collection children, Collection mToNImplementors)
          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.
protected  Query[] buildMtoNImplementorQueries(Collection owners, Collection children)
          Build the multiple queries for one relationship because of limitation of IN(...)
protected  Query buildMtoNImplementorQuery(Collection ids)
          Build a query to read the mn-implementors
protected  Query buildPrefetchQuery(Collection ids)
          Build the prefetch query for a M-N relationship, The query looks like the following sample :
 void prefetchRelationship(Collection owners)
          Prefetch the Relationship for the owners (the 1 side of a 1:n)
 
Methods inherited from class org.apache.ojb.broker.accesslayer.CollectionPrefetcher
associateBatched, buildPrefetchQueries, createCollection, getCollectionDescriptor
 
Methods inherited from class org.apache.ojb.broker.accesslayer.RelationshipPrefetcherImpl
getObjectReferenceDescriptor, getOwnerClassDescriptor, isCascadeRetrieve, prepareRelationshipSettings, restoreRelationshipSettings, setCascadeRetrieve, setObjectReferenceDescriptor
 
Methods inherited from class org.apache.ojb.broker.accesslayer.BasePrefetcher
buildPrefetchCriteria, buildPrefetchQuery, buildPrefetchQuery, getBroker, getDescriptorRepository, getItemClassDescriptor, getLimit, getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MtoNCollectionPrefetcher

public MtoNCollectionPrefetcher(PersistenceBrokerImpl aBroker,
                                ObjectReferenceDescriptor anOrd)
Parameters:
aBroker - the PersistenceBroker
anOrd - the CollectionDescriptor
Method Detail

prefetchRelationship

public void prefetchRelationship(Collection owners)
Description copied from interface: RelationshipPrefetcher
Prefetch the Relationship for the owners (the 1 side of a 1:n)

Specified by:
prefetchRelationship in interface RelationshipPrefetcher
Overrides:
prefetchRelationship in class BasePrefetcher
See Also:
RelationshipPrefetcher.prefetchRelationship(Collection)

buildPrefetchQuery

protected Query buildPrefetchQuery(Collection ids)
Build the prefetch query for a M-N relationship, The query looks like the following sample :
       crit = new Criteria();
       crit.addIn("PERSON_PROJECT.PROJECT_ID", ids);
       crit.addEqualToField("id","PERSON_PROJECT.PERSON_ID");
       qry = new QueryByMtoNCriteria(Person.class, "PERSON_PROJECT", crit, true);
 

Overrides:
buildPrefetchQuery in class CollectionPrefetcher
Parameters:
ids - Collection containing all identities of objects of the M side
Returns:
the prefetch Query

buildMtoNImplementorQuery

protected Query buildMtoNImplementorQuery(Collection ids)
Build a query to read the mn-implementors

Parameters:
ids -

buildMtoNImplementorQueries

protected Query[] buildMtoNImplementorQueries(Collection owners,
                                              Collection children)
Build the multiple queries for one relationship because of limitation of IN(...)

Parameters:
owners - Collection containing all objects of the ONE side

associateBatched

protected void associateBatched(Collection owners,
                                Collection children,
                                Collection mToNImplementors)
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 problem is documented in defect OJB296. The conversion of the keys of the mToNImplementor should solve this problem.



Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.