Hi,<div>What Wolfgang is trying to say about "inform" the Drools engine about the update is that you need to use a modify statement in your RHS. Your rule should look like this:</div><div><br><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" color="#a00000" face="Courier New"><b>rule</b></font><font size="2" face="Courier New"> </font><font size="2" color="#008000" face="Courier New">"for E band"</font> <br>
<font size="2" face="Courier New"> </font><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">lock-on-active true</span><br><font size="2" face="Courier New"> </font><font size="2" color="#a00000" face="Courier New"><b>when</b></font> <br>
<font size="2" face="Courier New"> r : Rating( rate == 1)</font> <br><font size="2" face="Courier New"> </font><font size="2" color="#a00000" face="Courier New"><b>then</b></font> </span></div><div>
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> <span class="Apple-style-span" style="font-family: 'Courier New'; font-size: small; ">modify(r){</span><br>
<font size="2" face="Courier New"> setBand(</font><font size="2" color="#008000" face="Courier New">"EBand"</font><font size="2" face="Courier New">);</font></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" face="Courier New"></font> </span><span class="Apple-style-span" style="font-family: 'Courier New'; border-collapse: collapse; ">}</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> </span></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" face="Courier New"> System.out.println( </font><font size="2" color="#008000" face="Courier New">"in E band"</font><font size="2" face="Courier New"> ); </font><font size="2" face="Courier New"> </font><br>
<font size="2" color="#a00000" face="Courier New"><b>end</b></font> </span></div><div><br></div><div>This is the way to inform Drools that your Fact is modified. But be careful, because when you modify a Fact, all the rules are evaluated again because the modification could activate another Rule. This will end in an infinite loop (just like Wolfgang mentioned), the "for E band" rule will be executed for ever. That's why you need to add the no-loop attribute (if the only rule that modifies a Rating is "for E band") or lock-on-active (if more than one rule could modify a Rating). </div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br><div class="gmail_quote">On Mon, Mar 29, 2010 at 7:20 AM, Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">You have to inform the Drools engine about the update done with<br>
r.setBand("..."), or else the query condition is still seeing the fact<br>
state at insert time.<br>
<br>
You may have to add the no-loop option to your rules.<br>
<br>
(Also, comments and actions disagree, e.g. "D Band" vs. "EBand")<br>
<font color="#888888"><br>
-W<br>
</font><div><div></div><div class="h5"><br>
On 3/29/10, Nilima R <<a href="mailto:nilima.r@tcs.com">nilima.r@tcs.com</a>> wrote:<br>
> Dear All,<br>
><br>
> I have created simple rule file and created model in that rule file only<br>
><br>
> package com.sample<br>
><br>
> import java.lang.String;<br>
><br>
> declare Rating<br>
> rate : int<br>
> band : String<br>
> name : String<br>
> end<br>
><br>
> query "employee with band E"<br>
> ratg : Rating(band == "EBand")<br>
> end<br>
><br>
> rule "for E band"<br>
><br>
> when<br>
> r : Rating( rate == 1)<br>
> then<br>
> r.setBand("EBand");<br>
> System.out.println( "in E band" );<br>
><br>
> end<br>
><br>
> rule "for D band"<br>
><br>
> when<br>
> r : Rating( rate == 2)<br>
> then<br>
> r.setBand("EBand");<br>
> System.out.println( "in E band" );<br>
><br>
> end<br>
><br>
> rule "for C band"<br>
><br>
> when<br>
> r : Rating( rate == 3)<br>
> then<br>
> r.setBand("EBand");<br>
> System.out.println( "in E band" );<br>
><br>
> end<br>
><br>
> rule "for B band"<br>
><br>
> when<br>
> r : Rating( rate == 4)<br>
> then<br>
> r.setBand("EBand");<br>
> System.out.println( "in E band" );<br>
><br>
> end<br>
><br>
><br>
> At the end I want to know how many employees have got E band and so have<br>
> written query for it in the rule file .and obtained the query results as<br>
> below<br>
><br>
><br>
> FactType bandType = kbase.getFactType( "com.source", "Rating" );<br>
> QueryResults results = ksession.getQueryResults(<br>
> "employee with band E");<br>
> System.out.println( "we have " + results.size() +<br>
> "employee with band E" );<br>
> System.out.println( "employee with band E:" );<br>
><br>
> for (Iterator i = results.iterator();<br>
> i.hasNext();) {<br>
> QueryResultsRow row =<br>
> (QueryResultsRow)i.next();<br>
> Object ratg = row.get("rating");<br>
> String name = (String) bandType.get( ratg,<br>
> "name" );<br>
> System.out.println(name);<br>
> }<br>
><br>
><br>
> But am getting the result of query as 0 records.<br>
><br>
><br>
> i am inserting objects one by one ( this for testing just purpose ) to<br>
> learn how query works.<br>
><br>
><br>
> Can someone plz point out what is wrong.Its Urgent ................<br>
><br>
><br>
> Thanks in advance.<br>
> Nilu<br>
> =====-----=====-----=====<br>
> Notice: The information contained in this e-mail<br>
> message and/or attachments to it may contain<br>
> confidential or privileged information. If you are<br>
> not the intended recipient, any dissemination, use,<br>
> review, distribution, printing or copying of the<br>
> information contained in this e-mail message<br>
> and/or attachments to it are strictly prohibited. If<br>
> you have received this communication in error,<br>
> please notify us by reply e-mail or telephone and<br>
> immediately and permanently delete the message<br>
> and any attachments. Thank you<br>
><br>
><br>
><br>
</div></div><div><div></div><div class="h5">_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
</div>