Show Table of Contents
6.5. アクション
アクションは、実行プロセスの中で、 イベント上で実行される Java コードの一部です。グラフは、ソフトウェア要件を伝達する重要な道具ですが、作成されるソフトウェアの単なるビュー (投影) にすぎず、 多くの技術的な詳細を隠します。 また、アクションは、グラフ表現とは別に、技術的な詳細を追加するメカニズムで、グラフが導入されると、アクションを付け足すことが可能です。 主なイベントタイプは、 entering a node、leaving a node、taking a transitionです。
重要
ノードに置かれたアクションと、イベントに置かれたアクションとでは違いがあることに注意してください。 イベントに置かれたアクションは、イベントが起動された時に実行されます。 プロセスの制御フローに影響を与えることはありませ ん(オブザーバーパターンに似ています)。 一方で、ノードに置かれたアクションは、 実行を渡す責務があります。
本項を読んで、 イベント上のアクション例を見てみましょう。 決められた遷移上で、 データベースを更新する方法を表しています (データベースの更新は技術的に重要ですが、ビジネスアナリストにとっては重要ではありません)。

図6.2 データベース更新のアクション
public class RemoveEmployeeUpdate implements ActionHandler {
public void execute(ExecutionContext ctx) throws Exception {
// get the fired employee from the process variables.
String firedEmployee =
(String) ctx.getContextInstance().getVariable("fired employee");
// by taking the same database connection as used for the jbpm
// updates, we reuse the jbpm transaction for our database update.
Connection connection =
ctx.getProcessInstance().getJbpmSession().getSession().getConnection();
Statement statement = connection.createStatement();
statement.execute("DELETE FROM EMPLOYEE WHERE ...");
statement.execute();
statement.close();
}
}<process-definition name="yearly evaluation">
<state name="fire employee">
<transition to="collect badge">
<action class="com.nomercy.hr.RemoveEmployeeUpdate" />
</transition>
</state>
<state name="collect badge">
</process-definition>注記
カスタムアクションへの設定の追加については 「委譲設定」 を参照してください。
6.5.1. アクション参照
アクションに名前を付けることが可能です。 名前を付けると、 アクションが指定されている他の場所からアクションを参照することができます。 名前付きのアクションを子要素としてプロセス定義へ追加することも可能です。
この機能を使用してアクション設定の重複に制限を設けます (アクションの設定が複雑であったり、 ランタイムのアクションをスケジュールしたり実行したりする必要がある場合に便利です)。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.