I agree that update is the proper route to take. This question is more
about my understanding of drools. My theory was insert would work as
long as my hashcode and equals methods are overriden correctly, which I
believe I have done. Since that didn't work, I thought there was
something fundemental about drools that I didn't understand.
My first assumption was something with shadow facts was causing my
problems. I am using Drools 5 and another user, Micheal, mentioned
Drools 5 does not use shadow facts. If that's the case I am further
confused as to why it didn't work.
Below is the code I am using. It's a pretty simple use case. In the
code, I pull the fact out of working memory before I run the query, and
look at the class name. Its been updated properly(i.e it equals Math),
but the query still doesn't return the Person fact. Is there something
about the query that relies on a property change listener firing before
it will re-analyze working memory to get results.
String name = "Dan";
Person daniel = new Person(name, "M", 29);
daniel.setLikesMath(true);
Person Chris = new Person("Chris", "M", 34);
Chris.setLikesMath(true);
Person Debbie = new Person("Deb", "F", 34);
Debbie.setLikesMath(false);
FactHandle danielHandle = DroolsUtil.insertOrUpdate(daniel);
DroolsUtil.insertOrUpdate(Chris);
DroolsUtil.insertOrUpdate(Debbie);
DroolsUtil.fireAllRules();
Person extractedDaniel =
(Person)DroolsUtil.getObject(danielHandle);
// This line prints out Math
System.out.println("Dans class: " +
extractedDaniel.getClassName());
List<Person> students =
(List<Person>)DroolsUtil.getQueryResults("getPeopleForClass",
"Math");
DroolsUtil.fireAllRules();
System.out.println("Number of students: " + students.size());
Thanks again for any help.
Daniel Quinn
Fedex - Custom Critical
Software Specialist I
234.310.4090(x2586)
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Ingomar Otter
Sent: Thursday, September 11, 2008 6:53 AM
To: Rules Users List
Subject: Re: [rules-users] Update vs insert
Ehm, I would think that unless person implements a
PropertyChangeListener, you need to tell the engine about the change of
the slot.
Update would be the proper way AFAIK.
In this case, I don't see why one would want to insert an object into
WM - as it is already in WM.
I think the exact result of the insert depends on whether you have
implemented equals/hashCode properly.
But again, in that example I understand that you want to change the
property of an object you have matched in the LHS.
The way to do this is using update().
-- Ingomar
Am 11.09.2008 um 12:39 schrieb Shyam, Pallav (MSCIBARRA):
Very strange. The facts are passed into the WM by-reference.
Therefore the query should work after calling the
person.setClassName("Math") on the fact. And this should work without
calling the insert or update.
This leaves me guessing that the query does not work on the facts
directly, instead they work on shadow facts.
________________________________
From: rules-users-bounces(a)lists.jboss.org
To: Rules Users List
Sent: Thu Sep 11 04:41:37 2008
Subject: [rules-users] Update vs insert
Hello,
What is the difference between calling insert and update in a rule
file? When I use insert my queries don't work, but if I use update
they seem to. I don't mind using update, but I would like to
understand the difference between the two. Here is my rule file.
rule "Add person to math class"
no-loop
when
person : Person(likesMath == true)
then
person.setClassName("Math");
insert(person);
end
I also have a query:
query getPeopleForClass(String _className)
Person(className == _className)
end
When I add two facts to working memory, where the likesMath
attribute is true, then run my query I get zero results back. When I
change the rule, "Add person to math class", to use update(person)
instead of insert(person) two students are returned.
Any help would be appreciated.
Thanks,
Dan
Daniel Quinn
Fedex - Custom Critical
Software Specialist I
234.310.4090(x2586)
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org
<mailto:rules-users-bounces@lists.jboss.org> ] On Behalf Of
thomaskukofka(a)web.de
Sent: Wednesday, September 10, 2008 2:27 PM
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Re: looping problem
Hello,
thanks that works. I just forgot to set the focus in the init rule..
Regards
Thomas
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
<
https://lists.jboss.org/mailman/listinfo/rules-users
>
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender.
Sender does not intend to waive confidentiality or privilege. Use of
this email is prohibited when received in error.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users