Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-2733

Support MVEL Dialect using custom inline accumulate code with external declarations in the executable model

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Optional Optional
    • None
    • None
    • executable model
    • None

      The executable model doesn't support custom inline accumulate code that uses external declarations such as

            String str = "import " + Person.class.getCanonicalName() + ";\n" +
                      "rule R dialect \"mvel\" when\n" +
                      "  String( $l : length )" +
                      "  $sum : Integer() from accumulate (\n" +
                      "            Person( age > 18, $age : age ), init( int sum = 0 * $l; ), action( sum += $age; ), reverse( sum -= $age; ), result( sum )\n" +
                      "         )" +
                      "then\n" +
                      "  insert($sum);\n" +
                      "end";
      

      (Notice that in the init we multiply the sum value with the length of string)

      But it can support such style using the "classic" generation of accumulate classes which gets compiled among the executable model and instantiate during the execution of the DSL.

      This mechanism is broken with the MVEL dialect, as we don't have such generated classes.

      Probably what we should do instead is putting MVEL expressions in the DSL directly such as

      accumulateScript("initCode", "accCode", "reverseCode");
      

      and then during interpretation create a new MVEL context and execute the accumulate in memory

      See
      AccumulateUnsupportedTest.testMVELAccumulate
      AccumulateUnsupportedTest.testMVELAccumulate2WM

            lmolteni@redhat.com Luca Molteni
            lmolteni@redhat.com Luca Molteni
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: