Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to express one object is null when I use drools rule engine

I want to know how can I express one object is null on the left hand side when I use drools rule engine? And anybody can tell me how to use the drools keyword "not" and so on.Thank you!

like image 294
SnowQin Avatar asked Jan 22 '14 09:01

SnowQin


People also ask

How do you call one rule from another rule in Drools?

Well, the answer is we can't call a Rule from another Rule. Drools matches the Rules with incoming data/facts, and if the data satisfies the Rule condition, it stores the data in an Agenda. It might be possible for the same data or facts to be matched by different rules, so it stores matching facts in an Agenda.

How do you use salience in Drools?

Setting a PrioritySalience is a keyword in the . drl file that we can assign a positive or negative number. The number determines the salience priority. A higher number denotes a higher priority, so rules with a higher salience will be executed first by the Drools engine.

What is .DRL file in Java?

A DRL file can contain one or more rules that define at minimum the rule conditions ( when ) and actions ( then ). The DRL designer in Decision Central provides syntax highlighting for Java, DRL, and XML. All data objects related to a DRL rule must be in the same project package as the DRL rule in Decision Central.


2 Answers

You can call not in when clause to check for null objects:

rule "somerule"
    no-loop
    when not AnObject()
    then
      // rule body when AnObject is null
end;
like image 103
anubhava Avatar answered Oct 10 '22 17:10

anubhava


Drools is built on top of Java, so there is an instance of the object (which may or may not have null properties) or there is not. If the object is a 'fact' in working memory, then it is not null and your LHS should instead be determining whether it exists:

exists MyObject()
not exists MyObject()

However if you are trying to find facts with null properties, you can do this:

obj: MyObject(myProperty == null)
like image 32
Steve Avatar answered Oct 10 '22 17:10

Steve