[jbpm-commits] JBoss JBPM SVN: r6225 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: test/java/org/jbpm and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 17 06:20:05 EDT 2010


Author: mputz
Date: 2010-03-17 06:20:03 -0400 (Wed, 17 Mar 2010)
New Revision: 6225

Added:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2828/
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2828/JBPM2828Test.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2828/
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2828/jbpm.nolog.cfg.xml
Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
Log:
JBPM-2828: Change VariableContainer.deleteVariable to delete the variableInstance if logging service is not enabled

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/VariableContainer.java	2010-03-17 06:53:22 UTC (rev 6224)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/VariableContainer.java	2010-03-17 10:20:03 UTC (rev 6225)
@@ -9,6 +9,9 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hibernate.Session;
+
+import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.context.log.VariableDeleteLog;
 import org.jbpm.graph.exe.ProcessInstance;
@@ -197,8 +200,19 @@
     if (variableInstances != null) {
       VariableInstance variableInstance = (VariableInstance) variableInstances.remove(name);
       if (variableInstance != null) {
-        getToken().addLog(new VariableDeleteLog(variableInstance));
         variableInstance.removeReferences();
+        // is engine running in memory only or with logging enabled? 
+        JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+        if (jbpmContext == null || jbpmContext.getServices().getLoggingService() != null) {
+          // record variable deletion
+          // do not actually delete variable instance because log refers to it
+          getToken().addLog(new VariableDeleteLog(variableInstance));
+        }
+        else {
+          // delete variable instance here before all references to it are lost
+          Session session = jbpmContext.getSession();
+          if (session != null) session.delete(variableInstance);
+        }
       }
     }
   }

Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2828/JBPM2828Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2828/JBPM2828Test.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2828/JBPM2828Test.java	2010-03-17 10:20:03 UTC (rev 6225)
@@ -0,0 +1,160 @@
+/*
+ * 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.JBPM2828;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.Session;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+
+
+/**
+ * Test to verify if contextInstance.deleteVariable(name) does not cause orphaned variable records
+ * 
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-2828">JBPM-2828</a>
+ * @author Martin Putz
+ */
+public class JBPM2828Test extends AbstractDbTestCase {
+
+  protected static List listVariable = new ArrayList();
+  protected static Long longVariable = new Long(10L);
+  protected static String stringVariable = "jBPM";
+
+  static {
+    listVariable.add("Bart");
+    listVariable.add("Lisa");
+    listVariable.add("Marge");
+    listVariable.add("Barney");
+    listVariable.add("Homer");
+    listVariable.add("Maggie");
+   }
+
+
+
+   public static class CreateVariablesAction implements ActionHandler {
+    private static final long serialVersionUID = 1L;
+    public void execute(ExecutionContext executionContext) throws Exception {
+      executionContext.setVariable("listVariable", listVariable); 
+      executionContext.setVariable("longVariable", longVariable); 
+      executionContext.setVariable("stringVariable", stringVariable); 
+    }
+   }
+
+   public static class DeleteVariablesAction implements ActionHandler {
+    private static final long serialVersionUID = 1L;
+    public void execute(ExecutionContext executionContext) throws Exception {
+      executionContext.getContextInstance().deleteVariable("listVariable"); 
+      executionContext.getContextInstance().deleteVariable("longVariable"); 
+      executionContext.getContextInstance().deleteVariable("stringVariable"); 
+    }
+   }
+
+
+  protected JbpmConfiguration getJbpmConfiguration() {
+    if (jbpmConfiguration == null) {
+      jbpmConfiguration = JbpmConfiguration.parseResource("org/jbpm/jbpm2828/jbpm.nolog.cfg.xml");
+    }
+    return jbpmConfiguration;
+  }
+
+
+  public void testDeleteVariable() {
+    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+      "<process-definition name='jbpmXXX'>" +
+      "  <start-state name='start'>" +
+      "    <transition to='state1'>" +
+      "      <action name='createVariables' class='"+this.getClass().getName()+"$CreateVariablesAction'/>" +
+      "    </transition>" +
+      "  </start-state>" +
+      "  <state name='state1'>" +
+      "    <transition to='state2' name='go'>" +
+      "      <action name='deleteVariables' class='"+this.getClass().getName()+"$DeleteVariablesAction'/>" +
+      "    </transition>" +
+      "  </state>" +
+      "  <state name='state2'>" +
+      "    <transition to='end' name='go'/>" +
+      "  </state>" +
+      "  <end-state name='end'/>" +
+      "</process-definition>"
+    );
+
+    processDefinition = saveAndReload(processDefinition);
+    try
+    {
+      ProcessInstance processInstance = new ProcessInstance(processDefinition);
+      processInstance.signal();
+      processInstance = saveAndReload(processInstance);
+
+      assertEquals(listVariable, processInstance.getContextInstance().getVariable("listVariable"));
+      assertEquals(longVariable, processInstance.getContextInstance().getVariable("longVariable"));
+      assertEquals(stringVariable, processInstance.getContextInstance().getVariable("stringVariable"));
+      assertEquals(1, getRecordCount("org.jbpm.context.exe.variableinstance.ByteArrayInstance", null));
+      assertEquals(1, getRecordCount("org.jbpm.context.exe.variableinstance.LongInstance", null));
+      assertEquals(1, getRecordCount("org.jbpm.context.exe.variableinstance.StringInstance", null));
+
+      processInstance.signal();
+      processInstance = saveAndReload(processInstance);
+      assertNull(processInstance.getContextInstance().getVariable("listVariable"));
+      assertNull(processInstance.getContextInstance().getVariable("longVariable"));
+      assertNull(processInstance.getContextInstance().getVariable("stringVariable"));
+      assertEquals(0, getRecordCount("org.jbpm.context.exe.variableinstance.ByteArrayInstance", null));
+      assertEquals(0, getRecordCount("org.jbpm.context.exe.variableinstance.LongInstance", null));
+      assertEquals(0, getRecordCount("org.jbpm.context.exe.variableinstance.StringInstance", null));
+
+    }
+    finally
+    {
+      jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
+    }
+    
+  }
+
+  protected int getRecordCount(String name, String where) {
+    if (session != null) {
+      return getRecords(session, name, where);
+    }
+    else {
+      beginSessionTransaction();
+      try {
+        return getRecords(session, name, where);
+      }
+      finally {
+        commitAndCloseSession();
+      }
+    }
+  }
+   
+   protected int getRecords(Session session, String name, String where) {
+    Number count = (Number) session.createQuery("select count(*) "
+        + "from " + name + (where!=null ? " " + where : "")).uniqueResult();
+    return count.intValue();      
+   }
+
+
+}

Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2828/jbpm.nolog.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2828/jbpm.nolog.cfg.xml	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2828/jbpm.nolog.cfg.xml	2010-03-17 10:20:03 UTC (rev 6225)
@@ -0,0 +1,10 @@
+<jbpm-configuration>
+  <jbpm-context>
+    <service name="authentication"
+      factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
+    <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
+    <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
+    <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
+    <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
+  </jbpm-context>
+</jbpm-configuration>



More information about the jbpm-commits mailing list