Home

Castle Stronghold

Castle Project Forum Index Castle Project
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Incorporating NHibernate's subselect fetching strategy

 
Post new topic   Reply to topic    Castle Project Forum Index -> AR Usage
View previous topic :: View next topic  
Author Message
mattyr



Joined: 01 May 2007
Posts: 4
Location: California

PostPosted: Wed May 02, 2007 5:07 am    Post subject: Incorporating NHibernate's subselect fetching strategy Reply with quote

This may be more of a "wishlist" post, but I'm curious if anyone has though about this, or has a better approach for the goal I have in mind.

I'm converting an existing data layer to ActiveRecord. Before the conversion, we used multiple SQL select statements to populate various tables in the local recordset with related data (Order->OrderItems, for example). We could customize the subselect queries based upon user customizable search criteria (OrderItem contains Product "foo"). These queries can potentially return thousands of objects (rows) of various types. Each of the individual tables are rather large, so as we've transitioned to ActiveRecord we're finding that using fetching strategies that result in joins are far too inefficient to be effective. We'd also like to preload as many of the objects as possible, as cascading select statements for each item is also proving to perform poorly.

What I've found is that NHibernate (1.2) has incorporated a fetching strategy that closely replicates what we were doing using plain old ADO.NET. What I'm referring to is subselect, mentioned (albeit briefly) in the documentation here.

We're using activerecord built from trunk, and it does not appear to support this functionality. Does anyone know if there is a reason for this? I'm currently experimenting with the following changes in the trunk code:

\ActiveRecord\Castle.ActiveRecord\Attributes\Enums.cs (~ line 107):
Code:

   /// <summary>
   /// Define the possible fetch option values
   /// </summary>
   public enum FetchEnum
   {
      /// <summary>
      /// Let NHibernate decide what to do here
      /// </summary>
      Unspecified,
      /// <summary>
      /// Use a JOIN to load the data
      /// </summary>
      Join,
      /// <summary>
      /// Use a seperate SELECT statement to load the data
      /// </summary>
      Select,

      // This is the new part:
      SubSelect
   }


and, in \ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\XmlGenerationVisitor.cs (~ line 952):
Code:

      private static string TranslateFetch(FetchEnum fetch)
      {
         switch(fetch)
         {
            case FetchEnum.Select:
               return "select";
            case FetchEnum.Join:
               return "join";

            // This is the new part:
            case FetchEnum.SubSelect:
                    return "subselect";

            default:
               return null;
         }
      }


I'm curious if this strategy will work... I'm ashamed to admit I have not yet run through all of the unit tests with this patch, but I did want to hear some opinions before I delve into this any further.

I'd like to see the subselect fetching strategy incorporated into ActiveRecord, but is there a better place for this tag? I realize that this can't apply in some places where the FetchEnum can be used (BelongsToAttribute, for example), but NHibernate will quickly throw an exception if it's out of place.

Any thoughts would help. Particularly complaints, or examples of situations where this would fail or produce unintended results. I'm completely open to alternative approaches as well.

Thanks!
Back to top
View user's profile Send private message
hammett
Castle Team


Joined: 15 Apr 2006
Posts: 1739
Location: SP, Brasil

PostPosted: Wed May 02, 2007 12:22 pm    Post subject: Reply with quote

Send us a patch, please.
_________________
Cheers,
hammett
http://hammett.castleproject.org/
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Castle Project Forum Index -> AR Usage All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group