Hello all,
Currently I'm starting to study hibernate and trying to build a generic DAO on top of it. One of the methods of this DAO is responsible for looking up objects. It gets a simple JavaBean as a parameter, based on the class of this bean, gets a HQL query from a property file, uses bean's properties as parameters for this query and executes this query using a hibernate session. This is simple and is working well.
My problem is that I'm trying to go a little futher. I'm trying to put a flag ( e.g. {} ) on these queries to mark some parts of the where clause as optional. These parts would be used if corresponding properties are set in the bean that is received as method's parameter.
For example, I would like to have something like this in my property file:
mypackage.MyJavaBean=from Item item where item.description like :searchString
and { item.date > :minDate }
When the generic method responsible for executing queries receives an instance of mypackage.MyJavaBean as parameter it has to get this query from the property file and, if minDate property of that bean has a value other than null, item.date > :minDate is used in the query. Otherwise that part of the query is cropped.
To do something like that I have do build a parser... I was thinking of using hibernate's parser instead. As far as I could see it seems that it is suffering some modifications, isn't it? Does anyone has other ideas?
Thanks a lot and sorry about this long mail.
Best regards,
F
|