Hi,
What's the goal of that rule?
If you have a Driver called Jack you create a new Driver called TOTO.
Now you have two facts.
You can create a query in your DRL file like:
query getAllDrivers()
$driver: Driver()
end
and then call that query from your code to get all the Driver facts that
were inserted in the working memory.
Check the documentation in the query section to see how to execute a query
from java code.
Cheers
On Tue, Dec 4, 2012 at 11:03 AM, Mister Nono <noel.maurice(a)univ-jfc.fr>wrote:
Hi,
I have the drools rule (made in guvnor server) :
1. | rule "driverRule"
2. | salience 10
3. | dialect "mvel"
4. | when
5. | Driver( driverAge : age > 18 && < 65 )
6. | then
7. | Driver fact0 = new Driver();
8. | fact0.setName( "TOTO" );
9. | insert( fact0 );
10. | end
... and the java code source :
KnowledgeAgent agent =
KnowledgeAgentFactory.newKnowledgeAgent("/Guvnor.properties");
KnowledgeBase ruleBase = agent.getKnowledgeBase();
StatefulKnowledgeSession workingMemory =
ruleBase.newStatefulKnowledgeSession();
Driver d = new Driver("Jack", 28, null);
workingMemory.insert(d);
workingMemory.fireAllRules();
for(Iterator i = workingMemory.getObjects().iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(obj.getClass().getCanonicalName());
if (obj instanceof Driver)
{
System.out.println("Driver name => " +
((Driver)obj).getName());
System.out.println("Driver age => " +
((Driver)obj).getAge());
}
}
But the drools rule changes the driver name "Jack" by "TOTO", but in
the
console the initial name "Jack" is always displayed.
How to access at the objet who is in knowledge base (the modified objet) ?
Thank. ;)
--
View this message in context:
http://drools.46999.n3.nabble.com/To-access-at-the-fact-object-tp4021064....
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
- MyJourney @
http://salaboy.wordpress.com
- Co-Founder @
http://www.jugargentina.org
- Co-Founder @
http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -