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

10,698

Solution 1

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;

Solution 2

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)
Share:
10,698

Related videos on Youtube

SnowQin
Author by

SnowQin

Updated on June 04, 2022

Comments

  • SnowQin
    SnowQin about 2 years

    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!

  • SnowQin
    SnowQin over 10 years
    Thank you for your replied,and could you tell me how to express an object is null ,just like this code:Object object = new Object(); but object's properties is null,I want to express object is null,so how can I express ? Thank you,could you write an detail example ,Thank you!
  • laune
    laune over 10 years
    This code is incomplete - there is no definition for "anObject".
  • SnowQin
    SnowQin over 10 years
    could you tell me your contact method, and may I make friends with you?
  • anubhava
    anubhava over 10 years
    What I have in my answer now is correct. Yes you can connect with me on LinkedIn. I have provided details on my profile.