[rules-users] setting global variables in session : the Command interface VS the RuleContext. What is the difference ?

Ahmed Feki feki.ahmed.job at gmail.com
Mon Apr 23 05:00:20 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120423/b7c51bd4/attachment.html 


More information about the rules-users mailing list