[rules-users] Update vs insert

Anstis, Michael (M.) manstis1 at ford.com
Thu Sep 11 06:55:00 EDT 2008


What version of Drools are you using?
 
Pre-5 has "Shadow Facts" so you can't rely upon pass-by-reference. I
believe 5 has had Shadow Facts removed.
 
Insert places a new object into WM whereas update refreshes (the shadow)
of an existing one.
 
I would expect you to have to use update in your example:-
 
rule "Add person to math class" 
    no-loop 
        when 
            person : Person(likesMath == true) 
        then 
            person.setClassName("Math"); 
            update(person); 
    end 
 
rule "And now, time for something completely different" 
    no-loop 
        when 
            person : Person(likesMath == true) 
        then 
            PreferredClass p = new PreferredClass("Math");
            p.setPerson(person);
            insert(p); 
    end 
 
 
Cheers,
 
Mike


________________________________

	From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Shyam, Pallav
(MSCIBARRA)
	Sent: 11 September 2008 11:40
	To: rules-users at lists.jboss.org
	Subject: Re: [rules-users] Update vs insert
	
	

	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 at 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 at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org
<mailto:rules-users-bounces at lists.jboss.org> ] On Behalf Of
thomaskukofka at web.de

	Sent: Wednesday, September 10, 2008 2:27 PM 
	To: rules-users at 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 at 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080911/07866a47/attachment.html 


More information about the rules-users mailing list