[rules-users] Drools - Query Problem

Wolfgang Laun wolfgang.laun at gmail.com
Mon Mar 29 06:20:09 EDT 2010


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 at 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
>
>
>



More information about the rules-users mailing list