How to load Drools Rule From DB -
i trying load drool rule file database. how can fire rule?
kbuilder.add( resourcefactory.newclasspathresource("myrule.drl"), resourcetype.drl );
provide content of rule db (jdbc etc.) , store in variable. (before kie drools) in kbuilder.
string rulecontent; // fill db in diffrent method/aspect knowledgebase kbase = knowledgebasefactory.newknowledgebase(); knowledgebuilder kbuilder = knowledgebuilderfactory.newknowledgebuilder(); resource r = resourcefactory.newreaderresource((reader) new stringreader(rulecontent)); kbuilder.add(dsl, resourcetype.drl); if (kbuilder.haserrors()) { log.error(kbuilder.geterrors().tostring()); } kbase.addknowledgepackages(kbuilder.getknowledgepackages()); statefulknowledgesession ksession = kbase.newstatefulknowledgesession(); // prepare fact object ksession.insert(factobject); ksession().fireallrules()
Comments
Post a Comment