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 Ron Gallagher <rg...@bellsouth.net> on 2003/07/09 20:41:46 UTC

Patch for prefetched relationships

I've started investigating the use of 'prefetched relationships' as a way to improve the performance of the application I'm working on.  My approach works something like this:

* I created a 'generic' QueryCustomizer.  The single purpose of this customizer is to add prefetched relationships to the query.

* In the collection-descriptor for a class (ie. com.rgi.Parent), I identify my Customizer in a query-customizer element.  I also include an 'attribute' element that identifies the relationships that should be prefetched.

Here are the basics from my repository.  (Note: field-descriptors and inverse-foreignkey entries have been removed for brevity.)

<class-descriptor class="com.rgi.Parent" table="parent">
  <collection-descriptor element-class-ref="com.rgi.Child1" name="child1List">
    <query-customizer class="com.rgi.Customizer"/>
    <attribute attribute-name="prefetch" attribute-value="child1aList,child1bList"/>
  </collection-descriptor>
</class-descriptor>

<class-descriptor class="com.rgi.Child1" table="child1">
  <collection-descriptor element-class-ref="com.rgi.Child1a" name="child1aList">
    <query-customizer class="com.rgi.Customizer"/>
    <attribute attribute-name="prefetch" attribute-value="child4List"/>
  </collection-descriptor>
  <collection-descriptor element-class-ref="com.rgi.Child1b" name="child1bList">
  </collection-descriptor>
</class-descriptor>

<class-descriptor class="com.rgi.Child1a" table="child1a">
  <collection-descriptor element-class-ref="com.rgi.Child4" name="child4List">
  </collection-descriptor>
</class-descriptor>

<class-descriptor class="com.rgi.Child1b" table="child1b">
</class-descriptor>

<class-descriptor class="com.rgi.Child4" table="child4">
</class-descriptor>


When the customizeQuery method on my Customizer is called, it simply gets the value of the "prefetch" attribute and adds those relationships to the list of prefetched relationships on the query that is passed to the method.

This works perfectly!!

However, I want to extend this concept another layer down in my hierarchy. In other words, when the 'child1aList' list on the 'Parent' class is populated, I want to go ahead and preload the 'child4List' on each instance of 'Child1a' that's in the list.  The query-customizer and attribute elements are there.  They're just not being used.

The 'problem' appears to be in the buildPrefetchQuery method in o.a.o.b.accesslayer.CollectionPrefetcher.  Even though the collection-descriptor is available to this object, it is not utlizing the QueryCustomizer that may be defined.  It makes sense to me to allow for query customizations at this point.  The only issue with this is that for most customizations, the 'parent' object is a single object.  In this situation, the 'parent' object is a Collection of objects, not a single object.

I've attached to this email an update and diff for o.a.o.b.accesslayer.CollectionPrefetcher that provides for this capability.  I've also included an update and diff for o.a.o.b.accesslayer.RelationshipPrefetcherImpl to deal with the possibility that a query could be null after customization.

If you feel these updates are appropriate, please include them in the code base.

Ron Gallagher
Atlanta, GA
rongallagher@bellsouth.net