Not really. Without modifying the objects you could do this outside the rules
using a WorkingMemoryEventListener, which has objectInserted() and
objectUpdated() methods. Event if you can modify the DataObject to add an "I'm
a new object" flag, and set it immediately on insertion, then you could do
differentiate with two rules:
rule "identify new DATAOBJECT"
when
do : DataObject(n00b == true);
then
do.setN00b(false);
update(do);
System.err.println("DataObject assertion detected: " + do);
end
rule "identify modified DATAOBJECT"
when
do : DataObject(n00b == false);
then
System.err.println("DataObject modification detected: " + do);
end
Which would still catch a spurious modification notification on assert! At
that point the semi-risky alternative is to not call update() in the "identify
new DATAOBJECT" rule action. That way, the "identify modified DATAOBJECT" is
not immediately activated, but it would be activated the next time update() is
called on the object. I say semi-risky because it's not often a good idea to
put a WM object into a state that the rete is not aware of, but in this case it
would do what you want.
--- On Wed, 9/16/09, Chris Richmond <[email protected]> wrote:
> From: Chris Richmond <[email protected]>
> Subject: [rules-users] determining what field changed
> To: "'Rules Users List'" <[email protected]>
> Date: Wednesday, September 16, 2009, 2:41 PM
>
> Is it possible
> to determine what fields from an object
> changed within a rule.
>
> So I am using
> this to determine if any DataObject has
> changed:
>
> //IDENTIFY ANY DATAOBJECT
> CHANGES
>
> rule
> "identify any DATAOBJECT"
> when
> $do :
> DataObject();
> then
> System.err.println("ANY
> DataObject change detected:" + $do);
> End
>
> However this
> also fires when any new DataObject() is
> injected into the system and the rules are fired. I
> would like to be able to
> only have a rule fire when an object is first
> created
>
> Vs. when it is
> modified and is there a way to detect what
> values of an object have changed if I don’t
> explicitly know what fields
> of DataObject changed ahead of time?
>
> Thanks,
> Chris
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users