[jboss-jira] [JBoss JIRA] Commented: (JBRULES-532) Query feature doesnt seem to work if there is more than one query.
Edson Tirelli (JIRA)
jira-events at jboss.com
Mon Nov 6 08:23:41 EST 2006
[ http://jira.jboss.com/jira/browse/JBRULES-532?page=comments#action_12346306 ]
Edson Tirelli commented on JBRULES-532:
---------------------------------------
Claumir,
I downloaded and unzipped your sample file, imported into eclipse as a project and executed the program and the result is this:
------------------
a 1
b 1
Hello World
Goodbye cruel world
------------------
As you can see it is working fine.
My guess is that you are using and old JBRules eclipse plugin. It is important to note that the eclipse plugin is bundled with drools-core and drools-compile jars (as well as all other dependencies), and when you run the project inside eclipse, it will use those jar as default classpath.
Would you please run this same sample outside eclipse using current jar files, or, manually set the current jar files in your project classpath inside eclipse in order to check it is indeed a classpath problem you are facing?
Updating your eclipse plugin for the latest version is also an option.
Thank you
Edson
> Query feature doesnt seem to work if there is more than one query.
> ------------------------------------------------------------------
>
> Key: JBRULES-532
> URL: http://jira.jboss.com/jira/browse/JBRULES-532
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Reporter: Sridhar Chandrasekharan
> Assigned To: Edson Tirelli
> Fix For: 3.0.5
>
> Attachments: rules.zip
>
>
> Consider the following:-
> *******************************************************************************
> 1) Foo.java
> package com.foo;
> public class Foo {
> private int a;
> private int b;
> public Foo(int a, int b) {
> super();
> this.a = a;
> this.b = b;
> }
> public boolean test()
> {
> return (a > b);
> }
> public int getA() {
> return a;
> }
> public int getB() {
> return b;
> }
>
> }
> *******************************************************************************************
> 2) FooTest.java
> package com.foo;
> import java.io.InputStreamReader;
> import java.io.*;
> import java.util.*;
>
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.WorkingMemory;
> import org.drools.compiler.PackageBuilder;
> import org.drools.rule.Package;
> import org.drools.QueryResults;
> import org.drools.QueryResult;
> public class FooTest {
>
>
> /**
> * This is a sample file to launch a rule package from a rule source file.
> */
> public static final void main(String[] args) {
> try {
>
> //load up the rulebase
> RuleBase ruleBase = readRule();
> WorkingMemory workingMemory = ruleBase.newWorkingMemory();
>
> //go !
>
> workingMemory.fireAllRules();
> QueryResults results = workingMemory.getQueryResults( "Foo query" );
> if(results == null)
> {
> System.out.println("Result is null");
> return;
> }
> System.out.println( "we have " + results.size() );
> for ( Iterator it = results.iterator(); it.hasNext(); ) {
> QueryResult result = ( QueryResult ) it.next();
> Foo foo = ( Foo ) result.get( "foo" );
> System.out.println( "A="+foo.getA() + " B=" + foo.getB());
> }
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> /**
> * Please note that this is the "low level" rule assembly API.
> */
> private static RuleBase readRule() throws Exception {
> //read in the source
> Reader source = new InputStreamReader( FooTest.class.getResourceAsStream( "/Foo.drl" ) );
>
> //optionally read in the DSL (if you are using it).
> //Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
> //Use package builder to build up a rule package.
> //An alternative lower level class called "DrlParser" can also be used...
>
> PackageBuilder builder = new PackageBuilder();
> //this wil parse and compile in one step
> //NOTE: There are 2 methods here, the one argument one is for normal DRL.
> builder.addPackageFromDrl( source );
> //Use the following instead of above if you are using a DSL:
> //builder.addPackageFromDrl( source, dsl );
>
> //get the compiled package (which is serializable)
> Package pkg = builder.getPackage();
>
> //add the package to a rulebase (deploy the rule package).
> RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> ruleBase.addPackage( pkg );
> return ruleBase;
> }
>
> }
> **************************************************
> 3) Foo.drl
> #created on: Oct 9, 2006
> package com.foo
> rule "Initialization rule"
> when
> #conditions
> then
> assert(new Foo(1,1));
> assert(new Foo(2,1));
> assert(new Foo(2,3));
> assert(new Foo(3,2));
> assert(new Foo(3,4));
> assert(new Foo(4,3));
> end
>
> query "Foo query"
> foo : Foo()
> end
> ****************************************
> The output is as follows:-
> we have 6
> A=1 B=1
> A=2 B=1
> A=2 B=3
> A=3 B=2
> A=3 B=4
> A=4 B=3
> *****************************************
> Now add another query to the Foo.drl file
> query "Bar query"
> foo : Foo()
> end
> and the output is
> Result is null
> Adding a second query caused the first query to stop working properly.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list