Here is a twist.
If I call "update($fact)" explicitly in the rule, the rule is NOT called twice.
Can someone point me to the code used by "update($fact)"? Maybe I can figure
out what I did wrong to cause the rule to fire incorrectly a second time.
Jason Smith
________________________________________
From: rules-users-bounces(a)lists.jboss.org [rules-users-bounces(a)lists.jboss.org] On Behalf
Of Jason Smith [jsmith(a)infotrustgroup.com]
Sent: Friday, November 27, 2009 9:54 AM
To: Rules Users List
Subject: [rules-users] Updates with property change on facts. How???
I implemented the following listener for my bean and I am calling .update() directly on
the StatefulKnowledgeSession.
QUESTION 1: Is there a better way? The old API supported .insert(fact,boolean). The new
one does not. I am not finding any documentation that explains the new API (version
5.0.1).
QUESTION 2: Why is this calling my rule twice? The rule is getting called twice, and the
second time it's called, the entry conditions are invalid! That is, I changed the
bean in a way that invalidates the WHEN condition. The rule still gets called twice.
How do I even begin to go about troubleshooting this? This same behavior was happening
with Drools 4 and the old API as well.
private class InnerPropertyChangeListener implements PropertyChangeListener
{
private final InternalFactHandle factHandle;
private final Object fact;
private final StatefulKnowledgeSession session;
public InnerPropertyChangeListener(InternalFactHandle factHandle, Object fact,
StatefulKnowledgeSession session)
{
this.factHandle = factHandle;
this.fact = fact;
this.session = session;
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
System.out.println("****** UPDATING " + evt.getPropertyName() + ":
" +
"\n NEW: " +
StringUtil.indent(BeanUtil.printObject(evt.getNewValue()),16) +
"\n OLD: " +
StringUtil.indent(BeanUtil.printObject(evt.getOldValue()),16));
if((evt.getNewValue() == null && evt.getOldValue() != null) ||
!evt.getNewValue().equals(evt.getOldValue()))
{
session.update(factHandle, fact);
}
}
}
Jason Smith
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users