Hi,
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:

rule "for E band" 
        lock-on-active true
        when 
                r : Rating( rate == 1) 
        then 
                                modify(r){
                   setBand("EBand");
                                } 
                System.out.println( "in E band" );                 
end 

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).  

On Mon, Mar 29, 2010 at 7:20 AM, Wolfgang Laun <wolfgang.laun@gmail.com> wrote:
You have to inform the Drools engine about the update done with
r.setBand("..."), or else the query condition is still seeing the fact
state at insert time.

You may have to add the no-loop option to your rules.

(Also, comments and actions disagree, e.g. "D Band" vs. "EBand")

-W

On 3/29/10, Nilima R <nilima.r@tcs.com> wrote:
> Dear All,
>
> I have created simple rule file and created model in that rule file only
>
> package com.sample
>
> import java.lang.String;
>
> declare Rating
> rate : int
> band : String
> name : String
> end
>
> query "employee with band E"
> ratg : Rating(band == "EBand")
> end
>
> rule "for E band"
>
>         when
>                 r : Rating( rate == 1)
>         then
>                 r.setBand("EBand");
>                 System.out.println( "in E band" );
>
> end
>
> rule "for D band"
>
>         when
>                 r : Rating( rate == 2)
>         then
>                 r.setBand("EBand");
>                 System.out.println( "in E band" );
>
> end
>
> rule "for C band"
>
>         when
>                 r : Rating( rate == 3)
>         then
>                 r.setBand("EBand");
>                 System.out.println( "in E band" );
>
> end
>
> rule "for B band"
>
>         when
>                 r : Rating( rate == 4)
>         then
>                 r.setBand("EBand");
>                 System.out.println( "in E band" );
>
> end
>
>
> At the end I want to know how many employees have got E band and so have
> written query for it in the rule file .and obtained the query results as
> below
>
>
> FactType bandType = kbase.getFactType( "com.source", "Rating" );
>                         QueryResults results = ksession.getQueryResults(
> "employee with band E");
>                         System.out.println( "we have " + results.size() +
> "employee with band E" );
>                         System.out.println( "employee with band E:" );
>
>                         for (Iterator i = results.iterator();
> i.hasNext();) {
>                             QueryResultsRow row =
> (QueryResultsRow)i.next();
>                             Object ratg = row.get("rating");
>                             String name = (String) bandType.get( ratg,
> "name" );
>                             System.out.println(name);
>                          }
>
>
> But am getting the result of query as 0 records.
>
>
> i am inserting objects one by one ( this for testing just purpose ) to
> learn how query works.
>
>
> Can someone plz point out what is wrong.Its Urgent ................
>
>
> Thanks in advance.
> Nilu
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti