[rules-users] Simple rule and Query

Wolfgang Laun wolfgang.laun at gmail.com
Thu Apr 14 03:34:26 EDT 2011


This seems to be fixed for 5.2.x.:

declare Num
  num : Integer
end

rule sort
when
    Integer( $i: intValue )
then
    insert( new Num( $i ) );
end

query numbers
    $a: Num( $b: num )
end


    QueryResults qRes = session.getQueryResults( "numbers" );
    System.out.println( "result count: " + qRes.size() );
    for( QueryResultsRow row: qRes ){
        Object obj = row.get( "$b" );
    System.out.println( "$b=" + obj.toString() );
    }

This produces the expected results.

Calling getQueryResults with a string not denoting an existing query returns
an empty result set. I've updated the javadoc - thanks.

-W





2011/4/14 DECOUX Yannick <yannick.decoux at ucm.be>

> query numbers
>     $a: Num( $b: num )
> end
> Hi everyone,
>
>
>
> I’am still stuck with this simple example, anyone can tell me where to
> look or what I’m missing ?
>
>
>
> Thanks
>
> Yannick
>
>
>
>
>
> *De :* DECOUX Yannick [mailto:yannick.decoux at ucm.be]
> *Envoyé :* mardi 5 avril 2011 07:52
> *À :* rules-users at lists.jboss.org
> *Objet :* [rules-users] Simple rule and Query
>
>
>
> Hi,
>
>
>
> I’am trying to use Query and i’am facing a little problem :
>
> Given this simple rule :
>
>
>
> *package* be.test.person
>
> *import* be.test.person.*
>
>
>
> *query* "get adult"
>
>       adult : Adult( )
>
> *end*
>
>
>
> *query* "get person"
>
>       person : Person( )
>
> *end*
>
>
>
> *declare* Adult
>
>       name : String
>
> *end*
>
>
>
> *rule* "A person over 18 is an adult"
>
>       *when*
>
>             Person( age >= 18)
>
>       *then*
>
>             System.out.println("Adult detected");
>
>             *insert*(*new* Adult());
>
> *end*
>
> * *
>
> Lets suppose one Person over 18 is inserted inside the working memory, the
> result of the query « get adult » is 0 (Please note the declaration of Adult
> type inside the rule)
>
> If I create a Java class Adult (commenting the one in the .drl file) and
> then run the query again, this time the result is 1
>
> Also, the signature of
> org.drools.runtime.rule.WorkingMemory.getQueryResults(String) says
> IllegalArgumentException when query is not found in the KnowledgeBase. This
> doesn’t seems to be the case when I use a fake query name.
>
> I’am using drools 5.1.1
>
>
>
> Any idea on this ?
>
>
>
> Thanks
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110414/00d2253b/attachment.html 


More information about the rules-users mailing list