[jboss-jira] [JBoss JIRA] Updated: (JBRULES-532) Query feature doesnt seem to work if there is more than one query.

Claumir Santos (JIRA) jira-events at jboss.com
Fri Nov 3 18:54:41 EST 2006


     [ http://jira.jboss.com/jira/browse/JBRULES-532?page=all ]

Claumir Santos updated JBRULES-532:
-----------------------------------

    Attachment: rules.zip

I built the source in the trunk and the bug continues there...    Please, try run this samples... 

> 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