On 2012-02-08 17:21, juanita wrote:
Here is what I have implemented so far:
----------------------
     public class ColorHqlGenerator : BaseHqlGeneratorForProperty
     {
         public ColorHqlGenerator()
         {
             SupportedProperties = new[]
             {
                 ReflectionHelper.GetProperty((Color x) =>  x.Red),
                 ReflectionHelper.GetProperty((Color x) =>  x.Green),
                 ReflectionHelper.GetProperty((Color x) =>  x.Blue)
             };
         }

         public override HqlTreeNode BuildHql(MemberInfo member,
Expression expression, HqlTreeBuilder treeBuilder,
IHqlExpressionVisitor visitor)
         {
             .... now what .... ???
         }
     }
--------------------------
The issue is with implementing the BuildHql method. I have pretty much
no idea what would need to be done here to have NHibernate finally
execute a SQL statement with ... where color='FF00FF'.

Note that merging the three where parts for the individual properties
(red, green, blue) into a single SQL where is highly desirable so that
the database can make use of an index on the column.
I understand that an edge case would be if the query had values only
for 2 or 1 of the color constituents. While this will not actually
happen in my case, an acceptable solution would be to assume the
missing constituents as 0.

What I am confused about in the few other examples I have seen is that
the HqlGenerator seems to make no use of the IUserType's methods to
convert between database and object representation at all.

I've got no direct experience with the BuildHql() method, but there's really only one thing this method needs to do:

  1. traverse the incoming Expression
  2. find all parts referencing a Color
  3. collect this data to build (one or more) comparisons
  4. pass this on to the treeBuilder
  5. probably modify the expression to not contain the Color references

If the incoming queries have a fixed form, you can probably take many shortcuts over parsing a generic query.

Methodically, I'd recommend getting the NHibernate source for the release you're working on, and break into the BuildHql method with the debugger of your choice and poke around in the interfaces and data structures you're receiving.


Good Hunting, David

--
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to