]
Luca Molteni commented on DROOLS-2733:
--------------------------------------
This could also be fixed by the mvel to java compiler
Support MVEL Dialect using custom inline accumulate code with
external declarations in the executable model
-----------------------------------------------------------------------------------------------------------
Key: DROOLS-2733
URL:
https://issues.jboss.org/browse/DROOLS-2733
Project: Drools
Issue Type: Feature Request
Components: executable model
Reporter: Luca Molteni
Assignee: Luca Molteni
Priority: Optional
The executable model doesn't support custom inline accumulate code that uses external
declarations such as
{code:java}
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";
{code}
(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
{code:java}
accumulateScript("initCode", "accCode", "reverseCode");
{code}
and then during interpretation create a new MVEL context and execute the accumulate in
memory
See
AccumulateUnsupportedTest.testMVELAccumulate
AccumulateUnsupportedTest.testMVELAccumulate2WM