[rules-users] global as link to DB: different results

Michael Anstis michael.anstis at gmail.com
Mon Oct 31 14:47:12 EDT 2011


Hmmmm... this may be the way it works, but it's not clear from the
documentation-

"The Conditional Element from enables users to specify an arbitrary source
for data to be matched by LHS patterns. This allows the engine to reason
over data not in the Working Memory. The data source could be a sub-field
on a bound variable or the results of a method call. It is a powerful
construction that allows out of the box integration with other application
components and frameworks. One common example is the integration with data
retrieved on-demand from databases using hibernate named queries."

I therefore assume "...or the results of a method call" should mean "...or
the results of a method call on a Fact" and the following should work:-

rule "dao"
  when
    $cs : CustomerRepository( )
    k : Customer(  ) from $cs.getCustomerService().findAll()
  then
    System.out.println( "Drools "+drools.getRule().getName()+": "
+k.getName());
end

?

2011/10/31 Wolfgang Laun <wolfgang.laun at gmail.com>

> If the "donator" isn't a fact, it's not visible to the engine.
>
> Globals are OK on the RHS and as a provider for constant (!) data used as
> stand-in for literals on the LHS. Other than this: beware!
>
> -W
>
>
>
> 2011/10/31 Michael Anstis <michael.anstis at gmail.com>
>
>> I thought use of the "from" keyword allowed you to reason over facts
>> (potentially) not in WM. I believe the OP's example is mentioned in the
>> docs?
>>
>> sent on the move
>>
>> On 31 Oct 2011 15:08, "Wolfgang Laun" <wolfgang.laun at gmail.com> wrote:
>>
>>> Globals cannot to be used - directly or indirectly - as objects that
>>> should trigger
>>> the firing of rules. It is only insert, modify or update, and retract
>>> that cause (re-)evaluation of LHS conditions.
>>>
>>> -W
>>>
>>>  On 31 October 2011 15:05, elsdestickere <elsdestickere at yahoo.com>wrote:
>>>
>>>> Hi,
>>>>
>>>> I read docs about global and Hibernate to access your DB from the rules.
>>>> I tried something simular for in memory DAO's.
>>>> But some rules fire ("WM" in RHS) as the DAO has 3 items, but others
>>>> ("dao"
>>>> in LHS) don't, how is that possible?
>>>>
>>>> global RepositoryFactory repFact;
>>>> rule "dao"
>>>>    when
>>>>       k : Customer(  ) from repFact.getCustomerRepository().findAll();
>>>>    then
>>>>        System.out.println( "Drools "+drools.getRule().getName()+": "
>>>> +k.getName());
>>>> end
>>>> rule "WM"
>>>>    when
>>>>       k : Customer(  ) ;
>>>>    then
>>>>        System.out.println( "Drools "+drools.getRule().getName()+": "
>>>> +k.getName()+" + size:
>>>> "+repFact.getCustomerRepository().findAll().size());
>>>> end
>>>> ...
>>>> RepositoryFactory repFact = Registry.getRepositoryFactory();
>>>> ksession.setGlobal("repFact", repFact);
>>>> ...
>>>> CustomerRepository customerRepo = Registry.getRepositoryFactory()
>>>>                                .getCustomerRepository();
>>>> customerRepo.add(tom);
>>>> customerRepo.add(elise);
>>>> customerRepo.add(bert);
>>>> ksession.insert(bert);
>>>> ksession.fireAllRules();
>>>>
>>>> ...
>>>> Output:
>>>> Drools WM: Bert + size: 3
>>>>
>>>> br,
>>>> Els
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://drools.46999.n3.nabble.com/global-as-link-to-DB-different-results-tp3467897p3467897.html
>>>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111031/1b3f3ebc/attachment.html 


More information about the rules-users mailing list