[rules-users] setting global variables in session : the Command interface VS the RuleContext. What is the difference ?
bardelman
feki.ahmed.job at gmail.com
Mon Apr 23 05:01:47 EDT 2012
hi ,
i m new in drools, i m reading the Drools-JBoss-Rules-5.0-Developers-Guide
book in which i found a validation rule example on its chapter 3. In this
exemple, global variables were set into the session with two methods shown
in this code :
...
session = knowledgeBase.newStatelessKnowledgeSession();
session.setGlobal("reportFactory", reportFactory);
session.setGlobal("inquiryService", inquiryService);
...
and these variables qualified as immutables, were called from the
RuleContext
public static void error(RuleContext drools,
Object... context) {
KnowledgeRuntime knowledgeRuntime = drools
.getKnowledgeRuntime();
ValidationReport validationReport = (ValidationReport)
knowledgeRuntime.getGlobal("validationReport");
ReportFactory reportFactory = (ReportFactory)
knowledgeRuntime.getGlobal("reportFactory");
...
and for other variables(or facts ) the Command interface was used instead :
List<Command> commands = new ArrayList<Command>();
commands.add(CommandFactory.newSetGlobal(
"validationReport", report));
commands.add(CommandFactory
.newInsertElements(getFacts(customer)));
session.execute(CommandFactory
.newBatchExecution(commands));
i m looking for accuracy in understanding when and which to use each method.
thanks for help
--
View this message in context: http://drools.46999.n3.nabble.com/setting-global-variables-in-session-the-Command-interface-VS-the-RuleContext-What-is-the-difference-tp3931886p3931886.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list