http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html_single/index.html#d0e3387
6. User Guide
ランタイムでの基本的な動作の説明をするよ。
6.1. The Basics
6.1.1. Stateless Knowledge Session
データ渡して一発実行には Stateless Knowledge Session を使います。
シンプルなユースケースから、説明していきます…
複数insertの一発実行も、もちろんできます。
KieCommands kieCommands = kieServices.getCommands(); List<Command> cmds = new ArrayList<Command>(); cmds.add( kieCommands.newInsert( new Person( "Mr John Smith" ), "mrSmith", true, null ) ); cmds.add( kieCommands.newInsert( new Person( "Mr John Doe" ), "mrDoe", true, null ) ); BatchExecutionResults results = ksession.execute( kieCommands.newBatchExecution( cmds ) ); assertEquals( new Person( "Mr John Smith" ), results.getValue( "mrSmith" ) );
6.1.2. Stateful Knowledge Session
継続的に使う場合は Stateful Knowledge Session。使い終わったら、 KieSession.dispose() を呼ばないとメモリリークするよ!
もうちょっと複雑な、RHSで insert/update が起こるユースケースの説明。
6.1.3. Methods versus Rules
「メソッドとルールはどう違うの?」っていう疑問のあるひとはここ読む。
6.1.4. Cross Products
SQLでJOINするときと同じですね。ちゃんとフィールド制約を入れないと、大量の組み合わせがマッチし、パフォーマンスにも影響するので注意。
6.2. Execution Control
6.2.1. Agenda
Agenda は実行可能と評価されたルールを管理します。
6.2.2. Rule Matches and Conflict Sets.
fireAllRules()が実行されたとき、Agenda上のルールはどういう順番で実行されるのかな?キャッシュフローのサンプルで説明。
salience で普通に順番付け。 agenda-group でグループ化して順番付け(スタック)。ruleflow-group で、フローに沿って順番付け。
6.3. Inference
Inference (推論)。RHSで insert/update/delete を行い、ルールの再評価を行うこと。複雑になるうえ、実際のビジネスユースケースでは使うことが少ないって言っちゃってますね。はい、まあこれが使いこなせれば上級者ってことで。
6.3.1. Bus Pass Example
6.4. Truth Maintenance with Logical Objects
insertLogical です。あるルール A の LHS が true となり、その結果、RHSで fact が logically insert されるとします。その後、もうそのルール A の LHS の条件が true にならなくなったとき、自動的にその fact は retract されます。意味分からないって? 6.4.1.1. Bus Pass Example With Inference and TMS の例がおすすめです。insert と insertLogical を適切に使い分けられれば達人です。たぶん。
6.4.1. Overview
6.5. Decision Tables in Spreadsheets
よく使われています。Excel万歳。
6.5.1. When to Use Decision Tables
6.5.2. Overview
6.5.3. How Decision Tables Work
要するに DRL を生成するテンプレートということ。1行が1ルールになります。
6.5.4. Spreadsheet Syntax
キーワードが元のDRLのキーワードと違ったりするんだよなー(salience が PRIORITYとか)。誰だよ決めたの。
6.5.5. Creating and integrating Spreadsheet based Decision Tables
6.5.6. Managing Business Rules in Decision Tables
6.5.7. Rule Templates
Decision Table とは別に、ルールテンプレートという機能もある。テンプレートから DRL を生成する。むしろ Decision Table が ルールテンプレート の1バリエーション。でも、まあただのテキスト処理だし、何使ってもいいんじゃね?
6.6. Logging
これは普通の、Drools自体のログのはなし。SLF4Jです。