在我的规则执行期间,我将在内存中“插入”新的事实对象,当规则完成触发时我需要读取它。在规则会议之外,我如何阅读这些事实?
我试图从会话外部(即在“fireAllRules()”方法之前)插入带有 outIdentifier 的事实。但是,因为我可能不知道在规则会话期间可能会插入多少个 AccountingPeriod 事实,或者即使它会被插入,所以这种方法似乎不合适。
会计期间事实:
package sample.package;
public class AccountingPeriod {
private LocalDate accountingDate;
private int personKey;
public AccountingPeriod(LocalDate accountingDate, int personKey) {
this.accountingDate = accountingDate;
this.personKey = personKey;
}
public LocalDate getAccountingDate() { return accountingDate; }
public LocalDate getPersonKey() { return personKey; }
}
执行代码:
sample.package;
public static void main(String args[]) {
StatelessKieSession ksession = [initialized KieSession]
ksession.execute(Arrays.asList(Facts[]));
[Code here to get the AccountingPeriod fact inserted in the rule session]
}
我的规则.drl
rule
when [some condition]
then
insert (new AccountingPeriod(LocalDate.of(year, month, day), 100));
end