[jbpm-commits] JBoss JBPM SVN: r2410 - in jbpm4/branches/tdiesler: modules/api/src/main/java/org/jbpm/api/client and 11 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Sep 27 16:52:42 EDT 2008


Author: thomas.diesler at jboss.com
Date: 2008-09-27 16:52:42 -0400 (Sat, 27 Sep 2008)
New Revision: 2410

Added:
   jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java
   jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/
   jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/PersistenceServiceTest.java
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceService.java
Removed:
   jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/Flow.java
Modified:
   jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/client/ProcessEngine.java
   jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/SequenceFlow.java
   jbpm4/branches/tdiesler/modules/cts/pom.xml
   jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/processbuilder/ProcessBuilderTest.java
   jbpm4/branches/tdiesler/modules/impl/pom.xml
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EndEventImpl.java
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EventImpl.java
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/SequenceFlowImpl.java
   jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/StartEventImpl.java
   jbpm4/branches/tdiesler/modules/impl/src/main/resources/jbpm-cfg-beans.xml
   jbpm4/branches/tdiesler/pom.xml
Log:
wip

Modified: jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/client/ProcessEngine.java
===================================================================
--- jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/client/ProcessEngine.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/client/ProcessEngine.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -89,7 +89,9 @@
   }
 
   /**
-   * Get the registered default ProcessEngine <p/> If there is no ProcessEngine registered, a call to this method will
+   * Get the registered default ProcessEngine 
+   * <p/> 
+   * If there is no ProcessEngine registered, a call to this method will
    * register the default engine automatically.
    * 
    * @return The configured instance of a process engine
@@ -135,13 +137,6 @@
     this.name = name;
   }
 
-  /**
-   * Do a shutdown of this
-   */
-  public void shutdownProcessEngine()
-  {
-  }
-
   private static ProcessEngine loadDefaultEngine()
   {
     ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();

Deleted: jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/Flow.java
===================================================================
--- jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/Flow.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/Flow.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.api.model;
-
-//$Id$
-
-/**
- * Sequence Flow and Message Flow, to a certain extent, represent orthogonal aspects of the business processes depicted in a model,
- * although they both affect the performance of activities within a Process.
- * 
- * @author thomas.diesler at jboss.com
- * @since 08-Jul-2008
- */
-public interface Flow
-{
-  /**
-   * Name is an optional attribute that is text description of the Connecting Object.
-   */
-  String getName();
-
-  /**
-   * SourceRef is an attribute that identifies which Graphical Element the Connecting
-   * Object is connected from. Note: there are restrictions as to what objects Sequence
-   * Flow and Message Flow can connect. 
-   */
-  Node getSourceRef();
-
-  /**
-   * TargetRef is an attribute that identifies which Graphical Element the Connecting
-   * Object is connected to. Note: there are restrictions as to what objects Sequence
-   * Flow and Message Flow can connect.
-   */
-  Node getTargetRef();
-
-  /**
-   * Get the required target name
-   */
-  String getTargetName();
-}
\ No newline at end of file

Modified: jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/SequenceFlow.java
===================================================================
--- jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/SequenceFlow.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/model/SequenceFlow.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -21,7 +21,9 @@
  */
 package org.jbpm.api.model;
 
+import java.io.Serializable;
 
+
 //$Id$
 
 /**
@@ -34,7 +36,7 @@
  * @author thomas.diesler at jboss.com
  * @since 08-Jul-2008
  */
-public interface SequenceFlow extends Flow
+public interface SequenceFlow extends Serializable
 {
   /**
    * The ConditionType
@@ -45,6 +47,25 @@
   }
 
   /**
+   * SourceRef is an attribute that identifies which Graphical Element the Connecting
+   * Object is connected from. Note: there are restrictions as to what objects Sequence
+   * Flow and Message Flow can connect. 
+   */
+  Node getSourceRef();
+
+  /**
+   * TargetRef is an attribute that identifies which Graphical Element the Connecting
+   * Object is connected to. Note: there are restrictions as to what objects Sequence
+   * Flow and Message Flow can connect.
+   */
+  Node getTargetRef();
+
+  /**
+   * Get the required target name
+   */
+  String getTargetName();
+  
+  /**
    * By default, the ConditionType of a Sequence Flow is None. This means that there is no evaluation at runtime to
    * determine whether or not the Sequence Flow will be used. Once a Token is ready to traverse the Sequence Flow (i.e.,
    * the Source is an activity that has completed), then the Token will do so. The normal, uncontrolled use of Sequence
@@ -67,6 +88,6 @@
    * Token will be generated and will traverse the Sequence--Subject to any constraints imposed by a Source that is a
    * Gateway.
    */
-  Expression getConditionExpression();
+  //Expression getConditionExpression();
 
 }
\ No newline at end of file

Added: jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java
===================================================================
--- jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java	                        (rev 0)
+++ jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.api.service;
+
+// $Id$
+
+import javax.management.ObjectName;
+
+import org.jbpm.api.model.Process;
+
+/**
+ * The persistence service for a process.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 17-Sep-2008
+ */
+public interface PersistenceService extends Service
+{
+  ObjectName saveProcess(Process proc);
+
+  Process loadProcess(ObjectName procID);
+
+  void deleteProcess(Process proc);
+
+}
\ No newline at end of file


Property changes on: jbpm4/branches/tdiesler/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/branches/tdiesler/modules/cts/pom.xml
===================================================================
--- jbpm4/branches/tdiesler/modules/cts/pom.xml	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/cts/pom.xml	2008-09-27 20:52:42 UTC (rev 2410)
@@ -25,6 +25,11 @@
     <relativePath>../../pom.xml</relativePath>
   </parent>
 
+  <!-- Properties -->
+  <properties>
+    <mysql.connector.version>5.1.6</mysql.connector.version>
+  </properties>
+  
   <!-- Dependencies -->
   <dependencies>
     <dependency>
@@ -46,6 +51,17 @@
     </dependency>
   </dependencies>
   
+  <!-- DependencyManagement -->
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>mysql</groupId>
+        <artifactId>mysql-connector-java</artifactId>
+        <version>${mysql.connector.version}</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  
   <!-- Plugins -->
   <build>
     <plugins>
@@ -75,6 +91,29 @@
       </dependencies>
     </profile>
     
+    <!-- 
+      Name:  no-database
+      Descr: Setup the default database   
+    -->
+    <profile>
+      <id>no-database</id>
+      <activation>
+        <property>
+          <name>!database</name>
+        </property>
+      </activation>
+      <properties>
+        <database>mysql</database>
+      </properties>
+      <dependencies>
+        <dependency>
+          <groupId>mysql</groupId>
+          <artifactId>mysql-connector-java</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+    
   </profiles>
   
 </project>
\ No newline at end of file

Added: jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/PersistenceServiceTest.java
===================================================================
--- jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/PersistenceServiceTest.java	                        (rev 0)
+++ jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/PersistenceServiceTest.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.cts.persistence;
+
+// $Id$
+
+import javax.management.ObjectName;
+
+import org.jbpm.api.ProcessNotFoundException;
+import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.model.Process;
+import org.jbpm.api.model.builder.ProcessBuilder;
+import org.jbpm.api.service.PersistenceService;
+import org.jbpm.api.test.CTSTestCase;
+
+/**
+ * Test the ExecutionManager
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class PersistenceServiceTest extends CTSTestCase
+{
+  /**
+   * Test save, load, delete of a trivial process
+   */
+  public void testSaveLoadDelete() throws Exception
+  {
+    ProcessEngine engine = ProcessEngine.getProcessEngine();
+    PersistenceService service = engine.getService(PersistenceService.class);
+
+    // Save the process
+    Process proc = getProcess();
+    service.saveProcess(proc);
+
+    // Load the process
+    ObjectName procID = proc.getID();
+    Process procLoad = service.loadProcess(procID);
+    assertEquals("Loaded process name equals", proc.getName(), procLoad.getName());
+
+    // Delete the process
+    service.deleteProcess(proc);
+    try
+    {
+      service.loadProcess(procID);
+      fail("ProcessNotFoundException expected");
+    }
+    catch (ProcessNotFoundException ex)
+    {
+      // expected
+    }
+  }
+
+  private Process getProcess()
+  {
+    ProcessEngine engine = ProcessEngine.getProcessEngine();
+    ProcessBuilder builder = engine.getService(ProcessBuilder.class);
+    builder.addProcess("Proc").addStartEvent("Start").addSequenceFlow("Task");
+    builder.addTask("Task").addSequenceFlow("End").addEndEvent("End");
+    return builder.getProcess();
+  }
+}


Property changes on: jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/persistence/PersistenceServiceTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/processbuilder/ProcessBuilderTest.java
===================================================================
--- jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/processbuilder/ProcessBuilderTest.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/cts/src/test/java/org/jbpm/test/cts/processbuilder/ProcessBuilderTest.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -60,6 +60,10 @@
     assertNotNull("Start not null", start);
     assertNotNull("Task not null", task);
     assertNotNull("End not null", end);
+    
+    assertSame(proc, start.getProcess());
+    assertSame(proc, task.getProcess());
+    assertSame(proc, end.getProcess());
 
     assertSame(start, proc.getNode(StartEvent.class, "Start"));
     assertSame(task, proc.getNode(Task.class, "Task"));

Modified: jbpm4/branches/tdiesler/modules/impl/pom.xml
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/pom.xml	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/pom.xml	2008-09-27 20:52:42 UTC (rev 2410)
@@ -33,8 +33,6 @@
     <hibernate.version>3.2.6.ga</hibernate.version>
     <hibernate.annotations.version>3.3.1.GA</hibernate.annotations.version>
     <hibernate.validator.version>3.0.0.ga</hibernate.validator.version>
-    <hsqldb.version>1.8.0.7</hsqldb.version>
-    <mysql.connector.version>5.1.6</mysql.connector.version>
   </properties>
 
   <!-- DependencyManagement -->
@@ -55,13 +53,6 @@
         <artifactId>hibernate-validator</artifactId>
         <version>${hibernate.validator.version}</version>
       </dependency>
-      
-      <!-- Database Driver Versions  -->
-      <dependency>
-        <groupId>mysql</groupId>
-        <artifactId>mysql-connector-java</artifactId>
-        <version>${mysql.connector.version}</version>
-      </dependency>
     </dependencies>
   </dependencyManagement>
   

Modified: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EndEventImpl.java
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EndEventImpl.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EndEventImpl.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -25,6 +25,8 @@
 
 import javax.management.ObjectName;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.Table;
 import javax.persistence.Transient;
 
@@ -68,16 +70,24 @@
   {
   }
 
+  @Enumerated(EnumType.STRING)
   public EventType getEventType()
   {
     return EventType.End;
   }
 
+  @Enumerated(EnumType.STRING)
   public ResultType getResultType()
   {
     return resultType;
   }
   
+  // Persistence method
+  protected void setResultType(ResultType resultType)
+  {
+    this.resultType = resultType;
+  }
+
   @Override
   @Transient
   public ObjectName getID()

Modified: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EventImpl.java
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EventImpl.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/EventImpl.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -68,4 +68,11 @@
   {
     return EventType.Intermediate;
   }
+
+  // Persistence method
+  protected void setEventType(EventType eventType)
+  {
+    // nothing to do
+  }
+
 }
\ No newline at end of file

Modified: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/SequenceFlowImpl.java
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/SequenceFlowImpl.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/SequenceFlowImpl.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -23,6 +23,12 @@
 
 //$Id$
 
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
 import javax.persistence.Transient;
 
 import org.jbpm.api.model.Expression;
@@ -36,17 +42,25 @@
  * @author thomas.diesler at jboss.com
  * @since 08-Jul-2008
  */
+ at Entity
+ at Table(name = "JBPM_SEQUENCE_FLOW")
 public class SequenceFlowImpl implements SequenceFlow
 {
   // provide serial version UID
   private static final long serialVersionUID = 1L;
 
+  @Id
+  @GeneratedValue
+  @SuppressWarnings("unused")
+  private Integer id;
+  
   private ConditionType conditionType = ConditionType.None;
-  private Expression conditionExpression;
-  private String name;
+  //private Expression conditionExpression;
   private String targetName;
-  private Node source;
-  private Node target;
+  @Transient
+  private Node sourceRef;
+  @Transient
+  private Node targetRef;
 
   public SequenceFlowImpl(String targetName)
   {
@@ -57,7 +71,7 @@
   {
     this.targetName = targetName;
     this.conditionType = type;
-    this.conditionExpression = expr;
+    //this.conditionExpression = expr;
   }
 
   // Persistence ctor
@@ -65,36 +79,26 @@
   {
   }
 
-  public String getName()
-  {
-    return name;
-  }
-
-  public void setName(String name)
-  {
-    this.name = name;
-  }
-
   @Transient
   public Node getSourceRef()
   {
-    return source;
+    return sourceRef;
   }
 
   protected void setSourceRef(Node source)
   {
-    this.source = source;
+    this.sourceRef = source;
   }
 
   @Transient
   public Node getTargetRef()
   {
-    return target;
+    return targetRef;
   }
   
   protected void setTargetRef(Node target)
   {
-    this.target = target;
+    this.targetRef = target;
   }
 
   public String getTargetName()
@@ -108,6 +112,7 @@
     this.targetName = targetName;
   }
   
+  @Enumerated(EnumType.STRING)
   public ConditionType getConditionType()
   {
     return conditionType;
@@ -119,10 +124,11 @@
     this.conditionType = conditionType;
   }
 
-  public Expression getConditionExpression()
-  {
-    return conditionExpression;
-  }
+  @Transient
+//  public Expression getConditionExpression()
+//  {
+//    return conditionExpression;
+//  }
 
   public String toString()
   {

Modified: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/StartEventImpl.java
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/StartEventImpl.java	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/model/StartEventImpl.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -80,6 +80,12 @@
     return triggerType;
   }
   
+  // Persistence method
+  protected void setTriggerType(TriggerType triggerType)
+  {
+    this.triggerType = triggerType;
+  }
+
   @Override
   @Transient
   public ObjectName getID()

Added: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceService.java
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceService.java	                        (rev 0)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceService.java	2008-09-27 20:52:42 UTC (rev 2410)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.ri.service;
+
+// $Id$
+
+import javax.management.ObjectName;
+
+import org.hibernate.Hibernate;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.classic.Session;
+import org.jbpm.api.ProcessNotFoundException;
+import org.jbpm.api.model.Process;
+import org.jbpm.api.service.PersistenceService;
+import org.jbpm.ri.model.AbstractElementImpl;
+import org.jbpm.ri.model.EndEventImpl;
+import org.jbpm.ri.model.NodeImpl;
+import org.jbpm.ri.model.ProcessImpl;
+import org.jbpm.ri.model.SequenceFlowImpl;
+import org.jbpm.ri.model.StartEventImpl;
+import org.jbpm.ri.model.TaskImpl;
+
+/**
+ * A Hibernate based persistence service for a process.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 17-Sep-2008
+ */
+public class HibernatePersistenceService implements PersistenceService
+{
+  private String hibernateConfig;
+  private SessionFactory sessionFactory;
+
+  public void setHibernateConfig(String hibernateConfig)
+  {
+    this.hibernateConfig = hibernateConfig;
+  }
+
+  public ObjectName saveProcess(Process proc)
+  {
+    Session session = getSessionFactory().openSession();
+    Transaction tx = session.beginTransaction();
+    try
+    {
+      session.saveOrUpdate(proc);
+      tx.commit();
+    }
+    finally
+    {
+      session.close();
+    }
+    return proc.getID();
+  }
+
+  public Process loadProcess(ObjectName procID)
+  {
+    Process proc = null;
+    Session session = getSessionFactory().openSession();
+    try
+    {
+      String key = procID.getKeyProperty("id");
+      proc = (Process)session.load(ProcessImpl.class, key);
+      Hibernate.initialize(proc);
+    }
+    catch (ObjectNotFoundException ex)
+    {
+      throw new ProcessNotFoundException("Cannot find process: " + procID);
+    }
+    finally
+    {
+      session.close();
+    }
+    return proc;
+  }
+
+  public void deleteProcess(Process proc)
+  {
+    Session session = getSessionFactory().openSession();
+    Transaction tx = session.beginTransaction();
+    try
+    {
+      session.delete(proc);
+      tx.commit();
+    }
+    finally
+    {
+      session.close();
+    }
+  }
+
+  private SessionFactory getSessionFactory()
+  {
+    // If this property is not explicitly set in the beans config
+    // fall back to the -Ddatabase property that also activates 
+    // the corresponding mvn profiles
+    if (hibernateConfig == null)
+    {
+      String database = System.getProperty("database", "mysql");
+      hibernateConfig = "hibernate.cfg." + database + ".xml";
+    }
+
+    if (sessionFactory == null)
+    {
+      AnnotationConfiguration anConfig = new AnnotationConfiguration();
+      anConfig.addAnnotatedClass(AbstractElementImpl.class);
+      anConfig.addAnnotatedClass(EndEventImpl.class);
+      anConfig.addAnnotatedClass(NodeImpl.class);
+      anConfig.addAnnotatedClass(TaskImpl.class);
+      anConfig.addAnnotatedClass(ProcessImpl.class);
+      anConfig.addAnnotatedClass(SequenceFlowImpl.class);
+      anConfig.addAnnotatedClass(StartEventImpl.class);
+      sessionFactory = anConfig.configure(hibernateConfig).buildSessionFactory();
+    }
+    return sessionFactory;
+  }
+}


Property changes on: jbpm4/branches/tdiesler/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/branches/tdiesler/modules/impl/src/main/resources/jbpm-cfg-beans.xml
===================================================================
--- jbpm4/branches/tdiesler/modules/impl/src/main/resources/jbpm-cfg-beans.xml	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/modules/impl/src/main/resources/jbpm-cfg-beans.xml	2008-09-27 20:52:42 UTC (rev 2410)
@@ -9,11 +9,13 @@
       <property name="services">
         <set elementClass="org.jbpm.api.service.Service">
           <inject bean="jBPMProcessBuilder" />
+          <inject bean="jBPMPersistenceService" />
         </set>
       </property>
     </bean>
 
     <!-- The Services -->
     <bean name="jBPMProcessBuilder" class="org.jbpm.ri.model.builder.ProcessBuilderImpl" />
+    <bean name="jBPMPersistenceService" class="org.jbpm.ri.service.HibernatePersistenceService" />
 
   </deployment>

Modified: jbpm4/branches/tdiesler/pom.xml
===================================================================
--- jbpm4/branches/tdiesler/pom.xml	2008-09-27 18:41:41 UTC (rev 2409)
+++ jbpm4/branches/tdiesler/pom.xml	2008-09-27 20:52:42 UTC (rev 2410)
@@ -40,19 +40,9 @@
   
   <!-- Properties -->
   <properties>
-    <cactus.version>13-1.7.1</cactus.version>
-    <clover.version>2.3.1</clover.version>
     <hibernate.version>3.2.5.ga</hibernate.version>
-    <hsqldb.version>1.8.0.7</hsqldb.version>
-    <jboss.j2ee.version>4.2.1.GA</jboss.j2ee.version>
-    <jboss.seam.version>2.0.1.GA</jboss.seam.version>
-    <jbpm.api.version>1.0.0-SNAPSHOT</jbpm.api.version>
-    <jsr233.version>2.0.3</jsr233.version>
-    <juel.version>2.1.0</juel.version>
     <log4j.version>1.2.14</log4j.version>
-    <servlet-api.version>2.5</servlet-api.version>
     <slf4j.version>1.5.3</slf4j.version>
-    <spring.version>2.5.4</spring.version>
   </properties>
   
   <!-- DependencyManagement -->
@@ -66,71 +56,11 @@
 
       <!-- Please sort by groupid -->      
       <dependency>
-        <groupId>cactus</groupId>
-        <artifactId>cactus</artifactId>
-        <version>${cactus.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>com.cenqua.clover</groupId>
-        <artifactId>clover</artifactId>
-        <version>${clover.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>hsqldb</groupId>
-        <artifactId>hsqldb</artifactId>
-        <version>${hsqldb.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>javax.servlet</groupId>
-        <artifactId>servlet-api</artifactId>
-        <version>${servlet-api.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>jboss</groupId>
-        <artifactId>jboss-j2ee</artifactId>
-        <version>${jboss.j2ee.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>juel</groupId>
-        <artifactId>juel</artifactId>
-        <version>${juel.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>juel</groupId>
-        <artifactId>juel-engine</artifactId>
-        <version>${juel.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>juel</groupId>
-        <artifactId>juel-impl</artifactId>
-        <version>${juel.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-        <version>${junit.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>log4j</groupId>
-        <artifactId>log4j</artifactId>
-        <version>${log4j.version}</version>
-      </dependency>
-      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate</artifactId>
         <version>${hibernate.version}</version>
       </dependency>
       <dependency>
-        <groupId>org.jboss.seam</groupId>
-        <artifactId>jboss-seam</artifactId>
-        <version>${jboss.seam.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.livetribe</groupId>
-        <artifactId>livetribe-jsr223</artifactId>
-        <version>${jsr233.version}</version>
-      </dependency>
-      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4j.version}</version>
@@ -140,11 +70,6 @@
         <artifactId>slf4j-log4j12</artifactId>
         <version>${slf4j.version}</version>
       </dependency>
-      <dependency>
-        <groupId>org.springframework</groupId>
-        <artifactId>spring</artifactId>
-        <version>${spring.version}</version>
-      </dependency>
     </dependencies>
   </dependencyManagement>
 




More information about the jbpm-commits mailing list