本文介绍了已弃用的drools代码到6.2版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的和已删除的drools代码,此代码可以读取容器外的规则文件(drl),并且可以使用任何Value Object和任何类。

I have an old and deprectaed code of drools, this code can read a rule file (drl) outside of the container and can use any Value Object and any class.

            CommandExecutor ksession;
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            String file = System.getenv("DOMAIN_HOME")+"/mydrls/business.drl";
            kbuilder.add(ResourceFactory.newFileResource(file), ResourceType.DRL);
            KnowledgeBase kbase = kbuilder.newKnowledgeBase();
            ksession = kbase.newStatelessKnowledgeSession();
            DataTest data = new DataTest();
            data.setAge(25);
            List cmds = new ArrayList();
            cmds.add( CommandFactory.newInsert( data ) );
            ksession.execute(CommandFactory.newBatchExecution( cmds ));

我如何使用drools版本6.2做同样的事情?

How I can do the same thing but with drools version 6.2?

推荐答案

您可以使用KieHelper类简化Laune的代码:

You can simplify Laune's code by using the KieHelper class:

KieHelper kieHelper = new KieHelper();
kieHelper.addResource(ResourceFactory.newInputStreamResource(new FileInputStream( "simple/simple.drl" )), ResourceType.DRL);

Results results = kieHelper.verify();
if( results.hasMessages( Message.Level.ERROR ) ){
    System.out.println( results.getMessages() );
    throw new IllegalStateException( "### errors ###" );
}

StatelessKieSession kieSession = kieHelper.build().newStatelessKieSession();

希望有所帮助。

这篇关于已弃用的drools代码到6.2版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:41