I've just managed to get incremental compilation working, was actually quite a small change. This means that you set a RuleBase on a PackageBuilder and it'll update the RuleBase ass you add drls to it - it avoids the creation and merging of a temporary Package, which was needed for shell environments.

I've also updated drools-clips to support deftemplates via the ClassBuilder, so it generates internal pojos underneath. I've updated the unit test to show this working, as the class is internal to Drools I had to use reflection to instantiate the facts :)

I'll commit this tomorrow, once I've improved it further.

   public void testTemplateCreation() throws Exception {
this.shell.eval( "(deftemplate Person (slot name (type String) ) (slot age (type int) ) )" );

this.shell.eval( "(defrule yyy => (printout t yy \" \" (eq 1 1) ) ) )" ); this.shell.eval( "(defrule xxx (Person (name ?name&bob) (age 30) ) (Person (name ?name) (age 35)) => (printout t xx \" \" (eq 1 1) ) )" );

       WorkingMemory wm = shell.getStatefulSession();
Class personClass = this.shell.getStatefulSession().getRuleBase().getPackage( "MAIN" ).getPackageScopeClassLoader().loadClass( "MAIN.Person" ); Method nameMethod = personClass.getMethod( "setName", new Class[] { String.class } ); Method ageMethod = personClass.getMethod( "setAge", new Class[] { int.class } ); Object bob1 = personClass.newInstance();
       nameMethod.invoke( bob1, "bob" );
       ageMethod.invoke( bob1, 30 );
wm.insert( bob1 );
       Object bob2 = personClass.newInstance();
       nameMethod.invoke( bob2, "bob" );
ageMethod.invoke( bob2, 35 );
       wm.insert( bob2 );
wm.fireAllRules();
       assertEquals( "yy truexx true",
new String( this.baos.toByteArray() ) ); }
_______________________________________________
rules-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-dev

Reply via email to