[rules-users] variable instance check?
Edson Tirelli
tirelli at post.com
Thu Oct 18 17:14:40 EDT 2007
Eric,
For now, the way to do identity checks is to use an inline eval:
when
$a : Fact()
$b : Fact( eval( $a == $b ) )
then
// $a and $b are identical
end
[]s
Edson
2007/10/18, Eric Miles <eric.miles at kronos.com>:
>
> In java, I can check to see if a 2 variables references the same
> instance as such:
>
> Object a = new Object();
> Object b = a;
>
> a == b
>
>
>
>
> Is there a way to do this in Drools? For instance, if there is an
> object in working memory and it is a specific instance, I do not want to
> fire the rule again. ie:
>
> rule "User Lookup UserKey"
> salience 10000
> when
> com.kronos.taws.model.User(empId == null, $key:empIdKey)
> then
> System.out.println("Firing 2!");
> insert($key);
>
> end
>
> I want to ensure that $key is not already in working memory. But mind
> you, there might be other $keys that are in working memory that do not
> belong to this particular com.kronos.taws.model.User instance. I do not
> want this rule to fire because I have subsequent rules that will make
> empId a value other than null.
>
> I attempted to do this:
>
> rule "User Lookup UserKey"
> when
> com.kronos.taws.model.User(empId == null, $key:empIdKey)
> not UserKey(this == $key)
> then
> System.out.println("Firing 2!");
> insert($key);
>
> end
>
> However, I still think this is doing an equality check because once the
> $key object is updated in another rule, this rule is fired again!
>
> Thanks in advance!
> Eric
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071018/5bd958ab/attachment.html
More information about the rules-users
mailing list