activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r538915 - in /activemq/camel/trunk/camel-bam: ./ src/main/java/org/apache/camel/bam/ src/main/java/org/apache/camel/bam/model/ src/test/profiles/ src/test/profiles/hibernate/ src/test/profiles/hibernate/META-INF/ src/test/profiles/mysql/ sr...
Date Thu, 17 May 2007 13:28:25 GMT
Author: jstrachan
Date: Thu May 17 06:28:23 2007
New Revision: 538915

URL: http://svn.apache.org/viewvc?view=rev&rev=538915
Log:
finally got the test case working with the hibernate profile; haven't yet figured out how to fix some strange openjpa related exception (it'd be nice to make openjpa the default profile one day)

Added:
    activemq/camel/trunk/camel-bam/src/test/profiles/
    activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/
    activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/
    activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml   (with props)
    activemq/camel/trunk/camel-bam/src/test/profiles/mysql/
    activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/
    activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml   (with props)
    activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/
    activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/
    activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml   (with props)
Removed:
    activemq/camel/trunk/camel-bam/src/test/resources/META-INF/persistence.xml
Modified:
    activemq/camel/trunk/camel-bam/pom.xml
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityBuilder.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityMonitorEngine.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityRules.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessor.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessorSupport.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessContext.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessRules.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TemporalRule.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TimeExpression.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityDefinition.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
    activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/TemporalEntity.java

Modified: activemq/camel/trunk/camel-bam/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/pom.xml?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/pom.xml (original)
+++ activemq/camel/trunk/camel-bam/pom.xml Thu May 17 06:28:23 2007
@@ -60,13 +60,6 @@
     </dependency>
 
     <dependency>
-      <groupId>org.apache.openjpa</groupId>
-      <artifactId>openjpa-persistence-jdbc</artifactId>
-      <!-- mandatory dependency for the enhancer! -->
-      <!--<scope>test</scope>-->
-    </dependency>
-
-    <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
       <type>test-jar</type>
@@ -80,25 +73,28 @@
       <optional>true</optional>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.derby</groupId>
-      <artifactId>derby</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>commons-dbcp</groupId>
-      <artifactId>commons-dbcp</artifactId>
-      <version>1.2.1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>commons-collections</groupId>
-      <artifactId>commons-collections</artifactId>
-      <version>3.2</version>
+    <!--
+        <dependency>
+          <groupId>commons-dbcp</groupId>
+          <artifactId>commons-dbcp</artifactId>
+          <version>1.2.1</version>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>commons-collections</groupId>
+          <artifactId>commons-collections</artifactId>
+          <version>3.2</version>
+          <scope>test</scope>
+        </dependency>
+    -->
+
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <version>5.0.5</version>
       <scope>test</scope>
     </dependency>
 
-
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
@@ -106,60 +102,9 @@
     </dependency>
   </dependencies>
 
+
   <build>
     <plugins>
-
-      <!-- lets enhance the classes for OpenJPA (shame it can't do it at runtime!) -->
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-
-        <executions>
-          <execution>
-            <phase>process-test-classes</phase>
-            <configuration>
-              <tasks>
-                <path id="cp">
-                  <path refid="maven.test.classpath"/>
-                  <path refid="maven.compile.classpath"/>
-                  <path refid="maven.dependency.classpath"/>
-                </path>
-                <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
-                  <classpath refid="cp"/>
-                </taskdef>
-
-                <mkdir dir="${basedir}/target/jpa-classes"/>
-                <openjpac directory="${basedir}/target/jpa-classes">
-                  <classpath refid="cp"/>
-                  <fileset dir="${basedir}/target/classes">
-                    <include name="org/apache/camel/bam/model/*.class"/>
-                  </fileset>
-                </openjpac>
-                <copy overwrite="true" todir="${basedir}/target/classes">
-                  <fileset dir="${basedir}/target/jpa-classes"/>
-                </copy>
-
-<!--
-                <mkdir dir="${basedir}/target/jpa-test-classes"/>
-                <openjpac directory="${basedir}/target/jpa-test-classes">
-                  <classpath refid="cp"/>
-                  <fileset dir="${basedir}/target/test-classes">
-                    <include name="org/apache/camel/examples/*.class"/>
-                  </fileset>
-                </openjpac>
-                <copy overwrite="true" todir="${basedir}/target/test-classes">
-                  <fileset dir="${basedir}/target/jpa-test-classes"/>
-                </copy>
--->
-              </tasks>
-            </configuration>
-            <goals>
-              <goal>run</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
@@ -170,11 +115,174 @@
           </includes>
           <excludes>
             <!-- TODO FIXME ASAP -->
-            <exclude>**/BamRouteTest.*</exclude>
+            <!--<exclude>**/BamRouteTest.*</exclude>-->
           </excludes>
         </configuration>
       </plugin>
 
     </plugins>
   </build>
+
+  <profiles>
+
+    <profile>
+      <id>hibernate</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <build>
+        <testResources>
+          <testResource>
+            <directory>${basedir}/src/test/profiles/hibernate</directory>
+          </testResource>
+          <testResource>
+            <directory>${basedir}/src/test/resources</directory>
+          </testResource>
+        </testResources>
+      </build>
+      <dependencies>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate-entitymanager</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>hsqldb</groupId>
+          <artifactId>hsqldb</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.geronimo.specs</groupId>
+          <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+
+    <profile>
+      <id>mysql</id>
+      <build>
+        <testResources>
+          <testResource>
+            <directory>${basedir}/src/test/profiles/mysql</directory>
+          </testResource>
+          <testResource>
+            <directory>${basedir}/src/test/resources</directory>
+          </testResource>
+        </testResources>
+      </build>
+      <dependencies>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate-entitymanager</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>hsqldb</groupId>
+          <artifactId>hsqldb</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.geronimo.specs</groupId>
+          <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+
+    <profile>
+      <id>openjpa</id>
+      <build>
+        <testResources>
+          <testResource>
+            <directory>${basedir}/src/test/profiles/openjpa</directory>
+          </testResource>
+          <testResource>
+            <directory>${basedir}/src/test/resources</directory>
+          </testResource>
+        </testResources>
+
+        <!-- lets enhance the classes for OpenJPA (shame it can't do it at runtime!) -->
+        <plugins>
+
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+
+            <executions>
+              <execution>
+                <phase>process-test-classes</phase>
+                <configuration>
+                  <tasks>
+                    <path id="cp">
+                      <path refid="maven.test.classpath"/>
+                      <path refid="maven.compile.classpath"/>
+                      <path refid="maven.dependency.classpath"/>
+                    </path>
+                    <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
+                      <classpath refid="cp"/>
+                    </taskdef>
+
+                    <mkdir dir="${basedir}/target/jpa-classes"/>
+                    <openjpac directory="${basedir}/target/jpa-classes">
+                      <classpath refid="cp"/>
+                      <fileset dir="${basedir}/target/classes">
+                        <include name="org/apache/camel/bam/model/*.class"/>
+                      </fileset>
+                    </openjpac>
+                    <copy overwrite="true" todir="${basedir}/target/classes">
+                      <fileset dir="${basedir}/target/jpa-classes"/>
+                    </copy>
+
+                    <!--
+                                    <mkdir dir="${basedir}/target/jpa-test-classes"/>
+                                    <openjpac directory="${basedir}/target/jpa-test-classes">
+                                      <classpath refid="cp"/>
+                                      <fileset dir="${basedir}/target/test-classes">
+                                        <include name="org/apache/camel/examples/*.class"/>
+                                      </fileset>
+                                    </openjpac>
+                                    <copy overwrite="true" todir="${basedir}/target/test-classes">
+                                      <fileset dir="${basedir}/target/jpa-test-classes"/>
+                                    </copy>
+                    -->
+                  </tasks>
+                </configuration>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+
+        </plugins>
+      </build>
+
+      <dependencies>
+
+        <!-- mandatory dependency for the enhancer! -->
+        <dependency>
+          <groupId>org.apache.openjpa</groupId>
+          <artifactId>openjpa-persistence-jdbc</artifactId>
+          <!--<scope>test</scope>-->
+        </dependency>
+
+        <dependency>
+          <groupId>org.apache.derby</groupId>
+          <artifactId>derby</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
 </project>

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityBuilder.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityBuilder.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityBuilder.java Thu May 17 06:28:23 2007
@@ -37,7 +37,7 @@
     public ActivityBuilder(ProcessBuilder processBuilder, Endpoint endpoint) {
         this.processBuilder = processBuilder;
         this.endpoint = endpoint;
-        this.activityRules = new ActivityRules(processBuilder.getProcessRules());
+        this.activityRules = new ActivityRules(processBuilder);
         this.activityRules.setActivityName(endpoint.getEndpointUri());
     }
 

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityMonitorEngine.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityMonitorEngine.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityMonitorEngine.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityMonitorEngine.java Thu May 17 06:28:23 2007
@@ -23,9 +23,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.springframework.orm.jpa.JpaCallback;
 import org.springframework.orm.jpa.JpaTemplate;
-import org.springframework.transaction.support.TransactionTemplate;
-import org.springframework.transaction.support.TransactionCallbackWithoutResult;
 import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.support.TransactionTemplate;
 
 import javax.persistence.EntityManager;
 import javax.persistence.LockModeType;
@@ -38,13 +38,13 @@
  */
 public class ActivityMonitorEngine extends ServiceSupport implements Runnable {
     private static final Log log = LogFactory.getLog(ActivityMonitorEngine.class);
-
     private JpaTemplate template;
     private TransactionTemplate transactionTemplate;
     private ProcessRules rules;
     private int escalateLevel = 0;
     private long windowMillis = 1000L;
     private Thread thread;
+    private boolean useLocking = false;
 
     public ActivityMonitorEngine(JpaTemplate template, TransactionTemplate transactionTemplate, ProcessRules rules) {
         this.template = template;
@@ -52,6 +52,14 @@
         this.rules = rules;
     }
 
+    public boolean isUseLocking() {
+        return useLocking;
+    }
+
+    public void setUseLocking(boolean useLocking) {
+        this.useLocking = useLocking;
+    }
+
     public void run() {
         log.info("Starting to poll for timeout events");
 
@@ -93,22 +101,26 @@
         template.execute(new JpaCallback() {
             public Object doInJpa(EntityManager entityManager) throws PersistenceException {
                 // lets try lock the object first
-                entityManager.lock(activityState, LockModeType.WRITE);
-                if (activityState.getEscalationLevel() == escalateLevel) {
-                    try {
-                        rules.processExpired(activityState);
-                    }
-                    catch (Exception e) {
-                        log.error("Failed to process expiration of: " + activityState + ". Reason: " + e, e);
-                    }
-                    activityState.setEscalationLevel(escalateLevel + 1);
+                if (isUseLocking()) {
+                    log.info("Attempting to lock: " + activityState);
+                    entityManager.lock(activityState, LockModeType.WRITE);
+                    log.info("Grabbed lock: " + activityState);
+                }
+
+                try {
+                    rules.processExpired(activityState);
+                }
+                catch (Exception e) {
+                    log.error("Failed to process expiration of: " + activityState + ". Reason: " + e, e);
                 }
+                activityState.setEscalationLevel(escalateLevel + 1);
                 return null;
             }
         });
     }
 
     protected void doStart() throws Exception {
+        rules.start();
         thread = new Thread(this, "ActivityMonitorEngine");
         thread.start();
     }
@@ -117,5 +129,6 @@
         if (thread != null) {
             thread = null;
         }
+        rules.stop();
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityRules.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityRules.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityRules.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ActivityRules.java Thu May 17 06:28:23 2007
@@ -18,8 +18,13 @@
 
 import org.apache.camel.bam.model.ActivityDefinition;
 import org.apache.camel.bam.model.ActivityState;
+import org.apache.camel.bam.model.ProcessInstance;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.ServiceHelper;
+import org.apache.camel.impl.ServiceSupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.orm.jpa.JpaTemplate;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -29,25 +34,53 @@
  *
  * @version $Revision: $
  */
-public class ActivityRules {
+public class ActivityRules extends ServiceSupport {
     private static final transient Log log = LogFactory.getLog(ActivityRules.class);
+
     private int expectedMessages = 1;
-    private ActivityDefinition activity;
-    private ProcessRules process;
+    private ProcessRules processRules;
     private List<TemporalRule> rules = new ArrayList<TemporalRule>();
+    private ActivityDefinition activityDefinition;
     private String activityName;
+    private final ProcessBuilder builder;
 
-    public ActivityRules(ProcessRules process) {
-        this.process = process;
-        process.getActivities().add(this);
+    public ActivityRules(ProcessBuilder builder) {
+        this.builder = builder;
+        this.processRules = builder.getProcessRules();
+        processRules.getActivities().add(this);
+    }
+    
+    public void addRule(TemporalRule rule) {
+        rules.add(rule);
     }
 
-    public ActivityDefinition getActivity() {
-        return activity;
+    /**
+     * Handles overdue activities
+     */
+    public void processExpired(ActivityState activityState) throws Exception {
+        for (TemporalRule rule : rules) {
+            rule.processExpired(activityState);
+        }
+    }
+
+    public void processExchange(Exchange exchange, ProcessInstance process) {
+        for (TemporalRule rule : rules) {
+            rule.processExchange(exchange, process);
+        }
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+
+    public ActivityDefinition getActivityDefinition() {
+        if (activityDefinition == null) {
+            activityDefinition = builder.findOrCreateActivityDefinition(activityName);
+        }
+        return activityDefinition;
     }
 
-    public void setActivity(ActivityDefinition activity) {
-        this.activity = activity;
+    public void setActivityDefinition(ActivityDefinition activityDefinition) {
+        this.activityDefinition = activityDefinition;
     }
 
     public int getExpectedMessages() {
@@ -58,43 +91,22 @@
         this.expectedMessages = expectedMessages;
     }
 
-    public ProcessRules getProcess() {
-        return process;
-    }
-
-    /**
-     * Perform any assertions after the state has been updated
-     */
-    public void processExchange(ActivityState activityState, ProcessContext context) {
-
-        log.info("Received state: " + activityState
-                + " message count " + activityState.getReceivedMessageCount()
-                + " started: " + activityState.getTimeStarted()
-                + " completed: " + activityState.getTimeCompleted());
-
-/*
-        process.fireRules(activityState, context);
-
-        for (TemporalRule rule : rules) {
-            rule.evaluate(context, activityState);
-        }
-*/
+    public ProcessRules getProcessRules() {
+        return processRules;
     }
 
     public void setActivityName(String activityName) {
         this.activityName = activityName;
     }
 
-    public void addRule(TemporalRule rule) {
-        rules.add(rule);
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected void doStart() throws Exception {
+        ServiceHelper.startServices(rules);
     }
 
-    /**
-     * Handles overdue activities
-     */
-    public void processExpired(ActivityState activityState) throws Exception {
-        for (TemporalRule rule : rules) {
-            rule.processExpired(activityState);
-        }
+    protected void doStop() throws Exception {
+        ServiceHelper.stopServices(rules);
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessor.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessor.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessor.java Thu May 17 06:28:23 2007
@@ -42,22 +42,13 @@
     protected void processEntity(Exchange exchange, ProcessInstance process) throws Exception {
         log.info("Processing entity! - attempting to get the current state for process: " + process);
 
-        ActivityState state = process.getActivityState(getActivity());
-        log.info("Found activity: "+ state);
+        // lets force the lazy creation of this activity
+        ActivityRules rules = getActivityRules();
+        ActivityState state = process.getOrCreateActivityState(rules);
 
-        if (state == null) {
-            state = createActivityState(exchange, process);
-            state.setProcess(process);
+        state.processExchange(rules, new ProcessContext(exchange, rules, state));
 
-            log.info("Storing activity: "+ state + " with process: " + state.getProcess());
-            //getTemplate().persist(state);
-        }
-        ProcessContext context = new ProcessContext(exchange, getActivity(), state);
-
-        state.processExchange(getActivity(), context);
+        rules.getProcessRules().processExchange(exchange, process);
     }
 
-    protected ActivityState createActivityState(Exchange exchange, ProcessInstance process) {
-        return new ActivityState();
-    }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessorSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessorSupport.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessorSupport.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/JpaBamProcessorSupport.java Thu May 17 06:28:23 2007
@@ -17,9 +17,9 @@
 package org.apache.camel.bam;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.camel.Expression;
-import org.apache.camel.bam.ActivityRules;
+import org.apache.camel.Processor;
+import org.apache.camel.bam.model.ProcessDefinition;
 import org.apache.camel.util.IntrospectionSupport;
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
@@ -42,7 +42,7 @@
     }
 
     public JpaBamProcessorSupport(TransactionTemplate transactionTemplate, JpaTemplate template, Expression<Exchange> correlationKeyExpression, ActivityRules activityRules) {
-        super(transactionTemplate,  correlationKeyExpression);
+        super(transactionTemplate, correlationKeyExpression);
         this.activityRules = activityRules;
         this.template = template;
     }
@@ -54,16 +54,15 @@
         return findByKeyQuery;
     }
 
-
     public void setFindByKeyQuery(String findByKeyQuery) {
         this.findByKeyQuery = findByKeyQuery;
     }
 
-    public ActivityRules getActivity() {
+    public ActivityRules getActivityRules() {
         return activityRules;
     }
 
-    public void setActivity(ActivityRules activityRules) {
+    public void setActivityRules(ActivityRules activityRules) {
         this.activityRules = activityRules;
     }
 
@@ -94,6 +93,8 @@
         if (entity == null) {
             entity = createEntity(exchange, key);
             setKeyProperty(entity, key);
+            ProcessDefinition definition = ProcessDefinition.getRefreshedProcessDefinition(template, getActivityRules().getProcessRules().getProcessDefinition());
+            setProcessDefinitionProperty(entity, definition);
             template.persist(entity);
         }
         return entity;
@@ -104,6 +105,10 @@
      */
     protected void setKeyProperty(T entity, Object key) {
         IntrospectionSupport.setProperty(entity, getKeyPropertyName(), key);
+    }
+
+    protected void setProcessDefinitionProperty(T entity, ProcessDefinition processDefinition) {
+        IntrospectionSupport.setProperty(entity, "processDefinition", processDefinition);
     }
 
     /**

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java Thu May 17 06:28:23 2007
@@ -20,11 +20,15 @@
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
 import org.apache.camel.bam.model.ProcessInstance;
+import org.apache.camel.bam.model.ActivityDefinition;
+import org.apache.camel.bam.model.ProcessDefinition;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.processor.LifecycleProcessor;
 import static org.apache.camel.util.ObjectHelper.notNull;
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.TransactionStatus;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -42,6 +46,7 @@
     private List<ActivityBuilder> activityBuilders = new ArrayList<ActivityBuilder>();
     private Class entityType = ProcessInstance.class;
     private ProcessRules processRules = new ProcessRules();
+    private ProcessDefinition processDefinition;
 
     protected ProcessBuilder(JpaTemplate jpaTemplate, TransactionTemplate transactionTemplate) {
         this(jpaTemplate, transactionTemplate, createProcessName());
@@ -77,6 +82,11 @@
 
     public Processor createActivityProcessor(ActivityBuilder activityBuilder) {
         notNull(jpaTemplate, "jpaTemplate");
+        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
+            protected void doInTransactionWithoutResult(TransactionStatus status) {
+                processRules.setProcessDefinition(getProcessDefinition());
+            }
+        });
         return new JpaBamProcessor(getTransactionTemplate(), getJpaTemplate(), activityBuilder.getCorrelationExpression(), activityBuilder.getActivityRules(), getEntityType());
     }
 
@@ -110,6 +120,18 @@
         return processName;
     }
 
+
+    public ProcessDefinition getProcessDefinition() {
+        if (processDefinition == null) {
+            processDefinition = findOrCreateProcessDefinition();
+        }
+        return processDefinition;
+    }
+
+    public void setProcessDefinition(ProcessDefinition processDefinition) {
+        this.processDefinition = processDefinition;
+    }
+
     // Implementation methods
     //-------------------------------------------------------------------------
     protected void populateRoutes(List<Route> routes) throws Exception {
@@ -130,4 +152,38 @@
             routes.add(new Route(from, processor));
         }
     }
+
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    public ActivityDefinition findOrCreateActivityDefinition(String activityName) {
+        ProcessDefinition definition = getProcessDefinition();
+        List<ActivityDefinition> list = jpaTemplate.find("select x from " + ActivityDefinition.class.getName() + " x where x.processDefinition = ?1 and x.name = ?2", definition, activityName);
+        if (!list.isEmpty()) {
+            return list.get(0);
+        }
+        else {
+            ActivityDefinition answer = new ActivityDefinition();
+            answer.setName(activityName);
+            answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(jpaTemplate, definition));
+            jpaTemplate.persist(answer);
+            return answer;
+        }
+    }
+
+    protected ProcessDefinition findOrCreateProcessDefinition() {
+        List<ProcessDefinition> list = jpaTemplate.find("select x from " + ProcessDefinition.class.getName() + " x where x.name = ?1", processName);
+        if (!list.isEmpty()) {
+            return list.get(0);
+        }
+        else {
+            ProcessDefinition answer = new ProcessDefinition();
+            answer.setName(processName);
+            jpaTemplate.persist(answer);
+            return answer;
+        }
+    }
+
+
+
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessContext.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessContext.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessContext.java Thu May 17 06:28:23 2007
@@ -37,8 +37,8 @@
         this.exchange = exchange;
         this.activityRules = activityRules;
         this.activityState = activityState;
-        this.processRules = activityRules.getProcess();
-        this.processInstance = activityState.getProcess();
+        this.processRules = activityRules.getProcessRules();
+        this.processInstance = activityState.getProcessInstance();
     }
 
     public ActivityRules getActivity() {

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessRules.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessRules.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessRules.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/ProcessRules.java Thu May 17 06:28:23 2007
@@ -16,26 +16,59 @@
  */
 package org.apache.camel.bam;
 
-import org.apache.camel.bam.ActivityRules;
+import org.apache.camel.Exchange;
 import org.apache.camel.bam.model.ActivityState;
+import org.apache.camel.bam.model.ProcessInstance;
+import org.apache.camel.bam.model.ProcessDefinition;
+import org.apache.camel.impl.ServiceSupport;
+import org.apache.camel.util.ServiceHelper;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @version $Revision: $
  */
-public class ProcessRules {
+public class ProcessRules extends ServiceSupport {
+    private ProcessDefinition processDefinition;
     private List<ActivityRules> activities = new ArrayList<ActivityRules>();
 
+    public void processExpired(ActivityState activityState) throws Exception {
+        for (ActivityRules activityRules : activities) {
+            activityRules.processExpired(activityState);
+        }
+    }
+
+    public void processExchange(Exchange exchange, ProcessInstance process) {
+        for (ActivityRules activityRules : activities) {
+            activityRules.processExchange(exchange, process);
+        }
+    }
 
+    // Properties
+    //-------------------------------------------------------------------------
     public List<ActivityRules> getActivities() {
         return activities;
     }
 
-    public void processExpired(ActivityState activityState) throws Exception {
-        for (ActivityRules activityRules : activities) {
-            activityRules.processExpired(activityState);
-        }
+    public ProcessDefinition getProcessDefinition() {
+        return processDefinition;
+    }
+
+    public void setProcessDefinition(ProcessDefinition processDefinition) {
+        this.processDefinition = processDefinition;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected void doStart() throws Exception {
+        ServiceHelper.startServices(activities);
+    }
+
+    protected void doStop() throws Exception {
+        ServiceHelper.stopServices(activities);
     }
 }
+
+
+

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TemporalRule.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TemporalRule.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TemporalRule.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TemporalRule.java Thu May 17 06:28:23 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.bam;
 
+import static org.apache.camel.util.ServiceHelper.startServices;
+import static org.apache.camel.util.ServiceHelper.stopServices;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.bam.model.ActivityState;
@@ -23,7 +25,9 @@
 import org.apache.camel.builder.FromBuilder;
 import org.apache.camel.builder.ProcessorFactory;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.util.Time;
+import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -34,7 +38,7 @@
  *
  * @version $Revision: $
  */
-public class TemporalRule {
+public class TemporalRule extends ServiceSupport {
     private static final transient Log log = LogFactory.getLog(TemporalRule.class);
     private TimeExpression first;
     private TimeExpression second;
@@ -43,9 +47,9 @@
     private Processor overdueAction;
     private ProcessorFactory overdueProcessorFactory;
 
-    public TemporalRule(TimeExpression left, TimeExpression right) {
-        this.first = left;
-        this.second = right;
+    public TemporalRule(TimeExpression first, TimeExpression second) {
+        this.first = first;
+        this.second = second;
     }
 
     public TemporalRule expectWithin(Time builder) {
@@ -77,9 +81,14 @@
         return second;
     }
 
-    public void evaluate(ProcessContext context, ActivityState activityState) {
-        ProcessInstance instance = context.getProcessInstance();
+    public Processor getOverdueAction() throws Exception {
+        if (overdueAction == null && overdueProcessorFactory != null) {
+            overdueAction = overdueProcessorFactory.createProcessor();
+        }
+        return overdueAction;
+    }
 
+    public void processExchange(Exchange exchange, ProcessInstance instance) {
         Date firstTime = first.evaluateState(instance);
         if (firstTime == null) {
             // ignore as first event has not accurred yet
@@ -88,9 +97,9 @@
 
         // TODO now we might need to set the second activity state
         // to 'grey' to indicate it now could happen?
-        // if the second activity state is not created yet we might wanna create it
 
-        ActivityState secondState = second.getActivityState(instance);
+        // lets force the lazy creation of the second state
+        ActivityState secondState = second.getOrCreateActivityState(instance);
         if (expectedMillis > 0L) {
             Date expected = secondState.getTimeExpected();
             if (expected == null) {
@@ -120,19 +129,32 @@
         }
     }
 
+    /*
+    public void evaluate(ProcessContext context, ActivityState activityState) {
+        ProcessInstance instance = context.getProcessInstance();
+
+    }
+    */
+
     public void processExpired(ActivityState activityState) throws Exception {
-        if (overdueAction == null && overdueProcessorFactory != null) {
-            overdueAction = overdueProcessorFactory.createProcessor();
-        }
-        if (overdueAction != null) {
+        Processor processor = getOverdueAction();
+        if (processor != null) {
             Date now = new Date();
-            ProcessInstance instance = activityState.getProcess();
+/*
+            TODO this doesn't work and returns null for some strange reason
+            ProcessInstance instance = activityState.getProcessInstance();
             ActivityState secondState = second.getActivityState(instance);
+            if (secondState == null) {
+                log.error("Could not find the second state! Process is: " + instance + " with first state: " + first.getActivityState(instance) + " and the state I was called with was: " + activityState);
+            }
+*/
+
+            ActivityState secondState = activityState;
             Date overdue = secondState.getTimeOverdue();
             if (now.compareTo(overdue) >= 0) {
                 Exchange exchange = createExchange();
                 exchange.getIn().setBody(activityState);
-                overdueAction.process(exchange);
+                processor.process(exchange);
             }
             else {
                 log.warn("Process has not actually expired; the time is: " + now + " but the overdue time is: " + overdue);
@@ -167,4 +189,12 @@
         }
     }
     */
+
+    protected void doStart() throws Exception {
+        startServices(getOverdueAction());
+    }
+
+    protected void doStop() throws Exception {
+        stopServices(getOverdueAction());
+    }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TimeExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TimeExpression.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TimeExpression.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/TimeExpression.java Thu May 17 06:28:23 2007
@@ -44,7 +44,7 @@
      * Creates a new temporal rule on this expression and the other expression
      */
     public TemporalRule after(TimeExpression expression) {
-        TemporalRule rule = new TemporalRule(this, expression);
+        TemporalRule rule = new TemporalRule(expression, this);
         rule.getSecond().getActivityRules().addRule(rule);
         return rule;
     }
@@ -76,5 +76,9 @@
 
     public ActivityState getActivityState(ProcessInstance instance) {
         return instance.getActivityState(activityRules);
+    }
+
+    public ActivityState getOrCreateActivityState(ProcessInstance instance) {
+        return instance.getOrCreateActivityState(activityRules);
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityDefinition.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityDefinition.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityDefinition.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityDefinition.java Thu May 17 06:28:23 2007
@@ -17,7 +17,12 @@
  */
 package org.apache.camel.bam.model;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
 
 /**
  * @version $Revision: 1.1 $
@@ -25,12 +30,36 @@
 @Entity
 public class ActivityDefinition extends EntitySupport {
     private String name;
+    private ProcessDefinition processDefinition;
 
+    // This crap is required to work around a bug in hibernate
+    @Override
+    @Id
+    @GeneratedValue
+    public Long getId() {
+        return super.getId();
+    }
+
+
+    @Override
+    public String toString() {
+        return "Activity[" + getId() + " name: " + getName() + "]";
+    }
+    
     public String getName() {
         return name;
     }
 
     public void setName(String name) {
         this.name = name;
+    }
+
+    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
+    public ProcessDefinition getProcessDefinition() {
+        return processDefinition;
+    }
+
+    public void setProcessDefinition(ProcessDefinition processDefinition) {
+        this.processDefinition = processDefinition;
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java Thu May 17 06:28:23 2007
@@ -25,6 +25,8 @@
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.ManyToOne;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
 import java.util.Date;
 
 /**
@@ -34,12 +36,25 @@
  */
 @Entity
 public class ActivityState extends TemporalEntity implements TimerEventHandler {
-    private ProcessInstance process;
-    private Integer receivedMessageCount;
+    private ProcessInstance processInstance;
+    private Integer receivedMessageCount = 0;
     private ActivityDefinition activityDefinition;
     private Date timeExpected;
     private Date timeOverdue;
-    private Integer escalationLevel;
+    private Integer escalationLevel = 0;
+
+    // This crap is required to work around a bug in hibernate
+    @Override
+    @Id
+    @GeneratedValue
+    public Long getId() {
+        return super.getId();
+    }
+
+    @Override
+    public String toString() {
+        return "ActivityState[" + getId() + " " + getActivityDefinition() + "]";
+    }
 
     public synchronized void processExchange(ActivityRules activityRules, ProcessContext context) throws Exception {
         int messageCount = 0;
@@ -59,16 +74,13 @@
         else if (messageCount > expectedMessages) {
             onExcessMessage(context);
         }
-
-        // now lets fire any assertions on the activity
-        activityRules.processExchange(this, context);
     }
 
     /**
      * Returns true if this state is for the given activity
      */
     public boolean isActivity(ActivityRules activityRules) {
-        return ObjectHelper.equals(getActivityDefinition(), activityRules.getActivity());
+        return ObjectHelper.equals(getActivityDefinition(), activityRules.getActivityDefinition());
     }
 
     /**
@@ -81,13 +93,13 @@
     // Properties
     //-----------------------------------------------------------------------
     @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
-    public ProcessInstance getProcess() {
-        return process;
+    public ProcessInstance getProcessInstance() {
+        return processInstance;
     }
 
-    public void setProcess(ProcessInstance process) {
-        this.process = process;
-        process.getActivityStates().add(this);
+    public void setProcessInstance(ProcessInstance processInstance) {
+        this.processInstance = processInstance;
+        processInstance.getActivityStates().add(this);
     }
 
     @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java Thu May 17 06:28:23 2007
@@ -17,20 +17,64 @@
  */
 package org.apache.camel.bam.model;
 
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.orm.jpa.JpaTemplate;
+
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.util.List;
 
 /**
  * @version $Revision: 1.1 $
  */
 @Entity
 public class ProcessDefinition extends EntitySupport {
+    private static final transient Log log = LogFactory.getLog(ProcessDefinition.class);
     private String name;
 
+    // This crap is required to work around a bug in hibernate
+    @Override
+    @Id
+    @GeneratedValue
+    public Long getId() {
+        return super.getId();
+    }
+
     public String getName() {
         return name;
     }
 
     public void setName(String name) {
         this.name = name;
+    }
+
+    public static ProcessDefinition getRefreshedProcessDefinition(JpaTemplate template, ProcessDefinition definition) {
+        // TODO refresh doesn't tend to work - maybe its a spring thing?
+        //template.refresh(definition);
+
+        ObjectHelper.notNull(definition, "definition");
+        Long id = definition.getId();
+        if (id == null) {
+            log.warn("No primary key is available!");
+            return findOrCreateProcessDefinition(template, definition.getName());
+        }
+        definition = template.find(ProcessDefinition.class, id);
+        return definition;
+    }
+
+    public static ProcessDefinition findOrCreateProcessDefinition(JpaTemplate template, String processName) {
+        List<ProcessDefinition> list = template.find("select x from " + ProcessDefinition.class.getName() + " x where x.name = ?1", processName);
+        if (!list.isEmpty()) {
+            return list.get(0);
+        }
+        else {
+            ProcessDefinition answer = new ProcessDefinition();
+            answer.setName(processName);
+            template.persist(answer);
+            return answer;
+        }
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java Thu May 17 06:28:23 2007
@@ -25,6 +25,8 @@
 import javax.persistence.FetchType;
 import javax.persistence.OneToMany;
 import javax.persistence.ManyToOne;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
 import java.util.HashSet;
 import java.util.Collection;
 import java.util.Date;
@@ -50,24 +52,14 @@
         return getClass().getName() + "[id: " + getId() + ", key: " + getCorrelationKey() + "]";
     }
 
-    /**
-     * Returns the activity state for the given activity
-     *
-     * @param activityRules the activity to find the state for
-     * @return the activity state or null if no state could be found for the
-     *         given activity
-     */
-    public ActivityState getActivityState(ActivityRules activityRules) {
-        log.info("About to iterate through the states: " + getActivityStates());
-
-        for (ActivityState activityState : getActivityStates()) {
-            if (activityState.isActivity(activityRules)) {
-                return activityState;
-            }
-        }
-        return null;
+    // This crap is required to work around a bug in hibernate
+    @Override
+    @Id
+    @GeneratedValue
+    public Long getId() {
+        return super.getId();
     }
-
+    
     @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
     public ProcessDefinition getProcessDefinition() {
         return processDefinition;
@@ -77,7 +69,7 @@
         this.processDefinition = processDefinition;
     }
 
-    @OneToMany(mappedBy = "process", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
+    @OneToMany(mappedBy = "processInstance", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
     public Collection<ActivityState> getActivityStates() {
         return activityStates;
     }
@@ -92,5 +84,47 @@
 
     public void setCorrelationKey(String correlationKey) {
         this.correlationKey = correlationKey;
+    }
+
+
+    // Helper methods
+    //-------------------------------------------------------------------------
+    
+    /**
+     * Returns the activity state for the given activity
+     *
+     * @param activityRules the activity to find the state for
+     * @return the activity state or null if no state could be found for the
+     *         given activity
+     */
+    public ActivityState getActivityState(ActivityRules activityRules) {
+        log.info("About to iterate through the states: " + getActivityStates());
+
+        for (ActivityState activityState : getActivityStates()) {
+            if (activityState.isActivity(activityRules)) {
+                return activityState;
+            }
+        }
+        return null;
+    }
+
+    public ActivityState getOrCreateActivityState(ActivityRules activityRules) {
+        ActivityState state = getActivityState(activityRules);
+        log.info("Found activity: "+ state);
+
+        if (state == null) {
+            state = createActivityState();
+            state.setProcessInstance(this);
+            state.setActivityDefinition(activityRules.getActivityDefinition());
+
+            // TODO not required: getTemplate().persist(state);
+        }
+
+        return state;
+    }
+
+
+    protected ActivityState createActivityState() {
+        return new ActivityState();
     }
 }

Modified: activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/TemporalEntity.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/TemporalEntity.java?view=diff&rev=538915&r1=538914&r2=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/TemporalEntity.java (original)
+++ activemq/camel/trunk/camel-bam/src/main/java/org/apache/camel/bam/model/TemporalEntity.java Thu May 17 06:28:23 2007
@@ -17,6 +17,7 @@
 package org.apache.camel.bam.model;
 
 import javax.persistence.Transient;
+import javax.persistence.Entity;
 import java.util.Date;
 
 /**

Added: activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml?view=auto&rev=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml (added)
+++ activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml Thu May 17 06:28:23 2007
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             version="1.0">
+
+  <persistence-unit name="bam" transaction-type="RESOURCE_LOCAL">
+    <class>org.apache.camel.bam.model.ActivityDefinition</class>
+    <class>org.apache.camel.bam.model.ActivityState</class>
+    <class>org.apache.camel.bam.model.ProcessDefinition</class>
+    <class>org.apache.camel.bam.model.ProcessInstance</class>
+
+    <properties>
+      <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+      <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
+      <property name="hibernate.connection.username" value="sa"/>
+      <property name="hibernate.connection.password" value=""/>
+      <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:camel_bam"/>
+      <property name="hibernate.hbm2ddl.auto" value="create"/>
+    </properties>
+
+  </persistence-unit>
+</persistence>

Propchange: activemq/camel/trunk/camel-bam/src/test/profiles/hibernate/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml?view=auto&rev=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml (added)
+++ activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml Thu May 17 06:28:23 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             version="1.0">
+
+  <persistence-unit name="bam" transaction-type="RESOURCE_LOCAL">
+    <class>org.apache.camel.bam.model.ActivityDefinition</class>
+    <class>org.apache.camel.bam.model.ActivityState</class>
+    <class>org.apache.camel.bam.model.ProcessDefinition</class>
+    <class>org.apache.camel.bam.model.ProcessInstance</class>
+
+    <properties>
+      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
+      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
+      <property name="hibernate.connection.url" value="jdbc:mysql://localhost/camel_bam?relaxAutoCommit=true"/>
+      <property name="hibernate.hbm2ddl.auto" value="create"/>
+    </properties>
+
+  </persistence-unit>
+</persistence>

Propchange: activemq/camel/trunk/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml?view=auto&rev=538915
==============================================================================
--- activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml (added)
+++ activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml Thu May 17 06:28:23 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             version="1.0">
+
+  <persistence-unit name="bam" transaction-type="RESOURCE_LOCAL">
+    <class>org.apache.camel.bam.model.ActivityDefinition</class>
+    <class>org.apache.camel.bam.model.ActivityState</class>
+    <class>org.apache.camel.bam.model.ProcessDefinition</class>
+    <class>org.apache.camel.bam.model.ProcessInstance</class>
+
+    <properties>
+      <property name="openjpa.ConnectionURL" value="jdbc:derby:target/bamTest;create=true"/>
+      <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+      <property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO"/>
+    </properties>
+  </persistence-unit>
+</persistence>

Propchange: activemq/camel/trunk/camel-bam/src/test/profiles/openjpa/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message