[rules-users] rule evaluation during insert
Neelesh Deo Dani
neeleshdev at yahoo.co.in
Sun Jul 10 22:58:38 EDT 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110711/d0fde7d3/attachment.html
More information about the rules-users
mailing list