[rules-users] Error in MVEL execution (optimization?)

Wolfgang Laun wolfgang.laun at gmail.com
Thu Jan 5 11:53:47 EST 2012


Below is a self-contained DRL showing the effect. Please note that the
dialect rule attribute isn't really important. If you use "$p.getName()" to
retrieve the name, the call is made once; as soon as you use just "name",
the matchXXX is called twice.

To run, compile, create a session, fireAllRules.

-W

package mvelmvel;

declare Person
   name: String
   age:  int
end

function boolean matchJava(String s1, String s2){
    System.out.println( "matchJava: " + s1 + "==" + s2 );
    return s1.equals( s2 );
}
function boolean matchMVEL(String s1, String s2){
    System.out.println( "matchMVEL: " + s1 + "==" + s2 );
    return s1.equals( s2 );
}

rule init
salience 100
when
then
    Person p = new Person( "Joe", 42 );
    insert( p );
end

rule testMVEL
dialect "mvel"
when
    $p: Person( matchMVEL( name, "Joe" ) == true && age > 40 )
then
    System.out.println( "testMVEL: old Joe" );
end

rule testJava
dialect "java"
when
    $p: Person( matchJava( $p.getName(), "Joe" ) == true && age > 40 )
then
    System.out.println( "testJava: old Joe" );
end



On 5 January 2012 16:50, ronalbury <ronalbury at gmail.com> wrote:

> Mark:  I know what Jira is ... but I don't know what you mean by a pull
> request ... I also don't have it set up as a JUnit test.
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Error-in-MVEL-execution-optimization-tp3633440p3635295.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120105/462528fb/attachment.html 


More information about the rules-users mailing list