[jbpm-commits] JBoss JBPM SVN: r2510 - in projects/spec/trunk/modules: api/src/main/java/org/jbpm/api/service and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 8 11:11:43 EDT 2008


Author: thomas.diesler at jboss.com
Date: 2008-10-08 11:11:43 -0400 (Wed, 08 Oct 2008)
New Revision: 2510

Added:
   projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/NodePersistenceTest.java
   projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcesDefinitionPersistenceTest.java
   projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcessPersistenceTest.java
Removed:
   projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/PersistenceServiceTest.java
   projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/PersistenceServiceImpl.java
Modified:
   projects/spec/trunk/modules/api/pom.xml
   projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java
   projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessDefinitionService.java
   projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessService.java
   projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceServiceImpl.java
   projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/InMemoryPersistenceServiceImpl.java
   projects/spec/trunk/modules/impl/src/main/resources/jbpm-cfg-beans.xml
Log:
Add Node persistence

Modified: projects/spec/trunk/modules/api/pom.xml
===================================================================
--- projects/spec/trunk/modules/api/pom.xml	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/api/pom.xml	2008-10-08 15:11:43 UTC (rev 2510)
@@ -27,6 +27,7 @@
 
   <!-- Properties -->
   <properties>
+    <hibernate.version>3.2.6.ga</hibernate.version>
     <jboss.microcontainer.version>2.0.0.CR1</jboss.microcontainer.version>
   </properties>
   
@@ -34,6 +35,11 @@
   <dependencyManagement>
     <dependencies>
       <dependency>
+        <groupId>org.hibernate</groupId>
+        <artifactId>hibernate</artifactId>
+        <version>${hibernate.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.jboss.microcontainer</groupId>
         <artifactId>jboss-kernel</artifactId>
         <version>${jboss.microcontainer.version}</version>
@@ -48,6 +54,10 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.microcontainer</groupId>
       <artifactId>jboss-kernel</artifactId>
     </dependency>

Modified: projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java
===================================================================
--- projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/PersistenceService.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -25,12 +25,14 @@
 
 import javax.management.ObjectName;
 
+import org.hibernate.Session;
 import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.model.Node;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.model.Process;
 
 /**
- * The persistence service for a process.
+ * The persistence service.
  * 
  * @author thomas.diesler at jboss.com
  * @since 17-Sep-2008
@@ -45,8 +47,13 @@
     ProcessEngine engine = ProcessEngine.getProcessEngine();
     return engine.getService(PersistenceService.class);
   }
-  
+
   /**
+   * Create a new persistence session
+   */
+  public abstract Session createSession();
+
+  /**
    * Save the ProcessDefinition to persistent storage
    */
   public abstract ObjectName saveProcessDefinition(ProcessDefinition procDef);
@@ -60,7 +67,7 @@
    * Delete the ProcessDefinition from persistent storage
    */
   public abstract void deleteProcessDefinition(ProcessDefinition procDef);
-  
+
   /**
    * Save the Process to persistent storage
    */
@@ -75,4 +82,14 @@
    * Delete the Process from persistent storage
    */
   public abstract void deleteProcess(Process proc);
+
+  /**
+   * Save the Node to persistent storage
+   */
+  public abstract ObjectName saveNode(Session session, Node node);
+
+  /**
+   * Load the Node from persistent storage
+   */
+  public abstract Node loadNode(Session session, ObjectName nodeID);
 }
\ No newline at end of file

Modified: projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessDefinitionService.java
===================================================================
--- projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessDefinitionService.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessDefinitionService.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -30,6 +30,7 @@
 
 import javax.management.ObjectName;
 
+import org.hibernate.Session;
 import org.jbpm.api.client.Deployment;
 import org.jbpm.api.client.ProcessEngine;
 import org.jbpm.api.model.ProcessDefinition;
@@ -92,11 +93,18 @@
     log.debug("registerProcessDefinition: " + procDef);
     
     // Save the ProcessDefinition through the PersistenceService
-    PersistenceService dbService = getProcessEngine().getService(PersistenceService.class);
-    ObjectName procDefID = dbService.saveProcessDefinition(procDef);
-    
-    procDefs.put(procDefID, procDef);
-    return procDefID;
+    PersistenceService persService = getProcessEngine().getService(PersistenceService.class);
+    Session session = persService.createSession();
+    try
+    {
+      ObjectName procDefID = persService.saveProcessDefinition(procDef);
+      procDefs.put(procDefID, procDef);
+      return procDefID;
+    }
+    finally
+    {
+      session.close();
+    }
   }
 
   /**
@@ -118,11 +126,18 @@
         procService.unregisterProcess(procID);
         
       // Delete the ProcessDefinition through the PersistenceService
-      PersistenceService dbService = engine.getService(PersistenceService.class);
-      dbService.deleteProcessDefinition(procDef);
-      
-      procDefs.remove(procDefID);
-      removed = true;
+      PersistenceService persService = engine.getService(PersistenceService.class);
+      Session session = persService.createSession();
+      try
+      {
+        persService.deleteProcessDefinition(procDef);
+        procDefs.remove(procDefID);
+        removed = true;
+      }
+      finally
+      {
+        session.close();
+      }
     }
     return removed;
   }

Modified: projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessService.java
===================================================================
--- projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessService.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ProcessService.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -31,6 +31,7 @@
 
 import javax.management.ObjectName;
 
+import org.hibernate.Session;
 import org.jbpm.api.client.ProcessEngine;
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
@@ -89,11 +90,18 @@
       procDefService.registerProcessDefinition(procDef);
     
     // Save the process through the PersistenceService
-    PersistenceService dbService = getProcessEngine().getService(PersistenceService.class);
-    ObjectName procID = dbService.saveProcess(proc);
-    
-    registeredProcs.put(procID, proc);
-    return procID;
+    PersistenceService persService = getProcessEngine().getService(PersistenceService.class);
+    Session session = persService.createSession();
+    try
+    {
+      ObjectName procID = persService.saveProcess(proc);
+      registeredProcs.put(procID, proc);
+      return procID;
+    }
+    finally
+    {
+      session.close();
+    }
   }
 
   /**
@@ -108,11 +116,18 @@
       log.debug("unregisterProcess: " + proc);
       
       // Delete the process through the PersistenceService
-      PersistenceService dbService = getProcessEngine().getService(PersistenceService.class);
-      dbService.deleteProcess(proc);
-      
-      registeredProcs.remove(procID);
-      removed = true;
+      PersistenceService persService = getProcessEngine().getService(PersistenceService.class);
+      Session session = persService.createSession();
+      try
+      {
+        persService.deleteProcess(proc);
+        registeredProcs.remove(procID);
+        removed = true;
+      }
+      finally
+      {
+        session.close();
+      }
     }
     return removed;
   }

Added: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/NodePersistenceTest.java
===================================================================
--- projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/NodePersistenceTest.java	                        (rev 0)
+++ projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/NodePersistenceTest.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -0,0 +1,73 @@
+/*
+ * 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.service.persistence;
+
+// $Id$
+
+import javax.management.ObjectName;
+
+import org.hibernate.Session;
+import org.jbpm.api.model.Node;
+import org.jbpm.api.model.Process;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.Task;
+import org.jbpm.api.service.PersistenceService;
+import org.jbpm.api.service.ProcessDefinitionService;
+import org.jbpm.api.service.ProcessService;
+import org.jbpm.api.test.CTSTestCase;
+import org.jbpm.test.cts.service.process.ProcessCatalog;
+
+/**
+ * Test the PersistenceService for Nodes
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class NodePersistenceTest extends CTSTestCase
+{
+  /**
+   * Test save, load of a Node
+   */
+  public void testNode() throws Exception
+  {
+    ProcessService procService = ProcessService.locateProcessService();
+    PersistenceService service = PersistenceService.locatePersistenceService();
+    
+    // Register (save) the process, which is not done implicitly
+    ProcessDefinition procDef = unregisterOnTearDown(ProcessCatalog.getDefaultProcess());
+    Process proc = procDef.newInstance();
+    procService.registerProcess(proc);
+    
+    ObjectName taskID = proc.getNode(Task.class, "Task").getKey();
+    
+    Session session = service.createSession();
+    try
+    {
+      Node task = service.loadNode(session, taskID);
+      assertNotNull("Node not null", task);
+    }
+    finally
+    {
+      session.close();
+    }
+  }
+}


Property changes on: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/NodePersistenceTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/PersistenceServiceTest.java
===================================================================
--- projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/PersistenceServiceTest.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/PersistenceServiceTest.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -1,124 +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.test.cts.service.persistence;
-
-// $Id: PersistenceServiceTest.java 2419 2008-09-29 07:22:59Z thomas.diesler at jboss.com $
-
-import javax.management.ObjectName;
-
-import org.jbpm.api.ProcessNotFoundException;
-import org.jbpm.api.model.EndEvent;
-import org.jbpm.api.model.Process;
-import org.jbpm.api.model.ProcessDefinition;
-import org.jbpm.api.model.StartEvent;
-import org.jbpm.api.model.Task;
-import org.jbpm.api.service.PersistenceService;
-import org.jbpm.api.service.ProcessDefinitionService;
-import org.jbpm.api.test.CTSTestCase;
-import org.jbpm.test.cts.service.process.ProcessCatalog;
-
-/**
- * Test the PersistenceService
- * 
- * @author thomas.diesler at jboss.com
- * @since 08-Jul-2008
- */
-public class PersistenceServiceTest extends CTSTestCase
-{
-  /**
-   * Test save, load, delete of a trivial ProcessDefinition
-   */
-  public void testProcessDefinition() throws Exception
-  {
-    PersistenceService service = PersistenceService.locatePersistenceService();
-
-    // Save the ProcessDefinition
-    ProcessDefinition procDef = ProcessCatalog.getDefaultProcess();
-    service.saveProcessDefinition(procDef);
-
-    // Load the ProcessDefinition
-    ObjectName procDefID = procDef.getKey();
-    ProcessDefinition loadDef = service.loadProcessDefinition(procDefID);
-    ProcessCatalog.validateDefaultProcess(loadDef);
-
-    StartEvent start = loadDef.getNode(StartEvent.class, "Start");
-    Task task = loadDef.getNode(Task.class, "Task");
-    EndEvent end = loadDef.getNode(EndEvent.class, "End");
-    
-    assertSame(loadDef, start.getProcessDefinition());
-    assertSame(loadDef, task.getProcessDefinition());
-    assertSame(loadDef, end.getProcessDefinition());
-
-    // Delete the ProcessDefinition
-    service.deleteProcessDefinition(procDef);
-    try
-    {
-      service.loadProcessDefinition(procDefID);
-      fail("ProcessNotFoundException expected");
-    }
-    catch (ProcessNotFoundException ex)
-    {
-      // expected
-    }
-  }
-
-  /**
-   * Test save, load, delete of a trivial Process
-   */
-  public void testProcess() throws Exception
-  {
-    ProcessDefinitionService procDefService = ProcessDefinitionService.locateProcessDefinitionService();
-    PersistenceService service = PersistenceService.locatePersistenceService();
-
-    // Register (save) the process definition, which is not done implicitly by saveProcess
-    ProcessDefinition procDef = unregisterOnTearDown(ProcessCatalog.getDefaultProcess());
-    procDefService.registerProcessDefinition(procDef);
-    
-    // Create and save the Process
-    Process proc = procDef.newInstance();
-    service.saveProcess(proc);
-
-    // Load the process
-    ObjectName procID = proc.getKey();
-    Process loadProc = service.loadProcess(procID);
-
-    StartEvent start = loadProc.getNode(StartEvent.class, "Start");
-    Task task = loadProc.getNode(Task.class, "Task");
-    EndEvent end = loadProc.getNode(EndEvent.class, "End");
-    
-    assertSame(loadProc, start.getProcess());
-    assertSame(loadProc, task.getProcess());
-    assertSame(loadProc, end.getProcess());
-    
-    // Delete the process
-    service.deleteProcess(proc);
-    try
-    {
-      service.loadProcess(procID);
-      fail("ProcessNotFoundException expected");
-    }
-    catch (ProcessNotFoundException ex)
-    {
-      // expected
-    }
-  }
-}

Copied: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcesDefinitionPersistenceTest.java (from rev 2508, projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/PersistenceServiceTest.java)
===================================================================
--- projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcesDefinitionPersistenceTest.java	                        (rev 0)
+++ projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcesDefinitionPersistenceTest.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -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.service.persistence;
+
+// $Id: PersistenceServiceTest.java 2419 2008-09-29 07:22:59Z thomas.diesler at jboss.com $
+
+import javax.management.ObjectName;
+
+import org.jbpm.api.ProcessNotFoundException;
+import org.jbpm.api.model.EndEvent;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.StartEvent;
+import org.jbpm.api.model.Task;
+import org.jbpm.api.service.PersistenceService;
+import org.jbpm.api.test.CTSTestCase;
+import org.jbpm.test.cts.service.process.ProcessCatalog;
+
+/**
+ * Test the PersistenceService
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class ProcesDefinitionPersistenceTest extends CTSTestCase
+{
+  /**
+   * Test save, load, delete of a trivial ProcessDefinition
+   */
+  public void testProcessDefinition() throws Exception
+  {
+    PersistenceService service = PersistenceService.locatePersistenceService();
+
+    // Save the ProcessDefinition
+    ProcessDefinition procDef = ProcessCatalog.getDefaultProcess();
+    service.saveProcessDefinition(procDef);
+
+    // Load the ProcessDefinition
+    ObjectName procDefID = procDef.getKey();
+    ProcessDefinition loadDef = service.loadProcessDefinition(procDefID);
+    ProcessCatalog.validateDefaultProcess(loadDef);
+
+    StartEvent start = loadDef.getNode(StartEvent.class, "Start");
+    Task task = loadDef.getNode(Task.class, "Task");
+    EndEvent end = loadDef.getNode(EndEvent.class, "End");
+    
+    assertSame(loadDef, start.getProcessDefinition());
+    assertSame(loadDef, task.getProcessDefinition());
+    assertSame(loadDef, end.getProcessDefinition());
+
+    // Delete the ProcessDefinition
+    service.deleteProcessDefinition(procDef);
+    try
+    {
+      service.loadProcessDefinition(procDefID);
+      fail("ProcessNotFoundException expected");
+    }
+    catch (ProcessNotFoundException ex)
+    {
+      // expected
+    }
+  }
+}

Added: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcessPersistenceTest.java
===================================================================
--- projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcessPersistenceTest.java	                        (rev 0)
+++ projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcessPersistenceTest.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -0,0 +1,87 @@
+/*
+ * 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.service.persistence;
+
+// $Id$
+
+import javax.management.ObjectName;
+
+import org.jbpm.api.ProcessNotFoundException;
+import org.jbpm.api.model.EndEvent;
+import org.jbpm.api.model.Process;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.StartEvent;
+import org.jbpm.api.model.Task;
+import org.jbpm.api.service.PersistenceService;
+import org.jbpm.api.service.ProcessDefinitionService;
+import org.jbpm.api.test.CTSTestCase;
+import org.jbpm.test.cts.service.process.ProcessCatalog;
+
+/**
+ * Test the PersistenceService
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class ProcessPersistenceTest extends CTSTestCase
+{
+  /**
+   * Test save, load, delete of a trivial Process
+   */
+  public void testProcess() throws Exception
+  {
+    ProcessDefinitionService procDefService = ProcessDefinitionService.locateProcessDefinitionService();
+    PersistenceService service = PersistenceService.locatePersistenceService();
+
+    // Register (save) the process definition, which is not done implicitly
+    ProcessDefinition procDef = unregisterOnTearDown(ProcessCatalog.getDefaultProcess());
+    procDefService.registerProcessDefinition(procDef);
+    
+    // Create and save the Process
+    Process proc = procDef.newInstance();
+    service.saveProcess(proc);
+
+    // Load the process
+    ObjectName procID = proc.getKey();
+    Process loadProc = service.loadProcess(procID);
+
+    StartEvent start = loadProc.getNode(StartEvent.class, "Start");
+    Task task = loadProc.getNode(Task.class, "Task");
+    EndEvent end = loadProc.getNode(EndEvent.class, "End");
+    
+    assertSame(loadProc, start.getProcess());
+    assertSame(loadProc, task.getProcess());
+    assertSame(loadProc, end.getProcess());
+    
+    // Delete the process
+    service.deleteProcess(proc);
+    try
+    {
+      service.loadProcess(procID);
+      fail("ProcessNotFoundException expected");
+    }
+    catch (ProcessNotFoundException ex)
+    {
+      // expected
+    }
+  }
+}


Property changes on: projects/spec/trunk/modules/cts/src/test/java/org/jbpm/test/cts/service/persistence/ProcessPersistenceTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceServiceImpl.java
===================================================================
--- projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceServiceImpl.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/HibernatePersistenceServiceImpl.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -34,13 +34,15 @@
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.hibernate.cfg.AnnotationConfiguration;
-import org.hibernate.classic.Session;
+import org.hibernate.Session;
 import org.jbpm.api.ProcessNotFoundException;
 import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.model.Node;
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.service.PersistenceService;
 import org.jbpm.api.service.Service;
+import org.jbpm.ri.model.NodeImpl;
 import org.jbpm.ri.model.ProcessDefinitionImpl;
 import org.jbpm.ri.model.ProcessImpl;
 import org.slf4j.Logger;
@@ -66,7 +68,7 @@
   {
     super.setProcessEngine(engine);
   }
-  
+
   public void setHibernateConfig(String hibernateConfig)
   {
     this.hibernateConfig = hibernateConfig;
@@ -78,6 +80,12 @@
   }
 
   @Override
+  public Session createSession()
+  {
+    return getSessionFactory().openSession();
+  }
+
+  @Override
   public ObjectName saveProcessDefinition(ProcessDefinition procDef)
   {
     log.debug("START saveProcessDefinition: " + procDef.getKey());
@@ -161,13 +169,13 @@
   public Process loadProcess(ObjectName procID)
   {
     log.debug("START loadProcess: " + procID);
-    ProcessImpl procImpl = null;
+    Process proc = null;
     Session session = getSessionFactory().openSession();
     try
     {
       Integer id = Integer.valueOf(procID.getKeyProperty("id"));
-      procImpl = (ProcessImpl)session.load(ProcessImpl.class, id);
-      Hibernate.initialize(procImpl);
+      proc = (Process)session.load(ProcessImpl.class, id);
+      Hibernate.initialize(proc);
     }
     catch (ObjectNotFoundException ex)
     {
@@ -178,7 +186,7 @@
       session.close();
     }
     log.debug("END loadProcess: " + procID);
-    return (Process)procImpl;
+    return proc;
   }
 
   @Override
@@ -199,6 +207,36 @@
     log.debug("END deleteProcess: " + proc);
   }
 
+  @Override
+  public ObjectName saveNode(Session session, Node node)
+  {
+    log.debug("START saveNode: " + node.getKey());
+    
+    session.saveOrUpdate(node);
+    
+    log.debug("END saveNode: " + node.getKey());
+    return node.getKey();
+  }
+
+  @Override
+  public Node loadNode(Session session, ObjectName nodeID)
+  {
+    log.debug("START loadNode: " + nodeID);
+    Node node = null;
+    try
+    {
+      Integer id = Integer.valueOf(nodeID.getKeyProperty("id"));
+      node = (Node)session.load(NodeImpl.class, id);
+      Hibernate.initialize(node);
+    }
+    catch (ObjectNotFoundException ex)
+    {
+      throw new ProcessNotFoundException("Cannot find node: " + nodeID);
+    }
+    log.debug("END loadNode: " + nodeID);
+    return node;
+  }
+
   @SuppressWarnings("unchecked")
   private SessionFactory getSessionFactory()
   {
@@ -214,7 +252,7 @@
     if (sessionFactory == null)
     {
       AnnotationConfiguration anConfig = new AnnotationConfiguration();
-      
+
       String serviceName = null;
       try
       {

Modified: projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/InMemoryPersistenceServiceImpl.java
===================================================================
--- projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/InMemoryPersistenceServiceImpl.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/InMemoryPersistenceServiceImpl.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -28,8 +28,10 @@
 
 import javax.management.ObjectName;
 
+import org.hibernate.Session;
 import org.jbpm.api.ProcessNotFoundException;
 import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.model.Node;
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.service.PersistenceService;
@@ -49,6 +51,7 @@
 
   private Map<ObjectName, ProcessDefinition> procDefs = new HashMap<ObjectName, ProcessDefinition>();
   private Map<ObjectName, Process> procs = new HashMap<ObjectName, Process>();
+  private Map<ObjectName, Node> nodes = new HashMap<ObjectName, Node>();
 
   @Override
   public void setProcessEngine(ProcessEngine engine)
@@ -57,70 +60,77 @@
   }
   
   @Override
+  public Session createSession()
+  {
+    return null;
+  }
+
+  @Override
   public ObjectName saveProcessDefinition(ProcessDefinition procDef)
   {
-    log.debug("START saveProcessDefinition: " + procDef.getKey());
-    
     procDefs.put(procDef.getKey(), procDef);
-    
-    log.debug("END saveProcessDefinition: " + procDef.getKey());
     return procDef.getKey();
   }
 
   @Override
   public ProcessDefinition loadProcessDefinition(ObjectName procDefID)
   {
-    log.debug("START loadProcessDefinition: " + procDefID);
-    
     ProcessDefinition procDef = procDefs.get(procDefID);
     if (procDef == null)
       throw new ProcessNotFoundException("Cannot find process: " + procDefID);
       
-    log.debug("END loadProcessDefinition: " + procDefID);
     return procDef;
   }
 
   @Override
   public void deleteProcessDefinition(ProcessDefinition procDef)
   {
-    log.debug("START deleteProcessDefinition: " + procDef);
-    
     procDefs.remove(procDef.getKey());
-    
-    log.debug("END deleteProcessDefinition: " + procDef);
   }
 
   @Override
   public ObjectName saveProcess(Process proc)
   {
-    log.debug("START saveProcess: " + proc.getKey());
-    
     procs.put(proc.getKey(), proc);
     
-    log.debug("END saveProcess: " + proc.getKey());
+    for (Node node : proc.getNodes())
+      nodes.put(node.getKey(), node);
+    
     return proc.getKey();
   }
 
   @Override
   public Process loadProcess(ObjectName procID)
   {
-    log.debug("START loadProcess: " + procID);
-    
     Process proc = procs.get(procID);
     if (proc == null)
       throw new ProcessNotFoundException("Cannot find process: " + procID);
     
-    log.debug("END loadProcess: " + procID);
     return proc;
   }
 
   @Override
   public void deleteProcess(Process proc)
   {
-    log.debug("START deleteProcess: " + proc);
-    
     procs.remove(proc.getKey());
     
-    log.debug("END deleteProcess: " + proc);
+    for (Node node : proc.getNodes())
+      nodes.remove(node.getKey());
   }
+
+  @Override
+  public ObjectName saveNode(Session session, Node node)
+  {
+    return node.getKey();
+  }
+
+  @Override
+  public Node loadNode(Session session, ObjectName nodeID)
+  {
+    Node node = nodes.get(nodeID);
+    if (node == null)
+      throw new ProcessNotFoundException("Cannot find node: " + nodeID);
+    
+    return node;
+  }
 }

Deleted: projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/PersistenceServiceImpl.java
===================================================================
--- projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/PersistenceServiceImpl.java	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/impl/src/main/java/org/jbpm/ri/service/PersistenceServiceImpl.java	2008-10-08 15:11:43 UTC (rev 2510)
@@ -1,239 +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.ri.service;
-
-// $Id$
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-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.client.ProcessEngine;
-import org.jbpm.api.model.Process;
-import org.jbpm.api.model.ProcessDefinition;
-import org.jbpm.api.service.PersistenceService;
-import org.jbpm.api.service.Service;
-import org.jbpm.ri.model.ProcessDefinitionImpl;
-import org.jbpm.ri.model.ProcessImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A Hibernate based persistence service for a process.
- * 
- * @author thomas.diesler at jboss.com
- * @since 17-Sep-2008
- */
-public class PersistenceServiceImpl extends PersistenceService implements MutableService
-{
-  // Provide logging
-  final Logger log = LoggerFactory.getLogger(PersistenceServiceImpl.class);
-
-  private String hibernateConfig;
-  private SessionFactory sessionFactory;
-  private Set<String> annotatedClasses = new HashSet<String>();
-
-  @Override
-  public void setProcessEngine(ProcessEngine engine)
-  {
-    super.setProcessEngine(engine);
-  }
-  
-  public void setHibernateConfig(String hibernateConfig)
-  {
-    this.hibernateConfig = hibernateConfig;
-  }
-
-  public void setAnnotatedClasses(Set<String> annotatedClasses)
-  {
-    this.annotatedClasses = annotatedClasses;
-  }
-
-  @Override
-  public ObjectName saveProcessDefinition(ProcessDefinition procDef)
-  {
-    log.debug("START saveProcessDefinition: " + procDef.getKey());
-    Session session = getSessionFactory().openSession();
-    Transaction tx = session.beginTransaction();
-    try
-    {
-      session.saveOrUpdate(procDef);
-      tx.commit();
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END saveProcessDefinition: " + procDef.getKey());
-    return procDef.getKey();
-  }
-
-  @Override
-  public ProcessDefinition loadProcessDefinition(ObjectName procDefID)
-  {
-    log.debug("START loadProcessDefinition: " + procDefID);
-    ProcessDefinitionImpl procDefImpl = null;
-    Session session = getSessionFactory().openSession();
-    try
-    {
-      Integer id = Integer.valueOf(procDefID.getKeyProperty("id"));
-      procDefImpl = (ProcessDefinitionImpl)session.load(ProcessDefinitionImpl.class, id);
-      Hibernate.initialize(procDefImpl);
-    }
-    catch (ObjectNotFoundException ex)
-    {
-      throw new ProcessNotFoundException("Cannot find process: " + procDefID);
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END loadProcessDefinition: " + procDefID);
-    return (ProcessDefinition)procDefImpl;
-  }
-
-  @Override
-  public void deleteProcessDefinition(ProcessDefinition procDef)
-  {
-    log.debug("START deleteProcessDefinition: " + procDef);
-    Session session = getSessionFactory().openSession();
-    Transaction tx = session.beginTransaction();
-    try
-    {
-      session.delete(procDef);
-      tx.commit();
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END deleteProcessDefinition: " + procDef);
-  }
-
-  @Override
-  public ObjectName saveProcess(Process proc)
-  {
-    log.debug("START saveProcess: " + proc.getKey());
-    Session session = getSessionFactory().openSession();
-    Transaction tx = session.beginTransaction();
-    try
-    {
-      session.saveOrUpdate(proc);
-      tx.commit();
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END saveProcess: " + proc.getKey());
-    return proc.getKey();
-  }
-
-  @Override
-  public Process loadProcess(ObjectName procID)
-  {
-    log.debug("START loadProcess: " + procID);
-    ProcessImpl procImpl = null;
-    Session session = getSessionFactory().openSession();
-    try
-    {
-      Integer id = Integer.valueOf(procID.getKeyProperty("id"));
-      procImpl = (ProcessImpl)session.load(ProcessImpl.class, id);
-      Hibernate.initialize(procImpl);
-    }
-    catch (ObjectNotFoundException ex)
-    {
-      throw new ProcessNotFoundException("Cannot find process: " + procID);
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END loadProcess: " + procID);
-    return (Process)procImpl;
-  }
-
-  @Override
-  public void deleteProcess(Process proc)
-  {
-    log.debug("START deleteProcess: " + proc);
-    Session session = getSessionFactory().openSession();
-    Transaction tx = session.beginTransaction();
-    try
-    {
-      session.delete(proc);
-      tx.commit();
-    }
-    finally
-    {
-      session.close();
-    }
-    log.debug("END deleteProcess: " + proc);
-  }
-
-  @SuppressWarnings("unchecked")
-  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();
-      
-      String serviceName = null;
-      try
-      {
-        ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
-        Iterator<String> itAnn = annotatedClasses.iterator();
-        while (itAnn.hasNext())
-        {
-          serviceName = itAnn.next();
-          Class<Service> serviceClass = (Class<Service>)ctxLoader.loadClass(serviceName);
-          anConfig.addAnnotatedClass(serviceClass);
-        }
-      }
-      catch (Exception ex)
-      {
-        throw new IllegalStateException("Cannot load service: " + serviceName, ex);
-      }
-
-      sessionFactory = anConfig.configure(hibernateConfig).buildSessionFactory();
-    }
-    return sessionFactory;
-  }
-}

Modified: projects/spec/trunk/modules/impl/src/main/resources/jbpm-cfg-beans.xml
===================================================================
--- projects/spec/trunk/modules/impl/src/main/resources/jbpm-cfg-beans.xml	2008-10-08 13:24:59 UTC (rev 2509)
+++ projects/spec/trunk/modules/impl/src/main/resources/jbpm-cfg-beans.xml	2008-10-08 15:11:43 UTC (rev 2510)
@@ -21,7 +21,7 @@
     </bean>
 
     <!-- The PersistenceService -->
-    <bean name="jBPMPersistenceService" class="org.jbpm.ri.service.PersistenceServiceImpl">
+    <bean name="jBPMPersistenceService" class="org.jbpm.ri.service.HibernatePersistenceServiceImpl">
       <property name="annotatedClasses">
         <set elementClass="java.lang.String">
           <value>org.jbpm.ri.model.AbstractElementImpl</value>




More information about the jbpm-commits mailing list