简体   繁体   中英

Insert Keyword in Decision Table

I am new to Drools, and going through an existing use case where the action contains the insert($param) or insert(new Object($param)) , i could not find the functionality of this keyword and the scope of this and how this is getting utilized further conditions.

Any response or documentation on this would help. I could not find this on any documentation.

I strongly recommend you to read the official documentation here: https://docs.drools.org/8.32.0.Final/drools-docs/docs-website/drools/rule-engine/index.html

The conditions of the rules in Drools are applied to "Facts" present in a KieSession . These "Facts" are nothing but Java objects. If you want to make an object a "Fact" then you have to insert it into the KieSession . Otherwise Drools will not know about its presence and no rules will be applied to it.

So, for example, if you have the following rule in your KieSession :

rule "Adult Person"
    Person(age >= 18)
then
    //do something
end

The Person pattern is making reference to a Java class named "Person". In Java, if you want to make a Person instance available to the KieSession you will need to do something like this:

Person person = new Person();
person.setAge(33); // up to this point, Drools is not aware of this object

kieSession.insert(person); //here we are telling Drools that the `person` object is a Fact and that the rules have to be evaluated for it.

In you case, the insert function is being called as part of the action of you rules and not straight from Java, but the idea is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM