1.2. Upgrade tips from Drools 3.0.x to Drools 4.0.x
Drools 4.0 is a major update over the previous Drools 3.0.x series. Unfortunately, in order to achieve the goals set for this release, some backward compatibility issues were introduced. This has been discussed at length in the mailing list and blogs.
This section of the manual documents a simple how-to on upgrading from Drools 3.0.x to Drools 4.0.x.
There are a few API changes that are visible to regular users and need to be fixed.
Drools 3.0.x had only one working memory type that functioned as a stateful working memory. Drools 4.0.x introduces separate APIs for Stateful and Stateless working memories called Rule Sessions.
In Drools 3.0.x, the code to create a working memory was:
WorkingMemory wm = rulebase.newWorkingMemory();
In Drools 4.0.x it must be changed to:
StatefulSession wm = rulebase.newStatefulSession();
The StatefulSession object has the same behavior as the Drools 3.0.x WorkingMemory (it even extends the WorkingMemory interface), so there should be no other problems with this fix.
Drools 4.0.x now supports pluggable dialects and has built-in support for Java and MVEL scripting language. In order to avoid keyword conflicts, the working memory actions were renamed as showed below:
| Drools 3.0.x | Drools 4.0.x |
|---|---|
| WorkingMemory.assertObject() | WorkingMemory.insert() |
| WorkingMemory.assertLogicalObject() | WorkingMemory.insertLogical() |
| WorkingMemory.modifyObject() | WorkingMemory.update() |