Using Drools 5.3.0.<br><br>I find that my "java" version produces three calls (one true, two false). This is my dialect "java" version of the first rule:<br><br>dialect "java"<br>rule "First Rule"<br>
when<br> $tf : TestFact(TestUtility.utilMethod($tf.getS(), "Value1") == true &&<br> i > 0<br> )<br> then<br> System.out.println("First Rule Fires");<br>
end<br><br>The MVEL version executes six (6) calls: two returning true, and four returning false. <br><br>-W<b><br></b><br><br><div class="gmail_quote">On 5 January 2012 14:55, ronalbury <span dir="ltr"><<a href="mailto:ronalbury@gmail.com">ronalbury@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">Here is a very simple test. Note that utilMethod is called twice for the<br>
first rule, but is never called for the other two rules. If you convert to<br>
Java dialect then things execute as expected.<br>
<br>
<br>
TestRules.drl:<br>
#created on: Jan 5, 2012<br>
package com.sample<br>
<br>
import com.sample.TestUtility;<br>
<br>
rule "First Rule"<br>
when<br>
$tf : TestFact(TestUtility.utilMethod(s, "Value1") == true<br>
&& i > 0<br>
)<br>
then<br>
System.out.println("First Rule Fires");<br>
end<br>
<br>
rule "Second Rule"<br>
when<br>
$tf : TestFact(TestUtility.utilMethod(s, "Value2") == true<br>
&& i > 0<br>
)<br>
then<br>
System.out.println("Second Rule Fires");<br>
end<br>
<br>
rule "Third Rule"<br>
when<br>
$tf : TestFact(TestUtility.utilMethod(s, "Value3") == true<br>
&& i > 0<br>
)<br>
then<br>
System.out.println("Third Rule Fires");<br>
end<br>
<br>
<br>
<br>
TestUtility.java:<br>
package com.sample;<br>
<br>
public class TestUtility {<br>
public static Boolean utilMethod(String s1, String s2) {<br>
Boolean result = null;<br>
<br>
if (s1 != null) {<br>
result = s1.equals(s2);<br>
}<br>
<br>
System.out.println("in utilMethod >" + s1 + "< >" + s2 + "< returns<br>
" + result);<br>
return result;<br>
}<br>
}<br>
<br>
TestDriver.java:<br>
public static final void main(String[] args) {<br>
try {<br>
// load up the knowledge base<br>
KnowledgeBase kbase = readKnowledgeBase();<br>
StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
<br>
// setup the debug listeners<br>
ksession.addEventListener(new DebugAgendaEventListener());<br>
ksession.addEventListener(new<br>
DebugWorkingMemoryEventListener());<br>
KnowledgeRuntimeLogger logger =<br>
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");<br>
<br>
// go !<br>
TestFact fact = new TestFact();<br>
fact.setS("asdf");<br>
fact.setI(10);<br>
ksession.insert(fact);<br>
ksession.fireAllRules();<br>
logger.close();<br>
}<br>
catch (Throwable t) {<br>
t.printStackTrace();<br>
}<br>
}<br>
<br>
<br>
Output:<br>
in utilMethod >asdf< >Value1< returns false<br>
in utilMethod >asdf< >Value1< returns false<br>
==>[ObjectInsertedEventImpl: getFactHandle()=[fact<br>
0:1:31556811:31556811:1:DEFAULT:com.sample.TestFact@1e184cb],<br>
getObject()=com.sample.TestFact@1e184cb,<br>
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@70610a,<br>
getPropagationContext()=PropagationContextImpl [activeActivations=0,<br>
dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact<br>
0:1:31556811:31556811:1:DEFAULT:com.sample.TestFact@1e184cb],<br>
leftTuple=null, originOffset=-1, propagationNumber=3, rule=null, type=0]]<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Error-in-MVEL-execution-optimization-tp3633440p3634884.html" target="_blank">http://drools.46999.n3.nabble.com/Error-in-MVEL-execution-optimization-tp3633440p3634884.html</a><br>
</font></span><div class="HOEnZb"><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>