[rules-users] rule evaluation during insert

Mauricio Salatino salaboy at gmail.com
Sun Jul 10 23:28:20 EDT 2011


Yes you should update the fact. Using ksession.update() method.
Take a look at the insert method that returns the FactHandle that you need
to use later in order to update the fact.
Cheers

2011/7/10 Neelesh Deo Dani <neeleshdev at yahoo.co.in>

> Hi,
>
> I'm using drools expert. When I insert the User object again in the
> session, after modifying the member variable 'trades' (details mentioned
> below) the rule doesn't get evaluated. It evaluate the rules only during the
> 1st insert. Is there a way to trigger the rule evaluation after every insert
> of the same object (when state is modified)?
>
>
>  I've following declaration and rule.
>
> ------------
>
> declare User
>
>     @timestamp(datetime)
>
>     name : String
>
>     trades: Integer
>
> end
>
>
> rule "Trades"
>
> when
>
>     $u:User(trades >= 3)
>
> then
>
>     System.out.println("Trades > 3 for "+ $u.getName());
>
> end
>
> ----------
>
> Following is the piece of code:
>
>
> StatefulKnowledgeSession session = s.kbase.newStatefulKnowledgeSession();
>
> String[] names = new String[]{"bob", "sam", "john"};
>
> FactType userType = s.kbase.getFactType("com.sample", "User" );
>
>
> Map<String, Object> name2user = new HashMap<String, Object>();
>
> for( String name: names ){
>
> Object u = userType.newInstance();
>
> userType.set(u, "name", name);
>
> name2user.put(name, u);
>
> }
>
>
> userType.set(name2user.get("bob"), "trades", 1);
>
> session.insert(name2user.get("bob"));
>
> session.fireAllRules();
>
>
> userType.set(name2user.get("bob"), "trades", 3);
>
> session.insert(name2user.get("bob"));
>
> // this insert doesn't evaluate the rule and hence the
>
> // condition $u:User(trades >= 3) is not checked
>
>
> session.fireAllRules();
>
>
>
> Thanks & Regards,
>
> Neelesh
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
 - CTO @ http://www.plugtree.com
 - MyJourney @ http://salaboy.wordpress.com
 - Co-Founder @ http://www.jbug.com.ar

 - Salatino "Salaboy" Mauricio -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110711/a4ee9e44/attachment.html 


More information about the rules-users mailing list