条件での自動例外処理

ルール・エンジンは、Java 例外を生成するルール条件の処理を継続します。

以下のサブクラスは、ルール・エンジンにより処理されます。

  • ArithmeticException
  • NumberFormatException
  • NullPointerException
  • IndexOutOfBoundsException

条件での自動例外処理では、評価中に例外となった条件の式は不明値として扱われ、ルール・エンジンにより処理されます。ルール・エンジンでは、以下の 3 値ロジックを使用してルール条件全体が評価されます。

このイメージには、and、or、および not 演算子の 3 値ロジックが含まれます。

ルール・エンジンによりルール条件が True または False に評価されると、条件式の不明値に関係なく、ルール・アクション・ロジックが適用されます。ルール・エンジンによりルール条件が不明として評価されると、条件式の不明値のために、ルールは適用されません。

例えば、次のルールで、the name of the customer の値が NULL で、the age of the customer が 20 の場合、最初の条件は解決できませんが、2 番目の条件は満たされます。

if
   the name of the customer is 'Paul'
   or the age of the customer is 20
then
   reject the loan;

このルールでは、論理 or 演算子が使用されているため、ローンを拒否するアクションが実行されます。the age of the customer が 20 ではない場合、最初の条件は解決できず、2 番目の条件も満たされません。この場合、ルールは実行されず、ローンは拒否されません。

サポートされるビジネス・ルール言語式

自動例外処理では、次の 2 つのビジネス・ルール言語式が現在サポートされています。

  • If there is no ... then ...
  • If there is at least one ... then ...

次のビジネス・ルール言語式は現在サポートされていません。ただし、サポートされていないいずれかのビジネス・ルール言語式を使用する場合は、ルール条件の評価中、ルール・エンジンは不明値を現行では無視するということを理解してください。

  • If there is no ... then ... else ...
  • If there is at least one ... then ... else
  • If there are at least <number> ...
  • If there are more than <number> ...
  • If there are less than <number> ...
  • If there are <number> then ... else ...

サポートされているビジネス・ルール言語の式とは別に、コレクションを使用する他のすべての式も、ルール条件の評価中に不明値を無視する同じロジックに従います。

次の例で、where 節が 2 人の borrower について True で、2 人の borrower について不明である場合、ルール・エンジンはルール条件が False であると見なします。else アクションが実行されます。

If there are more than 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is the name of 'the borrower', 
then
   reject ‘the loan’;
   add “more than 3 similar borrowers found" to the messages of 'the loan' ;
else
   add “3 or fewer similar borrowers found " to the messages of 'the loan' ;

自動例外処理のログを使用可能にするには、server.xml でロガー名 com.ibm.rules.engine.aeh を FINE に設定します。Java ロギング API の概要については、Java Logging Overview を参照してください。java.util.logging Java ロガーについて詳しくは、Oracle の資料のjava.util.logging を参照してください。

条件での自動例外処理の例

簡単なルール条件

次の例では、borrower の status が不明の場合、ルール・アクションは実行されません。

if
   the status of 'the borrower' starts with "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;
OR 演算子を使用するルール条件

次の例では、borrower の status が不明で、loan の comment に duplicate という語が含まれる場合、loan は reject され、duplicate detected というメッセージが送信されます。

if 
   the status of 'the borrower' starts with "Duplicate" or the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

ただし、borrower の status が不明で、コメントが不明の場合、ルール・アクションは実行されません。loan は reject されず、no duplicate found というメッセージは loan に追加されません。

AND 演算子を使用するルール条件

次の例では、borrower の status が不明で、loan の comment に duplicate という語が含まれる場合、then アクションも else アクションも実行されません。つまり、loan は reject されず、no duplicate found というメッセージは loan の messages に追加されません。

if 
   the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

loan が reject されるには、両方の式が True である必要があります。

NOT 演算子を使用するルール条件

次の例では、status が不明で、comment に duplicate が含まれない場合、アクションが実行され、no duplicate found が追加されます。

if it is not true that
   (the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate")
then
   add "no duplicate found" to the messages of 'the loan' ;
else 
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;

status が不明で、comment に duplicate が含まれる場合、ルール・アクションは実行されません。

If there is no ... then ...

past borrowers のコレクションに、where 節が不明の borrower が含まれる場合、ルール・アクションは実行されません。

If there is no borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
add "no duplicate found" to the message of 'the loan'
If there is at least one ... then ...

past borrowers のコレクションに where 節が True の borrower が含まれる場合、ルール・アクションは実行されます。past borrowers のコレクションに where 節が False または不明の borrower が含まれる場合、ルール・アクションは実行されません。

If there is at least one borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
   reject 'the loan' ;
   add "duplicate detected" to the message of 'the loan'
ルール変数

ルール変数 'statusIsNew' が不明の場合、ルール・エンジンにより式の評価が停止されます。条件は不明と見なされ、ルール・アクションは実行されません。

definitions
   set 'statusIsNew' to the status of 'the borrower' starts with “New";

if it is not true that 'statusIsNew' and  the comment of 'the loan' contains "similar"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;
オブジェクトのコレクション

コレクション・オブジェクトが満たす必要のあるテストで不明値がある場合、このオブジェクトはコレクションに追加されません。

definitions
set 'duplicateBorrowers' to all borrowers where the status of each borrower starts with "duplicate" ; 
サポートされないビジネス・ルール言語の式

次の例で、where 節が 3 人の borrower について True で、1 人の borrower について不明である場合、where 節が不明である borrower はカウントされないため、ルール・エンジンでは条件が True であると見なされます。then アクションが実行されます。

If there are at most 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is  the name of 'the borrower', 
then
   add “3 or less similar borrowers found" to the messages of 'the loan' ;
else
   reject ‘the loan’;
   add “more than 3 similar borrowers found" to the messages of 'the loan' ;

次の例で、where 節が 1 人の borrower について True で、2 人の borrower について不明である場合、where 節が不明である 2 人の borrower はカウントされないため、ルール・エンジンではルール条件が False であると見なされます。else アクションが実行されます。

if there are at least 3 borrowers in the past borrowers of 'the loan' where the name of each borrower is  the name of 'the borrower', 
then
   reject ‘the loan’;
   add “3 or more similar borrowers found" to the messages of 'the loan' ;
else
   add “less than 3 similar borrowers found" to the messages of 'the loan' ;