[rules-users] Identity, equality, hashing and indexing

Bruno Freudensprung bruno.freudensprung at temis.com
Wed Dec 8 09:00:04 EST 2010


Hi,

I have some existential questions about Drools Expert's magic :-).

When reading the documentation it is clear that, by default, facts are 
stored in an IdentityHashMap. If I understand things correctly it means 
that the objects I put in the working memory don't have to implement the 
hashCode() and equals() method. They should implement them only if I 
tell Drools to use the "equality mode".

So here is my first question: in equality mode, if a fact field is used 
by the hashCode method, and if that field is modified by a rule action, 
should I expect a weird behavior since facts are stored in a HashMap?

When digging into rules-users' archives I also found posts of Mark 
Proctor, talking about field indexing and alpha node hashing, that lead 
to my second question: should I expect a weird behavior if 2 fields are 
related to each other?
For instance (not a good example but it gives an idea): a Person type 
has a getFirstName() method, a getLastName() method and a getName() 
method that return the concatenation of getFirstName() and getLastName().
Is it problematic if one rule has a "Person(name == "John Doe")" fact in 
its LHS and if another rule modifies the "firstName" of that Person fact 
(John -> Jane)?
Does it depend on the equality vs. identity mode (I don't think so... 
unless the field itself is a also a fact)?

Many thanks in advance for your answers,
Best regards,

Bruno.





More information about the rules-users mailing list