7.3.3. 永続性を使用するためのエンジン設定
jbpm-test
モジュールの JBPMHelper
クラスには、セッションを作成するメソッドがあり、設定ファイルを使用してこのセッションを設定します。以下の情報は、永続性が有効になっている H2 in-memory データゲースを使用する jBPM.properties ファイルの例を紹介しています。
例7.1 jBPM.properties ファイルの例
# for creating a datasource persistence.datasource.name=jdbc/jbpm-ds persistence.datasource.user=sa persistence.datasource.password= persistence.datasource.url=jdbc:h2:tcp://localhost/~/jbpm-db persistence.datasource.driverClassName=org.h2.Driver # for configuring persistence of the session persistence.enabled=true persistence.persistenceunit.name=org.jbpm.persistence.jpa persistence.persistenceunit.dialect=org.hibernate.dialect.H2Dialect # for configuring the human task service taskservice.enabled=true taskservice.datasource.name=org.jbpm.task taskservice.transport=mina taskservice.usergroupcallback=org.jbpm.task.service.DefaultUserGroupCallbackImpl
JBPMHelper
クラスを使用してデータソースを登録することができます。
JBPMHelper.setupDataSource();
また、
JBPMHelper
クラスは、セッションの作成にも使用可能です (ナレッジベースが作成された後)。
StatefulKnowledgeSession ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
メソッドは、この ksession (例:
startProcess
) で呼び出すことが可能となり、エンジンは作成したデータソースですべてのランタイムのステータスを永続化します。
さらに、
JBPMHelper
クラスは、セッション ID を渡すことでデータベースからセッションのステータスをリストアしてセッションを再作成する際に使用できます。セッション ID は ksession.getId()
を使用してリトリーブします。
StatefulKnowledgeSession ksession = JBPMHelper.loadStatefulKnowledgeSession(kbase, sessionId);