イベントからのエンティティーの初期化

エンティティーが必要なとき、それらを参照する最初のイベントの受信時に初期化することができます。 ビジネス・モデル・ステートメント・タブでビジネス・ルール言語を使用して、イベントからのエンティティーの初期化を宣言します。

ステートメントでは、初期化するエンティティーと、それを初期化するイベントを指定します。

エンティティーの初期化の画面キャプチャー。
  1. バインド・エンティティーのタイプ。
  2. 処理されるイベント・タイプ。
  3. バインド・エンティティー。
  4. イベント内のバインド・エンティティーに対応する ID を取得する式。
  5. オプション: バインド・エンティティーの属性の初期化。
  6. オプション: イベント・タイプへの属性のマッピング。
構成体のアクション部分で、さまざまなタイプのアクションを記述することができます。
  • バインド・エンティティーの属性を指定します。
  • バインド・エンティティーを初期化した結果としてイベントを送信します。
最後のアクションが整数で終わる場合、ピリオドの前にスペースを追加する必要があります。アクションを指定しない場合は、構成体の最初の部分の終わりのコロンをピリオドに置き換えてください。
制約事項: エンティティーの初期化は、イベント・タイプとイベント・エンティティーの関係の組み合わせごとに一度だけ定義できます。イベントが同じタイプの 2 つのエンティティーに関連している場合、それぞれの関連しているエンティティーに独自の初期化ステートメントを使用できます。

また、 Java™ ベースのエンティティー初期化拡張機能を使用して、外部データ・ソースからエンティティーを初期化することも可能です。詳しくは、エンティティー初期化拡張の作成を参照してください。

例

次の例では、顧客 (customer) が銀行の口座を開設した (open account) ときに、 account エンティティーが初期化されます。 与信限度 (credit limit) とこの口座の顧客 (customer of this account) が、ルールのアクション部分で定義されます。 さらに、初期化された account エンティティーが、 customer リモート・エンティティーのエンティティーに追加されます。 ここで、customer エンティティーは、 名前で識別されていくつかの口座に関係するビジネス・エンティティーとして、ビジネス・モデルで定義されます。

an account is initialized from an open account event, where this account comes from the account of this open account event:
    - set the credit limit of this account to the limit of this open account event
    - set the customer of this account to the customer of this open account event
    - add this account to the accounts of the customer of this open account event.

次の例では、 new customer event が発生したときに customer エンティティーが初期化されます。ここで、このイベントは、名前を持つビジネス・イベントとしてビジネス・モデルで定義されています。 customer エンティティーに関係し、credit limit が 10,000 である new open account イベントをこの初期化で起動することを、ルールのアクション部分で指定します。

a customer is initialized from a new customer event, where this customer comes from the name of this new customer event:
    - emit a new open account event where the customer is this customer, the limit is 10,000 .

次の例では、 account エンティティーがアクションなしで初期化されます。

an account is initialized from an open account event, where this account comes from the account of this open account event.

エンティティーおよびイベント・タイプの階層におけるエンティティーの初期化

2 つ以上の初期化指定子がエンティティー・タイプの階層で宣言されている場合、その優先度は、当該階層に基づきます。 最も一般的なエンティティー・タイプが優先されます。

例 1

以下のビジネス・モデルでは、vehicle、car、vehicle activity、および car activity を定義します。car エンティティー・タイプは vehicle エンティティー・タイプの特殊化であり、car activity イベント・タイプは vehicle activity イベント・タイプの特殊化です。

a vehicle is a business entity identified by a vehicle id ( text ).

a car is a vehicle.
a car has a passenger capacity ( integer ).

a vehicle activity is a business event time-stamped by an event timestamp ( date & time ).
a vehicle activity is related to a vehicle.

a car activity is a vehicle activity. 

以下の初期化をビジネス・モデル・ステートメントで宣言できます。同じエンティティー・タイプを 2 つの異なるイベント・タイプによって初期化できます。ここで、最初の初期化ステートメントの優先度が高くなっています。これは、初期化をトリガーする vehicle activity イベント・タイプは、car activity イベント・タイプよりも一般的であるためです。

a vehicle is initialized from a vehicle activity, where this vehicle comes from the vehicle of this vehicle activity.

a vehicle is initialized from a car activity, where this vehicle comes from the vehicle of this car activity. 

例 2

ビジネス・エンティティーの階層、ビジネス・イベントの階層、およびエンティティー・タイプの 2 つの初期化指定子について検討します。

ビジネス・モデル定義:

a vehicle is a business entity identified by a vehicle id ( text ).

a car is a vehicle.
a car has a cost (numeric).

a leased car is a car.
a leased car has a monthly payment (numeric).

a car acquisition is a business event.
a car acquisition is related to a vehicle.
a car acquisition has an price (numeric).

a car leasing is a car acquisition.
a car leasing has a duration in months (numeric).
a car leasing has an initial payment (numeric).
a car leasing has a monthly payment (numeric).

ビジネス・モデル・ステートメント:

a car is initialized from a car acquisition , where this car comes from the vehicle of this car acquisition:
   - set the cost of this car to the price of this car acquisition.

a leased car is initialized from a car leasing , where this leased car comes from the vehicle of this car leasing:
   - set the monthly payment of this leased car to the monthly payment of this car leasing
   - set the cost of this leased car to the initial payment of this car leasing +
      the monthly payment of this car leasing * the duration in months of this car leasing.

最初の初期化指定子は、タイプ car acquisition のイベントを処理し、タイプ car のエンティティーを初期化します。 2 番目の初期化指定子は、タイプ car leasing のイベントを処理し、タイプ leased car のエンティティーを初期化します。

タイプ car leasing のインスタンスであり、作成されていない vehicle エンティティーに関連するイベント E1 について検討します。 leased car 初期化指定子により、このエンティティーを初期化できます。タイプ car leasing は car acquisition のサブタイプであるため、このイベントもタイプ car acquisition のインスタンスです。そのため、car 初期化指定子も、イベントの作成されていない vehicle エンティティーを初期化できます。このコンテキストでは、vehicle エンティティーはタイプ leased car のインスタンスおよびタイプ car のインスタンスです。 タイプ leased car は、これらのタイプの中で最も具体的です。そのため、ランタイム・システムは、イベント E1 の vehicle エンティティーの作成時に、タイプ leased car をインスタンス化します。次に、この新たに作成されたエンティティーが、leased car 初期化指定子および car 初期化指定子によって初期化されます。これらの両方の初期化指定子がイベント E1 を処理します。最初の初期化指定子はこのエンティティーの monthly payment および cost を設定し、2 番目の初期化指定子は leased car の cost をイベントの price に拡張します。