[jbpm-commits] JBoss JBPM SVN: r2263 - in jbpm4/pvm/trunk/modules: core/src/main/java/org/jbpm/pvm/internal/spring and 9 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Sep 16 08:40:52 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-09-16 08:40:52 -0400 (Tue, 16 Sep 2008)
New Revision: 2263

Added:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedTests.java
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Loan.hbm.xml
   jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.db.png
Removed:
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Order.hbm.xml
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/ExecutionType.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/JbpmTestCase.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedPersistenceTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/Loan.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/spring/SpringTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
   jbpm4/pvm/trunk/modules/core/src/test/resources/hibernate.properties
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/hibernate.cfg.xml
   jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml
   jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch03-Architecture.xml
Log:
docs

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/ExecutionType.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/ExecutionType.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/ExecutionType.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -16,6 +16,7 @@
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.NodeImpl;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.internal.util.ReflectUtil;
 
 public class ExecutionType implements UserType, ParameterizedType {
 
@@ -57,10 +58,10 @@
     }
     Class<?> ownerClass = owner.getClass();
     try {
-      Method method = ownerClass.getMethod("getProcessDefinition");
-      processDefinition = (ProcessDefinitionImpl) method.invoke(null, (Object[]) null);
+      Method method = ownerClass.getDeclaredMethod("getProcessDefinition");
+      processDefinition = (ProcessDefinitionImpl) ReflectUtil.invoke(method, null, null);
     } catch (Exception e) {
-      throw new RuntimeException("couldn't get process definition for "+owner);
+      throw new RuntimeException("couldn't get process definition for "+owner, e);
     }
     
     return processDefinition;

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -42,9 +42,6 @@
     addContext(new SpringEnvironmentContext(springEnvironmentFactory.getApplicationContext()));
   }
 
-  public void close() {
-  }
-
   public ClassLoader getClassLoader() {
     return null;
   }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/JbpmTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/JbpmTestCase.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/JbpmTestCase.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -38,12 +38,14 @@
   }
 
   public void setUp() throws Exception {
+    assertNull(Environment.getCurrent());
     LogFormatter.resetIndentation();
     log.info("=== starting "+getName()+" =============================");
   }
 
   public void tearDown() throws Exception {
     log.info("=== ending "+getName()+" =============================\n");
+    assertNull(Environment.getCurrent());
   }
 
   public void assertTextPresent(String expected, String value) {

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -25,6 +25,7 @@
 import junit.framework.TestSuite;
 
 import org.jbpm.pvm.api.db.continuation.ContinuationTests;
+import org.jbpm.pvm.api.db.embedded.EmbeddedTests;
 import org.jbpm.pvm.api.db.svc.DbSvcTests;
 import org.jbpm.pvm.api.spring.SpringTests;
 import org.jbpm.pvm.api.tx.TxTests;
@@ -57,8 +58,9 @@
     TestSuite variableTypeTests = new TestSuite(VariableCustomTypeTest.class);
     suite.addTest(new EnvironmentFactoryTestSetup(variableTypeTests, "org/jbpm/pvm/internal/db/type/environmentCustomTypes.cfg.xml"));
 
-    // Spring tests do not use EnvironmentFactoryTestCase
+    // These tests do not use EnvironmentFactoryTestCase
     suite.addTest(SpringTests.suite());
+    suite.addTest(EmbeddedTests.suite());
 
     //$JUnit-END$
     return suite;

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedPersistenceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedPersistenceTest.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedPersistenceTest.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -52,12 +52,14 @@
     loan = (Loan) session.get(Loan.class, loan.getDbid());
     assertEquals("evaluate", loan.getState());
     loan.approve();
-    assertEquals("end", loan.getState());
+    assertEquals("archive", loan.getState());
     
     newTransaction();
     
     loan = (Loan) session.get(Loan.class, loan.getDbid());
-    assertEquals("validate", loan.getState());
+    assertEquals("archive", loan.getState());
+    loan.archiveComplete();
+    assertEquals("end", loan.getState());
 
     commitTransaction();
   }
@@ -77,13 +79,13 @@
     
     loan = (Loan) session.get(Loan.class, loan.getDbid());
     assertEquals("evaluate", loan.getState());
-    loan.approve();
+    loan.reject();
     assertEquals("end", loan.getState());
     
     newTransaction();
     
     loan = (Loan) session.get(Loan.class, loan.getDbid());
-    assertEquals("validate", loan.getState());
+    assertEquals("end", loan.getState());
   }
 
 

Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedTests.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/EmbeddedTests.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -0,0 +1,17 @@
+package org.jbpm.pvm.api.db.embedded;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+public class EmbeddedTests {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite("org.jbpm.pvm.api.db.embedded");
+    //$JUnit-BEGIN$
+    suite.addTestSuite(EmbeddedPersistenceTest.class);
+    //$JUnit-END$
+    return suite;
+  }
+
+}

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/Loan.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/Loan.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/embedded/Loan.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -31,7 +31,7 @@
  */
 public class Loan {
 
-  // the loan process definition as a static resource
+  /** the loan process definition as a static resource */
   private static final ClientProcessDefinition processDefinition = createLoanProcess();
   
   private static ClientProcessDefinition createLoanProcess() {
@@ -51,12 +51,17 @@
     return processDefinition;
   }
 
+  /** exposes the process definition to the execution hibernate type */
+  private static ClientProcessDefinition getProcessDefinition() {
+    return processDefinition;
+  }
+
   long dbid;
   String customer;
   double amount;
   ClientExecution execution;
   
-  // constructor for persistence
+  /** constructor for persistence */
   protected Loan() {
   }
 
@@ -79,9 +84,9 @@
   }
 
   public String getState() {
-    return execution.getNode().getName();
+    return execution.getNodeName();
   }
-
+  
   // getters //////////////////////////////////////////////////////////////////
 
   public long getDbid() {

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/spring/SpringTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/spring/SpringTest.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/spring/SpringTest.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -40,6 +40,8 @@
     EnvironmentFactory environmentFactory = (EnvironmentFactory) applicationContext.getBean("environmentFactory");
     
     CommandService commandService = environmentFactory.get(CommandService.class);
+    
+    assertNull(Environment.getCurrent());
 
     Session session = (Session) commandService.execute(new Command<Object>() {
       public Object execute(Environment environment) throws Exception {
@@ -54,6 +56,8 @@
 
     assertFalse(session.isOpen());
 
+    assertNull(Environment.getCurrent());
+
     /* TODO translate the DeployerManager to a data structure that is 
      * easy to wire up with spring
     ProcessService processService = environmentFactory.get(ProcessService.class);

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java	2008-09-16 12:40:52 UTC (rev 2263)
@@ -110,7 +110,7 @@
 
   public void testExclusiveMessageProcessing() {
     insertExclusiveTestMessages();
-
+    
     JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
     jobExecutor.start();
     try {
@@ -121,7 +121,6 @@
       jobExecutor.stop(true);
     }
 
-    
     commandService.execute(new Command<Object>() {
       public Object execute(Environment environment) throws Exception {
         // exclusiveMessageIds maps execution keys to a set of thread ids.
@@ -297,7 +296,6 @@
         return null;
       }
     });
-    Environment environment = getEnvironmentFactory().openEnvironment();
   }
 
   

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/hibernate.properties
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/hibernate.properties	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/hibernate.properties	2008-09-16 12:40:52 UTC (rev 2263)
@@ -9,5 +9,3 @@
 # hibernate.show_sql                     true
 hibernate.format_sql                   true
 hibernate.use_sql_comments             true
-
-hibernate.jdbc.batch_size              0
\ No newline at end of file

Copied: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Loan.hbm.xml (from rev 2248, jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Order.hbm.xml)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Loan.hbm.xml	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Loan.hbm.xml	2008-09-16 12:40:52 UTC (rev 2263)
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE hibernate-mapping PUBLIC 
+          "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
+          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.jbpm.pvm.api.db.embedded" default-access="field">
+
+  <typedef name="execution" class="org.jbpm.pvm.internal.hibernate.ExecutionType" />
+
+  <class name="Loan" table="LOAN">
+
+    <id name="dbid">
+      <generator class="sequence"/>
+    </id>
+
+    <property name="execution" type="execution" />
+    <property name="customer" />
+    <property name="amount" />
+    
+  </class>
+
+</hibernate-mapping>
\ No newline at end of file


Property changes on: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Loan.hbm.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Deleted: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Order.hbm.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Order.hbm.xml	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/Order.hbm.xml	2008-09-16 12:40:52 UTC (rev 2263)
@@ -1,18 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.jbpm.pvm.api.db.embedded" default-access="field">
-
-  <typedef name="execution" class="org.jbpm.pvm.internal.hibernate.ExecutionType" />
-
-  <class name="Order" table="ORDERS">
-
-    <id name="dbid">
-      <generator class="sequence"/>
-    </id>
-
-    <property name="processInstance" type="execution" />
-    
-  </class>
-
-</hibernate-mapping>
\ No newline at end of file

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/hibernate.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/hibernate.cfg.xml	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/embedded/hibernate.cfg.xml	2008-09-16 12:40:52 UTC (rev 2263)
@@ -17,7 +17,7 @@
     <property name="hibernate.format_sql">true"</property>
     <property name="hibernate.use_sql_comments">true"</property>
     
-    <mapping resource="org/jbpm/pvm/api/db/embedded/Order.hbm.xml"/>
+    <mapping resource="org/jbpm/pvm/api/db/embedded/Loan.hbm.xml"/>
     
   </session-factory>
 </hibernate-configuration>

Added: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.db.png
===================================================================
(Binary files differ)


Property changes on: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/images/loan.db.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch02-ExecutionModes.xml	2008-09-16 12:40:52 UTC (rev 2263)
@@ -134,9 +134,7 @@
     &lt;hibernate-session-factory /&gt;
     
     &lt;id-generator /&gt;
-    
     &lt;variable-types resource=&quot;org/jbpm/pvm/pvm.types.xml&quot; /&gt;
-
     &lt;job-executor auto-start=&quot;false&quot; /&gt;
   
   &lt;/environment-factory&gt;
@@ -150,6 +148,19 @@
   &lt;/environment&gt;
 
 &lt;/contexts&gt;</programlisting>
+      <para>And next to it a hibernate.properties like this</para>
+      <literal>hibernate.properties:</literal>
+      <programlisting>hibernate.dialect                      org.hibernate.dialect.HSQLDialect
+hibernate.connection.driver_class      org.hsqldb.jdbcDriver
+hibernate.connection.url               jdbc:hsqldb:mem:.
+hibernate.connection.username          sa
+hibernate.connection.password
+hibernate.hbm2ddl.auto                 create-drop
+hibernate.cache.use_second_level_cache true
+hibernate.cache.provider_class         org.hibernate.cache.HashtableCacheProvider
+# hibernate.show_sql                     true
+hibernate.format_sql                   true
+hibernate.use_sql_comments             true</programlisting>
       <para>Then you can obtain the services from the environment factory like this:
       </para>
       <programlisting>EnvironmentFactory environmentFactory = new PvmEnvironmentFactory(&quot;environment.cfg.xml&quot;);
@@ -157,15 +168,224 @@
 processService = environmentFactory.get(ProcessService.class);
 executionService = environmentFactory.get(ExecutionService.class);
 managementService = environmentFactory.get(ManagementService.class);</programlisting>
-      <para>
+      <para>The responsibility of the <literal>ProcessService</literal> is to manage
+      the repository of process definitions.  Before we can start a process execution, 
+      the process definition needs to be deployed into the process repository.
+      Process definitions can be supplied in various formats and process definition 
+      languages.  A deployment collects process definition information from various 
+      sources like a ZIP file, an XML file or a process definition object.
+      The method <literal>ProcessService.deploy</literal> will take a deployment 
+      through all the deployers that are configured in the configuration file.    
       </para>
-    </section>
+      <para>In this example, we'll supply a process definition programmatically
+      for deployment.</para>
+      <programlisting>ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
+  .node("submit loan request").initial().behaviour(AutomaticActivity.class)
+    .transition().to("evaluate")
+  .node("evaluate").behaviour(WaitState.class)
+    .transition("approve").to("wire money")
+    .transition("reject").to("end")
+  .node("wire money").behaviour(AutomaticActivity.class)
+    .transition().to("archive")
+  .node("archive").behaviour(WaitState.class)
+    .transition().to("end")
+  .node("end").behaviour(WaitState.class)
+.done();
 
+Deployment deployment = new Deployment(processDefinition);
+processService.deploy(deployment);</programlisting>
+    <para>Now, a version of that process definition is stored in the database. 
+    The <literal>check-version</literal> deployer will have assigned version 1 
+    to the  stored process definition.  The <literal>create-id</literal> deployer 
+    will have distilled id <literal>loan:1</literal> from the process name and the 
+    assigned version.
+    </para>
+    <para>Deploying that process again will lead to a new process definition 
+    version being created in the database.  But an incremented version number will 
+    be assigned.  For the purpose of versioning, process definitions are considered 
+    equal if they have the same name.</para>
+    <para>It is recommended that a user provided key reference is supplied for 
+    all process executions.  Starting a new process execution goes like this:
+    </para>
+    <programlisting>Execution execution = executionService.startExecution("loan:1", "request7836");</programlisting>
+    <para>The return value is an execution interface, which prevents navigation of relations.  
+    That is because outside of the service methods, the transaction and hibernate session 
+    is not guaranteed to still be open.  In fact, the default configuration as given 
+    above will only keep the transaction and session open for the duration of the
+    service method.  So navigating the relations outside of the service methods might result 
+    into a hibernate <literal>LazyInitializationException</literal>.  But the 
+    current node name can still be verified:
+    </para>
+    <programlisting>assertEquals("evaluate", execution.getNodeName());</programlisting>
+    <para>Also very important is the generated id that can be obtained.  The default 
+    <literal>id-generator</literal> will use the process definition id and the 
+    given key to make a unique id for the process execution like this:</para>
+    <programlisting>assertEquals("loan:1/request7836", execution.getId());</programlisting>
+    <para>That id must be when providing the subsequent external triggers to the 
+    process execution like this:
+    </para>
+    <programlisting>executionService.signalExecution("loan:1/request7836", "approve");</programlisting>
+  </section>
+
   <section id="embeddedexecutionmode">
     <title>Embedded execution mode</title>
     <para>Embedded execution mode means that the state of a process is stored 
-    as a string column inside a user domain object like e.g. an Order.
+    as a string column inside a user domain object like e.g. a loan.
     </para>
+    <programlisting>public class Loan {
+
+  <emphasis role="bold">/** the loan process definition as a static resource */
+  private static final ClientProcessDefinition processDefinition = createLoanProcess();
+  
+  private static ClientProcessDefinition createLoanProcess() {
+    ClientProcessDefinition processDefinition = ProcessFactory.build(&quot;loan&quot;)
+      .node(&quot;submit loan request&quot;).initial().behaviour(AutomaticActivity.class)
+        .transition().to(&quot;evaluate&quot;)
+      .node(&quot;evaluate&quot;).behaviour(WaitState.class)
+        .transition(&quot;approve&quot;).to(&quot;wire money&quot;)
+        .transition(&quot;reject&quot;).to(&quot;end&quot;)
+      .node(&quot;wire money&quot;).behaviour(AutomaticActivity.class)
+        .transition().to(&quot;archive&quot;)
+      .node(&quot;archive&quot;).behaviour(WaitState.class)
+        .transition().to(&quot;end&quot;)
+      .node(&quot;end&quot;).behaviour(WaitState.class)
+    .done();
+    
+    return processDefinition;
+  }
+
+  /** exposes the process definition to the execution hibernate type */
+  private static ClientProcessDefinition getProcessDefinition() {
+    return processDefinition;
+  }
+  </emphasis>
+
+  long dbid;
+  String customer;
+  double amount;
+  <emphasis role="bold">ClientExecution execution;</emphasis>
+  
+  /** constructor for persistence */
+  protected Loan() {
+  }
+
+  public Loan(String customer, double amount) {
+    this.customer = customer;
+    this.amount = amount;
+    <emphasis role="bold">this.execution = processDefinition.startProcessInstance();</emphasis>
+  }
+
+  public void approve() {
+    <emphasis role="bold">execution.signal(&quot;approve&quot;);</emphasis>
+  }
+
+  public void reject() {
+    <emphasis role="bold">execution.signal(&quot;reject&quot;);</emphasis>
+  }
+
+  public void archiveComplete() {
+    <emphasis role="bold">execution.signal();</emphasis>
+  }
+
+  public String getState() {
+    return <emphasis role="bold">execution.getNodeName()</emphasis>;
+  }
+
+  ...getters...
+}</programlisting>
+    <para>If you ignore the bold parts for a second, you can see that this is a 
+    POJO without anything fancy.  It's just a bean that can be stored with hibernate. 
+    The bold part indicate that implementation part of the class that is related 
+    to process and execution.  Not that nothing of the process definition or 
+    execution is exposed to the user of the Loan class.
+    </para>
+    <para>Each <literal>Loan</literal> object corresponds to a <literal>loan</literal> 
+    process instance.  Some methods of the <literal>Loan</literal> class correspond 
+    to the external triggers that need to be given during the lifecycle of a
+    <literal>Loan</literal> object.
+    </para>
+    <para>Next we'll show how to use this class.  To get started we need a</para>
+    <emphasis role="bold"><literal>hibernate.cfg.xml:</literal></emphasis>
+    <programlisting>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+
+&lt;!DOCTYPE hibernate-configuration PUBLIC
+          &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
+          &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
+
+&lt;hibernate-configuration&gt;
+  &lt;session-factory&gt;
+
+    &lt;property name=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.HSQLDialect&lt;/property&gt;
+    &lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;org.hsqldb.jdbcDriver&lt;/property&gt;
+    &lt;property name=&quot;hibernate.connection.url&quot;&gt;jdbc:hsqldb:mem:.&lt;/property&gt;
+    &lt;property name=&quot;hibernate.connection.username&quot;&gt;sa&lt;/property&gt;
+    &lt;property name=&quot;hibernate.connection.password&quot;&gt;&lt;/property&gt;
+    &lt;property name=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/property&gt;
+    &lt;property name=&quot;hibernate.show_sql&quot;&gt;true&quot;&lt;/property&gt;
+    &lt;property name=&quot;hibernate.format_sql&quot;&gt;true&quot;&lt;/property&gt;
+    &lt;property name=&quot;hibernate.use_sql_comments&quot;&gt;true&quot;&lt;/property&gt;
+    
+    &lt;mapping resource=&quot;Loan.hbm.xml&quot;/&gt;
+    
+  &lt;/session-factory&gt;
+&lt;/hibernate-configuration&gt;</programlisting>
+    <para>And a</para>
+    <emphasis role="bold"><literal>Loan.hbm.xml:</literal></emphasis>
+    <programlisting>&lt;?xml version=&quot;1.0&quot;?&lt;
+
+&lt;!DOCTYPE hibernate-mapping PUBLIC 
+          &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot; 
+          &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&lt;
+
+&lt;hibernate-mapping package=&quot;org.jbpm.pvm.api.db.embedded&quot; default-access=&quot;field&quot;&lt;
+
+  &lt;typedef name=&quot;execution&quot; class=&quot;org.jbpm.pvm.internal.hibernate.ExecutionType&quot; /&lt;
+
+  &lt;class name=&quot;Loan&quot; table=&quot;LOAN&quot;&lt;
+
+    &lt;id name=&quot;dbid&quot;&lt;
+      &lt;generator class=&quot;sequence&quot;/&lt;
+    &lt;/id&lt;
+
+    &lt;property name=&quot;execution&quot; type=&quot;execution&quot; /&lt;
+    &lt;property name=&quot;customer&quot; /&lt;
+    &lt;property name=&quot;amount&quot; /&lt;
+    
+  &lt;/class&lt;
+
+&lt;/hibernate-mapping&lt;</programlisting>
+    <para>Then you can use the Loan class like this in a test</para>
+    <programlisting>Configuration configuration = new Configuration();
+configuration.configure();
+SessionFactory sessionFactory = configuration.buildSessionFactory();
+
+// start a session/transaction
+Session session = sessionFactory.openSession();
+Transaction transaction = session.beginTransaction();
+
+Loan loan = new Loan("john doe", 234.0);
+session.save(loan);
+assertEquals("evaluate", loan.getState());
+
+// start a new session/transaction
+transaction.commit();
+session.close();
+session = sessionFactory.openSession();
+transaction = session.beginTransaction();
+
+loan = (Loan) session.get(Loan.class, loan.getDbid());
+assertEquals("evaluate", loan.getState());
+loan.approve();
+assertEquals("archive", loan.getState());
+
+// start a new session/transaction
+transaction.commit();
+session.close();</programlisting>
+    <para>After executing this code snippet, this is the loan record in the DB:</para>
+    <figure id="loan.db">
+      <title>The loan record in the DB</title>
+      <mediaobject><imageobject><imagedata align="center" fileref="images/loan.db.png"/></imageobject></mediaobject>
+    </figure>
   </section>
 
 </chapter>
\ No newline at end of file

Modified: jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch03-Architecture.xml
===================================================================
--- jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch03-Architecture.xml	2008-09-16 11:56:56 UTC (rev 2262)
+++ jbpm4/pvm/trunk/modules/manual/src/main/docbook/en/modules/ch03-Architecture.xml	2008-09-16 12:40:52 UTC (rev 2263)
@@ -4,8 +4,9 @@
   <section id="apis">
     <title>APIs</title>
     <para>The Process Virtual Machine has 4 integrated API's that together 
-    offer a complete coverage of working with processes.  Each of the APIs has a 
-    specific purpose
+    offer a complete coverage of working with processes in the different execution modes.  
+    Each of the APIs has a specific purpose that fits within the following overall 
+    architecture.
     </para>
     <figure id="apis">
       <title>The 4 API's of the Process Virtual Machine</title>
@@ -26,27 +27,124 @@
     process events.  It's very similar to the activity API with that exception that event listeners
     are not able to control the flow of execution. 
     </para> 
-  </section>  
+  </section>
   
   <section>
-    <title>Configuration</title>
-    <para>
+    <title>Activity API</title>
+    <para>The activity API allows to implement the runtime activity behaviour in Java.
     </para>
+    <programlisting>public interface Activity extends Serializable {
+  void execute(ActivityExecution execution) throws Exception;
+}</programlisting>
+    <para>An activity is the behaviour of the node to which it is associated.
+    The provided execution is the execution that arrives in the node.
+    The interface <literal>ActivityExecution</literal> exposes special 
+    methods to control the execution flow.
+    </para>
+    <programlisting>public interface ActivityExecution extends OpenExecution {
+
+  void waitForSignal();
+  void takeDefaultTransition();
+  void take(String transitionName);
+  void execute(String nodeName);
+
+  Execution createExecution();
+  void removeExecution(Execution child);
+  
+  ClientProcessInstance createSubProcessInstance(ClientProcessDefinition processDefinition);
+  
+  ...
+
+}</programlisting>
   </section>
+
   <section>
+    <title>Event listener API</title>
+    <para>The event listener API allows for listeners to be developed in Java code 
+    and that are invoked on specific process events like entering a node or leaving 
+    a node.  It is very similar to the activity API, but the difference is  
+    that the propagation of the execution flow cannot be controlled.  E.g. when an execution 
+    is taking a transition, a listener to that event can be notified, but since the 
+    transition is already being taking, the execution flow cannot be changed 
+    by the event listeners.  
+    </para>
+    <programlisting>public interface EventListener extends Serializable {
+  
+  void notify(EventListenerExecution execution) throws Exception;
+
+}</programlisting>
+  </section>
+
+  <section>
+    <title>Client API</title>
+    <para>The client API was already introduced above in the object execution mode 
+    and embedded execution mode.  It's an interface that exposes the methods for 
+    managing executions on the plain process definition and execution objects directly. 
+    </para>
+    <para>At a minimal, the client API and the activity API are needed to create 
+    some a process definition with activities and execute it.
+    </para>
+  </section>
+
+  <section>
     <title>Environment</title>
-    <para>
+    <para>In the persistent execution mode, the first purpose of the environment is 
+    to enable processes to be executed in different transactional environments like 
+    standard Java, enterprise Java, SEAM and Spring.
     </para>
+    <para>The PVM code itself will only use transactional resources through self-defined 
+    interfaces.  For example, the PVM itself has interfaces for some methods on the hibernate 
+    session, a async messaging session and a timer session.
+    </para>
+    <para>The environment allows to configure the actual implementations, lazy 
+    initialization of the services on a request-basis and caching the service 
+    objects for the duration of the transaction. 
+    </para>
+    <para>An environment factory is static and one environment factory can serve 
+    all the threads in an application.
+    </para>
+    <programlisting>EnvironmentFactory environmentFactory = new PvmEnvironmentFactory("environment.cfg.xml");</programlisting>
+    <para>Environment blocks can surround persistent process operations 
+    like this:
+    </para>
+    <programlisting>Environment environment = environmentFactory.openEnvironment();
+try {
+
+  ... inside the environment block...
+
+} finally {
+  environment.close();
+}</programlisting>
+    <para>The PVM itself will fetch all it's transactional resources and configurations 
+    from the environment.
+    </para>
   </section>
+
   <section>
     <title>Commands</title>
-    <para>
+    <para>Commands encapsulate operations that are to be executed within an environment 
+    block.  The main purpose for commands is to capture the logic of 
     </para>
+    <programlisting>public interface Command&lt;T&gt; extends Serializable {
+
+  T execute(Environment environment) throws Exception;
+
+}</programlisting>
+    <para></para>
   </section>
+
   <section>
     <title>Services</title>
+    <para>Services are session facades that expose methods for persistent usage of 
+    the PVM.  
+    </para>
+  </section>
+
+  <section>
+    <title>Configuration</title>
     <para>
     </para>
   </section>
 
+
 </chapter>
\ No newline at end of file




More information about the jbpm-commits mailing list