1-18 Oracle Fusion Middleware Language Reference Guide for Oracle Business Rules
■
Obtain a list of the last fact traces for each instance of a specific fact type.
■
Obtain the last fact trace for a specific fact identified by its fact ID.
■
Obtain all of the fact traces for a fact identified by its fact ID.
■
For a fact trace, if the fact trace was created by a rule action, get the rule trace that rule firing in which the action executed.
■
For a rule trace, get the list of fact traces for each fact that matched and resulted in the rule firing.
■
Get the next or previous trace. Exploration of the trace is typically not an iteration over the trace. For example, obtaining a rule trace from a fact trace is essentially
jumping to that rule trace. The traces near the rule trace can be explored directly.
■
Obtain a list of rule traces for a rule identified by its name.
■
Obtain the rule engine state for a trace entry. The rule engine state reflects the state of the rule engine after the activity that generated the trace. This API enables
inspecting the rule engine state at the time of each trace. This API is most useful with development level tracing. With production level tracing, only the facts in
working memory can be tracked and they will not include any fact contents.
Example 1–21 shows a code sample that uses the decision trace analysis API.
Example 1–21 Decision Trace Analysis API Usage
DecisionTrace trace; ...
TraceAnalysis ta = new TraceAnalysistrace; Get all of the last fact traces for a fact type.
ListFactTrace factTraces = ta.getLastFactTracescom.example.MyFactType; From a particular fact trace, how it was arrived at may be explored, first by
obtaining the rule that asserted or modified the fact. From the FactRecord, the rule that resulted in the record can be obtained.
FactTrace factTrace = factTraces.get0; assumes there is one RuleTrace ruleTrace = ta.whichRulefactTrace;
The ruleTrace will be null if the fact operation was not part of a rule action.
System.out.printFact + factTrace.getFactId + , a + factTrace.getFactType + + factRecord.getFactOp;
if ruleTrace = null System.out.println by rule + ruleTrace.getRuleName;
else System.out.println;
The analysis can continue by obtaining the list of FactRecords that matched the rule and
proceeding to analyze the trace back in time. ListFactTrace matchingFacts = ta.getRuleMatchedFactsruleTrace;
1.7.3 Decision Trace Samples for Production and Development Level Tracing
Example 1–22 shows a sample production level trace document.
Example 1–22 Sample Production Level Decision Trace
?xml version=1.0 encoding=UTF-8 standalone=yes? decision-trace xmlns=http:xmlns.oracle.comrulesdecisiontrace
trace-entries xsi:type=rule-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
Rules Programming Concepts 1-19
timestamp1248975549890timestamp rule-nameOrderDiscount.goldCustomerrule-name
token-time0token-time sequence-number1sequence-number
trace-entries trace-entries xsi:type=rule-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975549893timestamp rule-nameOrderDiscount.goldCustomerDiscountrule-name
token-time0token-time sequence-number2sequence-number
trace-entries trace-entries xsi:type=rule-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975549894timestamp rule-nameOrderDiscount.applyDiscountrule-name
token-time0token-time sequence-number3sequence-number
trace-entries decision-trace
Example 1–23 Sample Development Level DecisionTrace
?xml version=1.0 encoding=UTF-8 standalone=yes? decision-trace xmlns=http:xmlns.oracle.comrulesdecisiontrace
trace-entries xsi:type=fact-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance timestamp1248975491008timestamp
fact-id1fact-id operationassertoperation
fact-typecom.example.Customerfact-type object-typecom.example.Customerobject-type
fact-object properties
nameYTDOrderAmountname value
string2000.0string value
properties properties
namelevelname value
stringnullstring value
properties properties
namenamename value
stringOneLtdstring value
properties properties
namepastDuename value
stringfalsestring value
properties fact-object
trace-entries trace-entries xsi:type=activation-trace
xmlns:xsi=http:www.w3.org2001XMLSchema-instance timestamp1248975491024timestamp
1-20 Oracle Fusion Middleware Language Reference Guide for Oracle Business Rules
rule-nameOrderDiscount.goldCustomerrule-name token-time2token-time
fact-ids1fact-ids operationaddoperation
trace-entries trace-entries xsi:type=fact-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975491025timestamp fact-id2fact-id
operationassertoperation fact-typecom.example.Orderfact-type
object-typecom.example.Orderobject-type fact-object
properties namecustomerNamename
value stringOneLtdstring
value properties
properties namediscountname
value string0.0string
value properties
properties namegrossAmountname
value string400.0string
value properties
properties namenetAmountname
value string0.0string
value properties
properties namenumbername
value string1001string
value properties
fact-object trace-entries
trace-entries xsi:type=activation-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975491035timestamp rule-nameOrderDiscount.goldCustomerDiscountrule-name
token-time5token-time fact-ids2fact-ids
fact-ids1fact-ids operationaddoperation
trace-entries trace-entries xsi:type=rule-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975491036timestamp rule-nameOrderDiscount.goldCustomerDiscountrule-name
token-time5token-time fact-ids2fact-ids
fact-ids1fact-ids sequence-number2sequence-number
Rules Programming Concepts 1-21
trace-entries ...
trace-entries xsi:type=rule-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance timestamp1248975491036timestamp
rule-nameOrderDiscount.applyDiscountrule-name token-time7token-time
fact-ids2fact-ids sequence-number3sequence-number
trace-entries ...
trace-entries xsi:type=ruleset-stack-trace xmlns:xsi=http:www.w3.org2001XMLSchema-instance
timestamp1248975491037timestamp operationpopoperation
ruleset-nameOrderDiscountruleset-name trace-entries
decision-trace
1.8 Building a Coin Counter Rules Program