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

elsdestickere elsdestickere at yahoo.com
Mon Oct 31 10:05:23 EDT 2011


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.



More information about the rules-users mailing list