[rules-dev] is there a way to get "declare"s out of the working memory?

Edson Tirelli ed.tirelli at gmail.com
Fri Oct 16 19:41:20 EDT 2009


http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/html_single/index.html#d0e3614

http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java

 public void testGeneratedBeans1()


   Edson

2009/10/16 leif hanack <leif.hanack at hypoport.de>

> Hi,
> since Drools 5 it is possible to define a dynamic variable holder by
> using the declare notation. This feature is really cool.
> I can create easily helper rules, that calculate temporary values:
>
> File: calculate_total_amount.drl
>
> declare TotalAmount
>  amount : Money
> end
>
> rule "calculate total amount"
>  when
>    ..
>  then
>    TotalAmount totalAmount = new TotalAmount();
>    totalAmount.setAmount($calculatedAmount);
>    insert(totalAmount);
> end
>
> Inside another file I use this helper.
>
> File: another_rule.drl
>
> rule "another rule"
>  when
>    TotalAmount( amount > 1000)
>  then
>     // do s.th.
> end
>
> I unit test my rule by querying a fact and verify my assertions. This
> works fine, as long as the fact is a class of my factmodel.
> Now my question: Is there a way to query a declared class (in this
> case TotalAmount)
>
> I tried it with some variations but without success:
>
> import my.package.of.the.rule;
> query "get total amount"
>  amount : TotalAmount()
> end
>
> I thought that a declare is compiled to a class, but I can not find it
> in the generated classes.
> Did you have any help?
>
> An alternative might be to create a holder class. S.th. like that
>
> rule "calculate total amount"
>  ..
>  then
>    TotalAmount totalAmount = new TotalAmount();
>    totalAmount.setAmount($calculatedAmount);
>    insert(totalAmount);
>    Holder holder = new Holder();
>    holder.setObject(totalAmount);
>    insert(holder);
> end
>
>
> import my.package.holder;
> query "get holder"
>  holder : Holder()
> end
>
> Thanks in advance, Leif
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>



-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20091016/fcea38c3/attachment.html 


More information about the rules-dev mailing list