On 3/9/07, Uday Kamath <UKamath(a)dharbor.com> wrote:
We had similar use case. What we do is we model the Schema elements,
generate Java Beans (pojo), and write rules using these Pojo. Now we have
written a Service on top which takes Hibernate QL and gets the database
records as the same Pojos that Rules are defined on and fire the Rules. Thus
the service is generic and can be changed to take any Query. The Rules can
me modified and changed anytime and redeployed but business objects in form
of Pojos remain the same. Hope this helps
-Uday
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of
Joe Chuby
Sent: Friday, March 09, 2007 3:53 AM
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Using rules with database scenario
Hi all,
First time trying to learn JBoss Rules here. We have a pretty large
database (DBMS), we want to build some rules and retrieve data based on the
rules.
Could someone give a hint or an example of this usage scenario? I mean, how
can I use rules for database query, without writing my rules in SQL
directly? We are currently writing everything in HQL (Hibernate), but the
rules change every 3 months on average, so that's not a way to maintain the
system. Therefore, we want to extract that portion of the business logic out
of the code. The data structure does not change, but the rules keep on
changing.
I'm reading the user's guide, running thru the examples, writing some of my
own, but still no clue how to make it work with database.
If someone could give a sample, that would be greatly appreciated.
Thanks a lot.
That's probably the best solution. Using the current version (3.1M1),
you can use the FROM keyword to reference facts from List object
returned from a method call on a service, for example.
Something like this works very good in my current testing project:
rule foobar
when
MyObject( someValue = "foobar" ) from MyObjectDAO.loadAll()
then
...
end
The DAO then uses Hibernate to load some objects and returns a
List<MyObject> which can be used by Drools.
As Uday already wrote, you could also write a DAO which retrieves
arbitrary objects using a given HQL statement.
Best regards
Marcus