Drools:在数据库中存储规则 [英] Drools: storing rules in database

查看:864
本文介绍了Drools:在数据库中存储规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我将所有规则文件存储在文件系统上(它们的版本很多),并在启动时将它们的不同版本加载到内存中。我想更改为将drools文件存储在数据库中,并且想知道Drools是否有任何解决方案或附加程序可以简化此操作,还是我应该自己制作?

Currently I store all rules files on the file system (there are lots of versions of them) and load the different versions of them into memory at startup. I would like to change to storing my drools files in a database and was wondering if there is any solution or addon to Drools which facilitates this or should I craft my own?

谢谢。

推荐答案

是的,可以做到。您所需要的就是获得 InputStream 的能力。在我的情况下,我使用自己的JPA类 RulePackage 来保存规则源作为byte [],但是您可以使用直接JDBC连接来访问数据库模式中的BLOB / CLOB字段。重要的是还要保存存储的规则源的类型,在构建规则包时将需要它:

Yes, it can be done. All you need is the ability to get InputStream.In my case I use my own JPA class RulePackage to persist rule source as byte[], but you could use direct JDBC connection to access BLOB/CLOB fields in your DB schema. Important thing is to save also type of stored rule source, it will be needed when building rule packages:

switch(rulePackage.getRuleSourceType()) {
  case DRL:
    kbuilder.add( ResourceFactory.newByteArrayResource(rulePackage.getSource()), ResourceType.DRL);
    break;
  case EXCEL:
    kbuilder.add( ResourceFactory.newByteArrayResource(rulePackage.getSource()), ResourceType.DTABLE, excelConfig);
    break;
  case CSV:
    kbuilder.add( ResourceFactory.newByteArrayResource(rulePackage.getSource()), ResourceType.DTABLE, csvConfig);
    break;
  default:
    throw new Exception("Rule package '" + rulePackage.getName() + "' has unknown type");
}

如果更适合您的情况,可以考虑使用newInputStreamResource方法:

You could consider using newInputStreamResource method if more applicable in your case:

   case DRL:
    kbuilder.add( ResourceFactory.newInputStreamResource(new StringInputStream(myDrlAsString)), ResourceType.DRL);
    break;

   case DRL:
    kbuilder.add( ResourceFactory.newInputStreamResource(new ByteArrayInputStream(myDrlAsByteArr)), ResourceType.DRL);
    break;

类似的东西。

这篇关于Drools:在数据库中存储规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆