1.2. Upgrade tips from Drools 3.0.x to Drools 4.0.x

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.

1.2.1. API changes

There are a few API changes that are visible to regular users and need to be fixed.

1.2.1.1. Working Memory creation

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();
Example 1.1. Drools 3.0.x: Working Memory Creation

In Drools 4.0.x it must be changed to:

StatefulSession wm = rulebase.newStatefulSession();
Example 1.2. Drools 4.0.x: Stateful Rule Session Creation

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.

1.2.1.2. Working Memory Actions

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()
Table 1.1. Working Memory Actions equivalent API methods