10-4 Oracle Fusion Middleware Users Guide for Oracle Business Rules
public double getRaisePercent { return raisePercent;
} }
In Example 10–1
, there is an oracle.rules.sdk2.decisionpoint.DecisionPointInstance
as a parameter to the exec method.
Table 10–1 shows the methods in
DecisionPointInstance that an application developer might need when
implementing the ActionType exec.
Using Rules Designer you can select parameters appropriate for the ActionType you are configuring.
10.2 Using Decision Points with ADF Business Components Facts
You can use a Decision Point to execute a decision function. There are certain Decision Point methods that only apply when working with ADF Business Components Fact
types. For more information on decision functions, see Chapter 6, Working with
Decision Functions .
10.2.1 How to Call a Decision Point with ADF Business Components Facts
When you use ADF Business Components fact types you invoke a decision function using the Rules SDK Decision Point interface.
To call a decision function using the Rules SDK Decision Point interface: 1.
Construct and configure the template DecisionPoint instance using the DecisionPointBuilder
. For more information, see
Section 7.3.1, How to Add a Decision Point Using Decision Point Builder
.
2.
Create a DecisionPointInstance using the DecisionPoint method getInstance
.
Table 10–1 DecisionPointInstance Methods
Method Description
getProperties Supplies a HashMapString,Object object containing any runtime-specified
parameters that the action types may need. If you intend to use the decision function from a Decision service, use only String
values. getRuleSession
Gives access to the Oracle Business Rules RuleSession object from which static configuration variables in the Rule Dictionary may be accessed.
getActivationID If populated by the caller, supplies a String value to be used for Set Control indirection.
getTransaction Provides a transaction object so that action types may make persistent changes in the
back end. addResult
Adds a named result to the list of output values in the form of a String key and Object value.
Output is assembled as a List of oracle.rules.sdk2.decisionpoint.DecisionPointInstance.NamedVal
ue objects as would be the case in a pure map implementation. The NamedValue
objects are simple data-bearing classes with a getter each for the name and value. Output values from one action types instance are never allowed to overwrite each
other, and in this regard, the action type implementations should be considered completely independent of each other.
Working with Oracle Business Rules and ADF Business Components 10-5
3.
Add the fact objects you want to use to the DecisionPointInstance using DecisionPointInstance
method addInput, setInputs, or setViewObject
. These are either ViewObject or ViewObjectReference instances. These must be added in the same order as they are declared in the
decision function input. For more information, see Section 10.2.1.3, Calling the
Invoke Method for an ADF Business Components Rule
4.
Set the transaction to be used by the DecisionPointInstance. For more information, see
Section 10.2.1.1, Setting the Decision Point Transaction
.
5.
Set any runtime properties the consequent application actions may expect. For more information, see
Section 10.2.1.2, Setting Runtime Properties .
6.
Call the DecisionPointInstance method invoke. For more information, see:
■
Section 10.2.1.3, Calling the Invoke Method for an ADF Business Components Rule
■
Section 10.2.1.4, What You Need to Know About Decision Point Invocation
10.2.1.1 Setting the Decision Point Transaction
The Oracle Business Rules SDK framework requires an oracle.jbo.server.DBTransactionImpl2
instance to load a ViewObject and to provide ActionType instances within a transactional context. The class
oracle.jbo.server.DBTransactionImpl2 is the default JBO transaction object
returned by calling the ApplicationModule method getTransaction. Setting the transaction requires calling the DecisionPointInstance method
setTransaction with the Transaction object as a parameter.
Should a DBTransaction instance not be available for some reason, the Oracle Business Rules SDK framework can bootstrap one using any of the three provided
overrides of the setTransaction method.
These require one of:
■
A JDBC URL, user name, and password.
■
A JDBC connection object.
■
A javax.sql.DataSource object and a flag to specify whether the DataSource
represents a JTA transaction or a local transaction.
10.2.1.2 Setting Runtime Properties
Runtime properties may be provided with the setProperty method. These can then be retrieved by ActionType instances during their execution. If no runtime
properties are needed, you may safely omit these calls.
10.2.1.3 Calling the Invoke Method for an ADF Business Components Rule
The ViewObject to be used in a Decision Point invocation can be specified in one of two ways, as shown in
Table 10–2 .
10-6 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Example 10–2 shows how to invoke a Decision Point with a ViewObject instance
using the setInputs method. For the complete example, see Example 10–5
.
Example 10–2 Invoking a Decision Point Using setInputs Method
public class OutsideManagerFinder { private static final String AM_DEF = com.example.AppModule;
private static final String CONFIG = AppModuleLocal; private static final String VO_NAME = EmployeesView1;
private static final DictionaryFQN DICT_FQN = new DictionaryFQNcom.example, Chapter10Rules;
private static final String DF_NAME = FindOutsideManagers; private DecisionPoint dp = null;
public OutsideManagerFinder { try {
dp = new DecisionPointBuilder .withDICT_FQN
.withDF_NAME .build;
} catch SDKException e { System.err.printlne;
} }
public void run { final ApplicationModule am =
Configuration.createRootApplicationModuleAM_DEF, CONFIG; final ViewObject vo = am.findViewObjectVO_NAME;
final DecisionPointInstance point = dp.getInstance; point.setTransactionDBTransactionImpl2am.getTransaction;
point.setAutoCommittrue; point.setInputsnew ArrayListObject{{ addvo; }};
try {
Table 10–2 Setting the View Object for a Decision Point Invocation
ViewObject Set Method
Description
setViewObject The decision function is invoked once for each ViewObject row. This
the preferred way to use view objects. Between each invocation of the decision function, the rule session is not reset so any asserted facts from
previous invocations of the decision function are still in working memory. In most cases, users should write rules that retract the
asserted facts before the decision function call completes. For example, you can have a cleanup ruleset that retracts the ViewObject row that
runs before the Postprocessing decision function is called.
Section 10.3.9.3, How to Add Retract Employees Ruleset shows this
usage. To use setViewObject, the ViewObject must be the first entry in the decision function InputTable.
addInput setInputs
The decision function is invoked once with all of the ViewObject rows loaded at the same time. This is generally not a scalable operation,
since hundreds of thousands of rows can be loaded at the same time. There are some cases where there are a known small number of rows in
a ViewObject that this method of calling the ViewObject can be useful.
Working with Oracle Business Rules and ADF Business Components 10-7
ListObject invokeList = point.invoke;
ListDecisionPoint.NamedValue results = point.getResults;
} catch RLException e { System.err.printlne;
} catch SDKException e { System.err.printlne;
} }
Example 10–3 shows how to invoke a DecisionPoint using the setViewObject
method to set the ViewObject.
Example 10–3 Invoking a Decision Point Using setViewObject Method
public void run { final ApplicationModule am =
Configuration.createRootApplicationModuleAM_DEF, CONFIG; final ViewObject vo = am.findViewObjectVO_NAME;
final DecisionPointInstance point = dp.getInstance; point.setTransactionDBTransactionImpl2am.getTransaction;
point.setAutoCommittrue; point.setViewObjectvo;
try { ListObject invokeList = point.invoke;
ListDecisionPoint.NamedValue results = point.getResults;
} catch RLException e { System.err.printlne;
} catch SDKException e { System.err.printlne;
} }
10.2.1.4 What You Need to Know About Decision Point Invocation
Care must be taken when invoking Decision Points using a view object that loads large amounts of data, since the default behavior of the JBO classes is to load all data
eagerly. If a view object with many rows and potentially very many child rows is loaded into memory, not only is there risk of memory-exhaustion, but DML actions
taken based on such large data risk using all rollback segments.
10.2.2 How to Call a Decision Function with Java Decision Point Interface