Thursday, December 20, 2007

Modify Block for Java Dialect

In one more post in the series: "What are you guys doing right now?", :) we just added support to modify block in Java dialect consequences.

This is a feature that was already supported by MVEL and we decided to port it to Java so that it would benefit everyone, independently of the chosen dialect.

Basically, a modify block is a block of code that allow attributes of a given fact to be changed in the consequence of your rules, even with shadow facts turned off. In other words, if you don't want to pay for the shadow fact performance and memory cost, you can disabled them as long as you only change fact attributes inside modify blocks.

Example:

rule "Eat Cheese"
when
$p: Person( status == "hungry" )
$c: Cheese( )
then
retract( $c );
modify( $p ) {
setStatus( "full" ),
setAge( $p.getAge() + 1 )
}
end

So, inside of the modify block, you may write a comma separated list of Java expressions (set attribute values, call methods, etc) that are applied to the object scoped to that modify call. All of them are executed in sequence and inside a single fact update scope.

The grammar pseudo BNF looks like this:

modify ::= 'modify' '(' <expression> ')' '{' [ <expression> [ ',' <expression> ]* ] '}'

This feature was added both to trunk and 4.0.x branches and will be released in Drools 4.0.4 and Drools 4.1.0.

Happy drooling,
Edson
Share/Bookmark

6 comments:

  1. If a fact did not have property change support listener support, normally I would call update() on it after modifying it. Is that explicit call still necessary when using the modify block, or is it implied?

    ReplyDelete
  2. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    WordPress development company in Chennai

    ReplyDelete
  3. This is a very amazing post for cheap web hosting services. in this post, you have provided all the basic information regarding.
    website builder for reseller

    ReplyDelete
  4. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    private label website builder

    ReplyDelete
  5. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    white label website builder

    ReplyDelete
  6. It has been simply incredibly generous with you to provide openly what exactly many individuals wouldíve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    Java Training | best java training institute in chennai | java j2ee training in chennai |
    java training chennai | java classes in chennai | java course in chennai | java training with placement in chennai| best java training center in chennai |
    java coaching classes in chennai

    ReplyDelete