Oracle Rules... the world?? Design and Run-time Rules Engine - also for PL/SQL? americas cup win 2682133k1

Oracle Rules… the world?? Design and Run-time Rules Engine – also for PL/SQL?

I was triggered by the news item on OC4J on OTN’s homepage, ”
Download Oracle Application Server 10g (10.1.3) Developer Preview 4 – including … Oracle Rules” to resume my research into Business Rules. I have heard rumours about Oracle Rules for over a year now, but I had not yet seen more details. I was and am still curious if it can complement, enhance or even replace the CDM RuleFrame engine for (database) server side business rule enforcement. I helped create this engine while I was still working at Oracle, and the subject is still close to my heart. You may have read my post on The future of CDM RuleFrame – the Oracle framework for server-side business rules. In this post I discuss many ways to improve RuleFrame, using for example SQL and PL/SQL features from Oracle 8i and especially 9i as well as decoupling RuleFrame from Oracle Designer. Oracle Rules seems to be a way forward with Business Rules, even though it is primarily focused on middle-tier based Business Rule enforcement for Java and XML Objects.

Introducing Oracle Rules

Looking through the documentation and examples on the Oracle Rules home page on OTN, I decided to download the preview of Oracle Rules and give it a try. From these explorations, I draw the following conclusions:

Oracle Rules has three major components:

  1. The Rules Repository – for both Design Time and Run Time storage of Business Rules
  2. The Business Rules Author – the design time browser based User Interface for specifying business rules in terms of Facts, Properties, Functions and Operators
  3. The Business Rule Run Time Engine – the run time component that will evaluate rules for specific object instances

I am of course enormously oversimplifying the Oracle Rules architecture here.

There are some other essential facts to realize about Oracle Rules:
The Business Rules Author is a web based, multi user tool that can be used by Business Analysts as well as Developers. It is more or less technology agnostic; although the assumption is that Business Rules are enforced on Java Objects, the specification of the rules is done in terms of Facts and Properties, Expressions and Functions. Facts can be defined manually or automatically created by registering Java Classes. There is nothing stopping us from defining facts that do not represent Java Classes, but instead for example a Java Script object or a Table Record. The Rules Author is a J2EE Application, based on UIX and Servlet technology, deployed in OC4J 10.1.3 preview 3 or later (when that is available).

The Rules Repository can be either file based or database based (I am not entirely sure about the latter, but I think it either already is or will be the case).

There does not seem to be any connection between Oracle Rules and OCL (Object Constraint Language), the subset of UML 1.1 and 2.0 that describes specification of Object oriented Business Rules. OCL never seems to have made it big, it still is part of a world wide standard. So perhaps this is a missed opportunity. Then again, it should be fairly easy to convert OCL definitions into Oracle Rules style Business Rules and vice versa.

I have not seen any reference on the Business Rules (“validations”) that you can define in Oracle ADF Business Components and their relation to Oracle Rules. You would expect at least a document outlining when to use one and when to use the other. It seems more likely that you migrate the Validation definitions away from ADF BC and into Oracle Rules and extend ADF BC to invoke Oracle Rules at the appropriate moments. Undoubtedly we will see more about this. (Of course there always seems to be some distance between the Application Server (10g AS) and the JDeveloper teams)

Oracle Rules comes with a Java-based SDK (Software Developer’s Kit) that provides programmatic access to the Rule Repository. This allows us several things:

  • Programmatically registering Facts with their properties etc.
  • Programmatically specifying rules – for example when migrating from OCL, ADF BC or third party rule definitions
  • Programmatically accessing rule definitions – for example in order to generate the implementation of those rules for environments currently not support in the Oracle Rules runtime engine, such as PL/SQL

The documentation for Oracle Rules suggests a way of working with the Rules Engine from other technologies than Java (running in the same JVM as the Rules Engine): “The Rule Session API is the interface between the application and the Rule Engine. In the event that the application is not running in the application server (for
example, a PL/SQL application running in a database), use JDeveloper to create a web service wrapper for the Rule Session API.” While I am sure this will work, I am equally convinced that this will never provide satisfactory performance for bulk DML operations such as performed in batch programming – it may suffice for OLTP applications, but I doubt that as well.

Quoting from a Technical White Paper

Rule Language The Rule Engine directly executes Oracle Rule Language (RL) RL is interpreted rather than compiled so that rules may be changed without rebuilding, redeploying, or even restarting applications. RL features Java-like syntax and type checking. RL programs can assert any Java object as a fact, and rules can reference any object property and invoke any method in its condition and actions.
Example of a rule in Rule Language

rule approvePO {
if (fact PurchaseOrder po
&& po.amount > 1000
&& po.approvalLevel ==
po.approvalLevel = "VP";

Programmers can use RL as a full-featured rules programming language, or business analysts can use the Rule Author and RL can be generated from the Rule Repository behind the scenes. The rule engine has a command line interface for interactive RL development and debugging.

Rete – The Rule Engine uses the industry-standard Rete algorithm that was first developed by artificial intelligence researchers in the late 1970s and is at the core of rule engines from major rule vendors.
The Rete algorithm combines rule conditions for all rules into a single network of nodes. There is an input node for each fact definition. There is an output node for each rule. In between input and output nodes are test nodes and join nodes. A test occurs when a rule condition has a boolean expression. A join occurs when a rule condition ANDs two facts…

Oracle Rules, CDM RuleFrame and (Database) Server Side Business Rules

Those of you who know me or have read my ramblings before will know that I am very attached to server side (that is: in the database) implementation of (data oriented) business rules. If possible in a declarative way and otherwise using database triggers. I have come to realize that you can discern at least two types of business rules: application, process and flow oriented rules on the one hand and data oriented rules on the other. The latter category must always be implemented in the database; that to me is the only way to guarantee data integrity. Implementing such rules in a middle tier simply is not good enough in the long run; someone will run an import job on the database, use TOAD or SQL*Plus to ‘fix’ the data or another application comes along and starts using the same tables, without relying on the middle tier Java API to get there.

So do I see value for Oracle Rules? Yes, I most certainly do.

First of all, there are rules that are not data oriented, and have no meaning in the database. Those should be in the middle tier. For example, not all objects are mapped to persistent database records.

Second, I can certainly see value in enforcing some rules not only in the database but also in the middle tier or on the client. Better and faster user feedback, decreasing the load on the database server etc. may be reasons for doing so.

But even more importantly, I see tremendous value in having a single repository of business rule definitions! With CDM RuleFrame we have always struggled a bit, trying to force our way with regard to Business Rules into the Oracle Designer Repository. It was a bit like plugging round pegs into square holes, but it was the only repository we had. In the Oracle Designer Web Assistant (today known as the Repository Object Browser) we did a better job of representing rule definitions, but it was still inadequate. And like I mentioned before, it is not ideal to have RuleFrame entangled with Oracle Designer.

Using Oracle Rules – the Rules Repository and the Rules Author – seems like a big step forward. Business Analysts can use a user friendly, largely technology unaware interface that is browser based, multi-user etc. to build up their collection of rules. If we can use these rule definitions in a run time engine, that would be of course a big bonus. Generating PL/SQL code – triggers and CAPI packages – from the RuleFrame definitions in Oracle Designer could be replaced with generation of the same or similar artefacts from the Oracle Rules Repository! (and there is always the option of using the Java based run time engine through a WebService directly from PL/SQL). By the way, I do not know yet if the Oracle Rules engine could be loaded into the Database JVM; in that case, we could even have direct invocations from PL/SQL.

In order to give our Business Analysts a head start for defining business rules, we should load Oracle Rules with the Business Facts. Typically these are taken from Class definitions, but there really does not seem to be a reason why they cannot be taken from Entity or Table Definitions. So we can use the Rules Repository SDK to create Facts based on Entity definitions in our Oracle Designer repository or Tables in the Oracle Database dictionary!

I think I will start by trying out whether I can define typical data oriented rules (in terms of table based Facts) in Oracle Rules Author. The next step would be registering Facts through the SDK, based on Tables. Then I could see whether the Rule definitions lend themselves to generation of PL/SQL code. And we can try to upload the runtime Rule Engine into the Database JVM. I will keep you posted.


  1. Satish January 10, 2012
  2. Surya November 27, 2007
  3. Lucas August 16, 2005
  4. Toon Koppelaars August 15, 2005
  5. Sandor Nieuwenhuijs August 5, 2005
  6. Wilfred August 4, 2005