java - Loading and updating rules from a database in Drools 6 -
how 1 go loading rules database table @ startup , updating them same table in drools 6.2.0? i've found example using drools 5 convert scala java looks api has changed pretty drastically... don't see rulebasefactory class, example.
any sample or documentation appreciated.
i'm not sure org.dools.rulebasefactory taken. below how done in drools 5.3 (and possibly earlier) 5.6:
knowledgebuilder kbuilder = knowledgebuilderfactory.newknowledgebuilder(); kbuilder.add( ..., resourcetype.drl); if( kbuilder.haserrors() ){ system.err.println( "### compilation errors ###" ); knowledgebuildererrors errors = kbuilder.geterrors(); for( knowledgebuildererror err: errors ){ system.err.println( err.tostring() ); } throw new illegalstateexception( "compile errors" ); } knowledgebase kbase = kbuilder.newknowledgebase(); statelessknowledgesession ksession = kbase.newstatelessknowledgesession();
the ellipsis indicates place inserting data holding rule text. check api suitable types; java.lang.string should acceptable.
this way use 6.2:
kieservices kieservices = kieservices.factory.get(); kiefilesystem kfs = kieservices.newkiefilesystem(); kfs.write( "src/main/resources/simple.drl", ... ); kiebuilder kiebuilder = kieservices.newkiebuilder( kfs ).buildall(); results results = kiebuilder.getresults(); if( results.hasmessages( message.level.error ) ){ system.out.println( results.getmessages() ); throw new illegalstateexception( "### errors ###" ); } kiecontainer kiecontainer = kieservices.newkiecontainer( kieservices.getrepository().getdefaultreleaseid() ); kiebase kiebase = kiecontainer.getkiebase(); kiesession = kiecontainer.newkiesession();
Comments
Post a Comment