Skip Headers
Oracle® Business Rules User's Guide
10g (10.1.3.1.0)

Part Number B28965-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

1 Overview of Oracle Business Rules

This guide provides information about 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. By using Oracle Business Rules, business analysts can change business rules 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 the age of a driver is younger than 21, then decline to rent.

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

If a frequent flyer account has total miles for the year that 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, you can use Oracle Business Rules to 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 nontechnical 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 must modify the application, recompile, and then redeploy the application. Using Oracle Business Rules, this process can be simplified because a business rules application is built to support easily changing business rules.

Oracle Business Rules allows a business analyst to change policies that are expressed as business rules, with little or no assistance from a programmer. Applications using Oracle Business Rules, called rule-enabled applications, support continuous change that allows the applications to 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, constrain and support facts. In Oracle Business Rules, a data model specifies the types of facts or business objects that you can use to create business rules. For example, for a car rental company that needs to create a rule to match the age of a driver, the driver information represents the facts used in the rule. Using Rule Author, you can define 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 in a single network of nodes in current working memory.

By using the Rete algorithm, the Rules Engine avoids unnecessary rechecking when facts are deleted, added, or modified. To process facts and rules, the Rete algorithm creates and uses an input node for each fact definition and 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 affecting 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. With Oracle Business Rules you add a set of facts to the system using assert calls.

  • 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.

In 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. These new facts 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. It provides a point-and-click interface for creating new rules and editing existing rules. Rule Author allows 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 you 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 either to work with the initial set of rules, or to 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.

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

Note 1:

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

Note 2:

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 Rules SDK to create, modify, and access rules and the data model using well-defined interfaces. Customer applications can use 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 rules, 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 (Rule Author uses the Rules SDK dictionary storage plug-in to store rules).

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

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). 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. 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 about RL Language

1.2.4 Introducing Oracle Business Rules Rules Engine

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

Rules Engine has the following features:

  • High performance: Rules Engine implements specialized matching algorithms for facts that are defined in the system.

  • Thread-safe execution suitable for a parallel processing architecture: Rules Engine provides one thread that can assert facts while another is evaluating the network.

  • Agility: Rules Engine allows rules to change without stopping business processes.

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

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

1.3 Oracle Business Rules Rule Author Terms and Concepts

This section provides information about 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 the age of a driver 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 a combination of facts 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. A rule might perform several kinds of actions. 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

In Oracle Business Rules, a repository stores dictionaries. A dictionary usually corresponds to a rules application and typically stores the rules and definitions for a rule-enabled application. A dictionary is a set of XML files that stores the rules 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 Rules SDK. Dictionaries may 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

In Oracle Business Rules, facts that you can run against the rules are data objects that have been asserted. 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.

In Rule Author, you make business objects and their methods known to Oracle Business Rules using fact definitions that are part of a data model.

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. 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 Rules Engine so that rules can access, create, modify, and delete instances of the Java class. Declaring a Java fact type allows 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 Rules Engine can detect that a Java object supports PropertyChangeListener; in this case it uses 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 subelements of an XML element or complexType to be declared to 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 JavaBean 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 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 to specify 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 rules could specify other ways 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

In Oracle Business Rules you define a function in a manner similar to a Java method, but a RL function does not belong to a class. You can use RL 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 an RL function definition to share the same or a similar expression among several rules, and to return results to the application.

1.3.5.2 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.3.5.3 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. In 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.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 must determine the parts of rules that are likely to require 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 and the programmer together working determine the business facts required for use with the business rules. These could be the business objects that represent policies that require frequent change, or other policies that might change due to agile business processes.

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 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 or another tool to define 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 business vocabulary.

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 Rules SDK to create or modify rules, or the data model from within the administrative portion of a rule-enabled application.

1.4.5 Modify or Create Application Logic That Uses Oracle 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 Rules Engine. Otherwise, the programmer may need to invoke 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 Rules Engine.

Note:

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

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 application. The programmer must provide a set of tests and must in the debugging for a complex set of rules. The programmer can enable Rules Engine tracing to provide information about facts, rule activations, and rule firings. The programmer should develop an automated mechanism for loading test facts 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; this requires only an incremental amount of work.