Skip Headers
Oracle® Business Rules User's Guide
10g Release 3 (10.1.3)
B15986-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

1 Overview of Oracle Business Rules

This guide provides information on using Oracle Business Rules. Oracle Business Rules is a component of Oracle Application Server that enables applications to rapidly adapt to regulatory and competitive pressures. This increased agility is possible because business analysts using Oracle Business Rules can create and change business rules that are separated from the application code. Using Oracle Business Rules, business rules can change without stopping business processes. Also, externalizing business rules allows business analysts to manage business rules directly, without involving programmers.

This guide shows you how to work with Oracle Business Rules Rule Author (Rule Author), describes the Oracle Business Rules SDK (Rules SDK) and describes how to create a rule enabled Java program.

This chapter covers the following topics:

1.1 Introduction to Oracle Business Rules

This section introduces the concept of business rules and covers the following:

1.1.1 What Are Business Rules?

Business rules are statements that describe business policies. For example, a car rental company might use the following business rule:

If a driver's age is younger than 21, then decline to rent.

An airline might use a business rule such as the following:

If a frequent flyer's total miles for the year are greater than 100,000, then status is Gold.

A financial institution could use a business rule such as:

If annual income is less than $10,000, then deny loan.

These examples represent individual business rules. In practice, using Oracle Business Rules you can combine many business rules.

For the car rental example, you can name the driver age rule the Under Age rule. Traditionally, business rules such as the Under Age rule are buried in application code, and might appear in a Java application as follows:

public boolean checkUnderAgeRule (Driver driver) { 
   boolean declineRent = false;  
   int age = driver.getAge();
   if(  age < 21 ) { 
      declineRent = true; 
   }
   return declineRent; 
}

This code is not easy for non-technical users to read and can be difficult to understand and modify. For example, suppose that the rental company changes its policy to "Under 18", so that all drivers under 18 match for the Under Age rule. In many production environments, the developer would need to modify the application, recompile, and then redeploy the application. Using Oracle Business Rules, this process can be simplified.

Oracle Business Rules allows a business analyst to change business policies that are expressed as rules, with little or no assistance from a programmer. Applications using Oracle Business Rules, called rule enabled applications, can quickly adapt to new government regulations, improvements in internal company processes, or changes in relationships between customers and suppliers.

1.1.2 What Is a Data Model?

In Oracle Business Rules, facts are data objects that are asserted in the Rules Engine. Rules, such as the Under Age rule operate on facts. In Oracle Business Rules, a data model specifies the types of facts or business objects that you can use when you create business rules. For example, for a car rental company that needs to create a rule to match a driver's age, the driver's age information represents the facts used in the rule. Using Rule Author, you can create a data model and then use the objects in the data model when you create rules.

1.1.3 What Is a Rule-Based System?

This section covers the following:

1.1.3.1 Rule-Based Systems Using the Rete Algorithm

The Rete algorithm was first developed by artificial intelligence researchers in the late 1970s and is at the core of Rules Engines from several vendors. Oracle Business Rules uses the Rete algorithm to optimize the pattern matching process for rules and facts. The Rete algorithm stores partially matched results into a single network of nodes in current working memory.

Using the Rete algorithm, the Rules Engine avoids unnecessary rechecking when facts are deleted, added, or modified. To process facts and rules using the Rete algorithm, there is an input node for each fact definition and there is an output node for each rule. Fact references flow from input to output nodesFoot 1 .

The Rete algorithm provides the following benefits:

  • Independence from rule order – rules can be added and removed without impacting other rules.

  • Optimization across multiple rules – rules with common conditions share nodes in the Rete network.

  • High performance inference cycles – each rule firing typically changes just a few facts and the cost of updating the Rete network is proportional to the number of changed facts, not to the total number of facts or rules.

1.1.3.2 Oracle Business Rules Rule-Based Systems

A rule-based system using the Rete Algorithm is the foundation of Oracle Business Rules. A rule-based system consists of the following:

  • The Rule-base: contains the appropriate business policies or other knowledge encoded into If-Then rules.

  • Working memory: contains the information that has been added to the system. Using Oracle Business Rules; this consists of a set of facts.

  • Inference Engine: the Rules Engine which processes the rules performs pattern matching to determine which rules match the facts, for a given run through the set of facts.

Using Oracle Business Rules the rule-based system is a data-driven forward chaining system. The facts determine which rules can fire, when a rule fires that matches a set of facts, the rule may add new facts which are once again run against the rules. This process repeats until a conclusion is reached or the cycle is stopped or reset. Thus, in a forward chaining rule-based system, facts cause rules to fire, and firing rules can create more facts, which in turn can fire more rules. This process is called an inference cycle.

1.2 Oracle Business Rules Components

Figure 1-1 shows the Oracle Business Rules components.

This section covers the following topics:

Figure 1-1 Oracle Business Rules Architecture

Oracle Business Rules Architecture
Description of "Figure 1-1 Oracle Business Rules Architecture"

1.2.1 Introducing Oracle Business Rules Rule Author

Oracle Business Rules Rule Author (Rule Author) lets you work with rules from anywhere using a web browser and provides a point-and-click interface for creating new rules and editing existing rules. Rule Author reduces a rule developer's work, allowing you to work directly with business rules and a data model. You do not need to understand the Oracle Business Rules RL Language (RL Language) to work with Rule Author. Rule Author provides an easy way for business users to create, view, and modify business rules.

Rule Author supports several types of users, including the application developer and the business analyst. The application developer uses Rule Author to define a data model and an initial set of rules. The business analyst uses Rule Author to either work with the initial set of rules, or modify and customize the initial set of rules according to business needs. Using Rule Author, a business analyst can create and customize rules with little or no assistance from a programmer.

Rule Author stores rules programs in a dictionary that is saved to a repository using a Rule Author dictionary storage plug-in. You can create as many dictionaries as necessary, and each dictionary can have multiple versions. A rule enabled program accesses a dictionary with the Oracle Business Rules SDK.


Note:

It is not safe for multiple users to edit the same dictionary.

As shipped, Rule Author supports a WebDAV (Web Distributed Authoring and Versioning) repository and a file repository.


Note:

For file repositories, only one user may edit the repository at any given time, regardless of the number of dictionaries stored in the repository. For WebDAV repositories, a single user may edit multiple dictionaries simultaneously.

1.2.2 Introducing Oracle Business Rules Rules SDK

Oracle Business Rules SDK (Rules SDK) is a Java library that provides business rule management features that a developer can use to write customized rules programs. Rule Author uses the Rules SDK to create, modify, and access rules and the data model using well defined interfaces. Customer applications can use the Rules SDK to display, create, and modify collections of rules and the data model.

You can use the Rules SDK APIs in a rule enabled application to access, or to create and modify rules (the rules and the associated data model could be initially created in a custom application or using Rule Author where they are stored using a Rules SDK dictionary storage plug-in).

Using the Rules SDK you can also support custom repositories, using the dictionary storage plug-in portion of the Rules SDK API.

1.2.3 Introducing Oracle Business Rules RL Language

Oracle Business Rules supports a high level Java-like language called Oracle Business Rules RL Language (RL Language). The RL Language defines the valid syntax for Oracle Business Rules programs. RL Language includes an intuitive Java-like syntax for defining rules that supports the power of Java semantics, providing an easy-to-use syntax for application developers. RL Language consists of a collection of text statements that can be generated dynamically, or stored in a file.

Using RL Language, application programs can assert Java objects as facts, and rules can reference object properties and invoke methods. Likewise, application programs can use XML documents, or portions of XML documents as facts.

Programmers can use RL Language as a full-featured rules programming language. Business analysts can use Rule Author to work with rules, and in this case the business analyst does not need to directly view or write RL Language programs.


See Also:

Oracle Business Rules Language Reference Guide for detailed information on RL Language.

1.2.4 Introducing Oracle Business Rules Rules Engine

The Oracle Business Rules Rules Engine (Rules Engine) is a Java library that efficiently applies rules to facts and defines and processes rules. The Rules Engine defines a declarative rule language, provides a language processing engine (inference engine), and provides tools to support debugging.

The Rules Engine has the following features:

  • High performance – implementing specialized matching algorithms.

  • Thread-safe execution suitable for a parallel processing architecture (one thread can assert facts while another is evaluating the network).

  • Agility – meaning business rules can change without stopping business processes.

A rule enabled Java application can load and run rules programs. The rule enabled application passes facts, in the form of Java objects or XML documents, and rules to the Rules Engine. The Rules Engine runs in the rule enabled Java application, and uses the Rete algorithm to efficiently fire rules that match the facts.

The Rules Engine supports an interactive command-line interface for development, testing, and debugging of RL Language programs.

1.3 Oracle Business Rules Rule Author Terms and Concepts

This section provides information on Rule Author terms and concepts and covers the following topics:

1.3.1 Working with Rules

A rule consists of a condition, or If part, and a list of actions, or a Then part. Rules follow a simple if-then structure. This section covers the components of a rule.

1.3.1.1 Rule Conditions

The rule If part is composed of conditional expressions, rule conditions, that refer to facts. For example,

If a driver's age is younger than 21.

The conditional expression refers to a fact (driver), followed by a test that the fact's data member, age, is less than 21.

The rule condition activates the rule whenever there is a combination of facts that makes the conditional expression true. In some respects the rule condition is like a query over the available facts in the Rules Engine, and for every row returned from the query, the rule is activated.

1.3.1.2 Rule Actions

The rule Then part contains the actions that are executed if all of the rule conditions are satisfied. The actions are executed, or fired, when all of the conditions in the If part are met. There are several kinds of actions that a rule might perform. An action can add new facts or remove facts. An action can execute a Java method or perform an RL Language function, which may modify the status of facts or create new facts.

Rules fire sequentially, not in parallel. Note that rule actions often change the set of rule activations and thus change the next rule to fire.

1.3.2 Working with Rule Sets

A rule set groups a set of rules. A rule set is a collection of rules that are all intended to be evaluated together.

1.3.3 Working with Repositories and Dictionaries

Using Oracle Business Rules, a repository stores dictionaries. A dictionary usually corresponds to a rules application. A dictionary is a set of XML files that stores the application's rule sets and the data model. You store a dictionary in a repository using a supplied dictionary storage plug-in or a custom dictionary storage plug-in. The dictionary storage plug-in API is part of the Rules SDK. A dictionary typically stores all the rules and definitions for a rule enabled application. Dictionaries my have different versions. Dictionaries and dictionary versions can be created, deleted, exported, and imported into a repository.

As shipped, Rule Author supports a WebDAV (Web Distributed Authoring and Versioning) repository and a file repository.

1.3.4 Working with Facts

Using Rule Author, facts are data objects that have been asserted in the Rules Engine. Each object instance corresponds to a single fact. If an object is re-asserted (whether it has been changed or not), the Rules Engine is updated to reflect the new state of the object. Re-asserting the object does not create a new fact. In order to have multiple facts of a particular fact type, separate object instances must be asserted.

Using Rule Author, you can create rules that operate on facts that are part of a data model. You make business objects and their methods known to Oracle Business Rules using fact definitions.

This section covers the three types of Oracle Business Rules fact definitions:

You typically use Java Fact Types and XML Fact Types to create rules that examine the business objects in a rule enabled application, or to return results to the application and you use RL Language Fact Type definitions to create intermediate facts that can trigger other rules in the Rules Engine.

1.3.4.1 Java Fact Type Definitions

A Java fact type allows selected properties and methods of a Java class to be declared to the Rules Engine so that rules can access, create, modify, and delete instances of the Java class. Declaring a Java fact type allows the Rules Engine to access and use public attributes, public methods, and bean properties defined in a Java class (bean properties are preferable for some applications because the Rules Engine can detect that a Java object supports PropertyChangeListener; in this case it utilizes that mechanism to be notified when the object changes).

1.3.4.2 XML Fact Type Definitions

An XML fact type allows selected attributes and sub-elements of an XML element or complexType to be declared to the Rules Engine so that instances of it can be accessed, created, modified, and deleted by rules.

1.3.4.3 Oracle Business Rules RL Language Fact Type Definitions

An RL Language fact type is similar to a relational database row or a Java Bean without methods. An RL Language fact type contains a list of members of either RL Language fact type, Java fact type, or primitive type. RL Language fact types can be used to extend a Java application's object model by providing virtual dynamic types.

For example,

If customer spent $500 within past 3 months

then customer is a Gold Customer

This rule might use a Java fact type, specifying the customer data and also use an action that creates an RL Language fact type, Gold Customer. A rule might be defined to use a Gold Customer fact, as follows:

If customer is a Gold customer

then offer 10% discount

This rule uses the RL Language fact type, named Gold Customer. This rule then infers, using the Gold Customer fact, that if a customer spent $500 within the past 3 months, then the customer is eligible for a 10% discount. In addition, there could be other ways specified in the rules that a customer becomes a Gold Customer.

1.3.5 Working with Functions Variables and Constraints

This section covers the following definitions:

1.3.5.1 Function Definitions

Using Oracle Business Rules, a function is similar to a Java method, but it does not belong to a class. You can use functions to extend a Java application object model so that users can perform operations in rules without modifying the original Java application code.

You can also use a function definition to share the same or a similar expression among several rules, and to return results to the application.

1.3.5.2 Constraint Definitions

Constraint definitions let you mark portions of rules as customizable. For example, the discount to offer to a Gold customer could be constrained to be within a specified range such as 5 to 25 percent. Using Rule Author, by defining a constraint, you can select a value from within the specified range using a special interface that does not allow you to modify the entire rule.


Note:

Use of constraints is a Rule Author feature that supports rule customization (using the Rule Author rule customization tab).

1.3.5.3 Variable Definitions

You can use variable definitions to share information among several rules and functions. For example, if a 10% discount is used in several rules, you can create and use a variable Gold Discount, so that the appropriate discount is applied to all the rules using the variable.

Using variable definitions can make programs modular and easier to maintain.

1.4 Steps for Rule Enabling a Java Application

Programmers and business analysts work together to rule-enable a Java application. For many applications, after the application is rule enabled, the programmer role diminishes over time, leaving ongoing rule maintenance to the business analyst.

The tasks required to rule-enable a Java application include:

These tasks require cooperation between the programmer and the business analyst. Programmers understand application code and are comfortable with Java development, web services, and XML (if the business objects are represented in XML). Business analysts understand the business objects at a higher level, and the business analysts should understand rules as if…then statements concerning business objects. The business analysts also need to determine the parts of rules that are likely to need frequent change.

1.4.1 Identify Application Areas to Rule Enable

The business analyst and programmer collaborate to expose business objects as facts suitable for use in business rules. The business analyst determines the business facts required for use with the business rules.

The business analyst should determine what functionality should be rule-driven. For example, in an online shopping application, perhaps the tax and promotion functions should be rule-based, but not the shopping cart or product catalog.

1.4.2 Provide Rule Author Definitions for the Data Model

The programmer uses definitions in Rule Author to specify the data model (working with the Rule Author Definitions tab). Working with the business analyst the programmer also defines helpful functions, intermediate facts, variables, and constraints.

1.4.3 Develop a Business Vocabulary for the Data Model

The programmer and the business analyst use Rule Author to develop a business-friendly vocabulary for the Rule Author definitions, so that the rules are more understandable. While determining what business facts, functions, and other definitions to capture, the business analyst has been developing a vocabulary. The programmer enters this information using Rule Author.

1.4.4 Write and Customize Rules

At this point, the business analyst should be able to use Rule Author to write and customize rules using the defined business vocabulary. Alternatively, the programmer may use the Rules SDK to create or modify rules, or the data model from within the administrative portion of a rules-enabled application.

1.4.5 Modify or Create Application Logic that Uses the Rules Engine

The programmer determines how to replace procedural functionality with new rule-driven functionality. If the application is written in Java then the application code can directly invoke the Rules Engine. Otherwise, the programmer may need to invoke the Rules Engine using a web service or other remote API. The programmer must either create a new application or modify an existing application to interact with the Rules Engine.


Note:

Procedural code that is being rule enabled may need to be "mined" to extract existing hard-coded rules.


See Also:

Chapter 2, "Getting Started with Rule Author" for details on working with Rule Author and on the steps a programmer takes to rule-enable a Java application.

1.4.6 Test the Rule Enabled Application

The programmer and the business analyst test the modifications made to the application. The programmer may need to assist in the debugging of a complex set of rules. Rules Engine tracing can be enabled to provide information about facts, rule activations, and rule firings. A mechanism for loading test facts should be developed that validates a set of the business analyst rules.



Footnote Legend

Footnote 1: Fact references flow from input to output nodes. 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. A rule is activated when its output node contains fact references. Fact references are cached throughout the network to speed up recomputing activated rules. When a fact is added, removed, or changed, the Rete network updates the caches and the rule activations with only an incremental amount of work.