即使规则被激发,也无法更新事实



我已经实现了构建器设计模式,并且我对抽象类有条件,并且希望更新扩展抽象类的事实。虽然规则被解雇了,但它没有更新事实为什么?

DRL

rule "Rule_1"
when
$a : AnotherClas.Builder()
$b : AnotherClas(definitionName = "test") from $a.build
then
$b.setUpdateFact("updated");

end

JAVA类

public abstract class TestClass{
public final String definitionName;
protected TestClass(String definitionName) {
this.definitionName = definitionName;
}
}

另一个JAVA类

public class AnotherClass extends TestClass{
private String updateFact;
private TestClass(String reviewDefinitionName) {
super(reviewDefinitionName);
}
public void setUpdateFact(String updateFact) {
this.updateFact= updateFact;
}

public void getUpdateFact() {
return updateFact;
}
public static class Builder {
private String definitionName;

public TestClass build() {
return new TestClass(definitionName);
}
public Builder definitionName(String definitionName) {
this.definitionName = definitionName;
return this;
} 
}
}

我缺什么了吗?请帮我找出实现的正确方法

您的方法AnotherClass.Builder.build()正在创建一个未插入工作内存或DataSource的对象的新实例。这就是为什么modify的调用不会对任何效果进行排序的原因。

首先,您将$a绑定到一个静态生成器:

$a : AnotherClas.Builder()

则在from $a.build中调用该方法:

public ReviewBatchConfig build() {
return new ReviewBatchConfig(definitionName);
}

正如上面的实现所示,它没有插入WM/DS中,因此缺少API要求。

在调用规则引擎API之前,您可以考虑在代码中使用构建器模式,一旦从构建器模式中了解了代码中的所有对象,就可以将它们插入WM/DS并调用规则引擎规则。

最新更新