[jbpm-commits] JBoss JBPM SVN: r5761 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/job and 7 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Oct 20 10:51:32 EDT 2009
Author: jbarrez
Date: 2009-10-20 10:51:31 -0400 (Tue, 20 Oct 2009)
New Revision: 5761
Added:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/idgenerator/
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/idgenerator/DeploymentIdGenerationTest.java
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.hibernate.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/process.jpdl.xml
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseDbidGenerator.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DbidGenerator.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryDbidGenerator.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/lob/Lob.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
Log:
Bugfix: when recreating a process engine and deploying a process after other processes have been deployed, the dbidGenerator is reset to the wrong values.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseDbidGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseDbidGenerator.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DatabaseDbidGenerator.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -101,6 +101,10 @@
}
}
+ public void reset() {
+ initialize(); // resetting the DatabaseIdGenerator means just reinitializing the id
+ }
+
public void initialize() {
nextId = commandService.execute(new InitializePropertiesCmd(blocksize));
lastId = nextId + blocksize - 1;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DbidGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DbidGenerator.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/DbidGenerator.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -44,4 +44,7 @@
}
public abstract long getNextId();
+
+ public abstract void reset();
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryDbidGenerator.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryDbidGenerator.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/MemoryDbidGenerator.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -27,9 +27,14 @@
*/
public class MemoryDbidGenerator extends DbidGenerator {
- static long nextId = 1;
+ long nextId = 1;
public synchronized long getNextId() {
return nextId++;
}
+
+ public synchronized void reset() {
+ nextId = 1;
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -125,7 +125,7 @@
ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
objectStream.writeObject(configuration);
byte[] bytes = byteStream.toByteArray();
- configurationBytes = new Lob(bytes);
+ configurationBytes = new Lob(bytes, true);
} catch (Exception e) {
throw new JbpmException("couldn't serialize configuration object for "+this, e);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/lob/Lob.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/lob/Lob.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/lob/Lob.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -60,19 +60,35 @@
return dbid;
}
+ public void setDbid(long dbid) {
+ this.dbid = dbid;
+ }
+
+ // Only for Hibernate. Do not use directly!
public Lob() {
}
- public Lob(byte[] bytes) {
+ /**
+ * @param bytes The actual bytes that will be stored.
+ * @param generateId If true, the default {@link DbidGenerator} will be used
+ * generate a dbid for this Lob object.
+ */
+ public Lob(byte[] bytes, boolean generateDbid) {
cachedBytes = bytes;
getBlobStrategy().set(bytes, this);
- this.dbid = DbidGenerator.getDbidGenerator().getNextId();
+
+ if (generateDbid) {
+ this.dbid = DbidGenerator.getDbidGenerator().getNextId();
+ }
}
- public Lob(char[] text) {
+ public Lob(char[] text, boolean generateDbid) {
cachedChars = text;
getClobStrategy().set(text, this);
- this.dbid = DbidGenerator.getDbidGenerator().getNextId();
+
+ if (generateDbid) {
+ this.dbid = DbidGenerator.getDbidGenerator().getNextId();
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -41,6 +41,7 @@
import org.jbpm.pvm.internal.cmd.CommandService;
import org.jbpm.pvm.internal.cmd.DeployCmd;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.id.DbidGenerator;
import org.jbpm.pvm.internal.lob.Lob;
import org.jbpm.pvm.internal.stream.ByteArrayStreamInput;
import org.jbpm.pvm.internal.stream.FileStreamInput;
@@ -144,8 +145,12 @@
} catch (IOException e) {
throw new JbpmException("couldn't read from "+streamInput, e);
}
- Lob lob = new Lob(bytes);
+
+ // Since this method is probably called outside an environment block, we
+ // need to generate the dbid of the Lob later (during the actual deployment).
+ Lob lob = new Lob(bytes, false);
resources.put(name, lob);
+
return this;
}
@@ -156,6 +161,20 @@
return resources.keySet();
}
+ /**
+ * This method should be called before saving the deployment. It will assign a
+ * generated dbid to the resource Lobs.
+ *
+ * Note: when using a database, this method must be called within an
+ * environment block!
+ */
+ public void initResourceLobDbids() {
+ for (Lob resource : resources.values()) {
+ long resourceDbid = DbidGenerator.getDbidGenerator().getNextId();
+ resource.setDbid(resourceDbid);
+ }
+ }
+
public byte[] getBytes(String resourceName) {
if (resources!=null) {
Lob lob = resources.get(resourceName);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -33,6 +33,7 @@
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.id.DbidGenerator;
+import org.jbpm.pvm.internal.lob.Lob;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
@@ -54,8 +55,9 @@
long dbid = DbidGenerator.getDbidGenerator().getNextId();
deploymentImpl.setDbid(dbid);
- session.save(deploymentImpl);
+ deploymentImpl.initResourceLobDbids();
+ session.save(deploymentImpl); // will also save the attached resources
deployerManager.deploy(deploymentImpl);
return deploymentImpl.getId();
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -49,7 +49,7 @@
dbSession.delete(this.lob);
}
}
- this.lob = new Lob((byte[])value);
+ this.lob = new Lob((byte[])value, true);
}
public Lob getLob() {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2009-10-20 14:39:08 UTC (rev 5760)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -44,7 +44,7 @@
}
public void setObject(Object value) {
- this.lob = new Lob((char[])value);
+ this.lob = new Lob((char[])value, true);
}
public Lob getLob() {
Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/idgenerator/DeploymentIdGenerationTest.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/idgenerator/DeploymentIdGenerationTest.java (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/idgenerator/DeploymentIdGenerationTest.java 2009-10-20 14:51:31 UTC (rev 5761)
@@ -0,0 +1,110 @@
+/*
+ * 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.idgenerator;
+
+import java.util.List;
+
+import javax.persistence.Lob;
+
+import org.jbpm.api.Deployment;
+import org.jbpm.api.NewDeployment;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.pvm.internal.id.DbidGenerator;
+import org.jbpm.pvm.internal.id.MemoryDbidGenerator;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+import org.jbpm.test.JbpmCustomCfgTestCase;
+
+
+/**
+ * @author Joram Barrez
+ */
+public class DeploymentIdGenerationTest extends JbpmCustomCfgTestCase {
+
+ /**
+ * Test for a specific problem discovered after changing the idGeneration:
+ *
+ * After deploying some processes, the server is restarted and the
+ * {@link ProcessEngine} is recreated. At that point, when trying to deploy a
+ * process from the classpath, a new {@link Lob} object is created.
+ *
+ * This Lob object required a new dbId from the current DbIdGenerator.
+ * However, the id acquirement happened outside an environment block which
+ * means that the default DbIdGenerator was used: the
+ * {@link MemoryDbidGenerator}.
+ *
+ * Of course, after a restart the member fields of the
+ * {@link MemoryDbidGenerator} were reset, leading to generated ids that were
+ * used before, causing all kind of strange Hibernate errors.
+ *
+ * This test emulates this situation by closing and nullifying the
+ * {@link ProcessEngine} and deploying and continuing a given process.
+ */
+ public void testDeploymentIdGenerationAfterProcessEngineClose() {
+
+ // Start a simple process
+ deployTestProcess();
+ String pid = executionService.startProcessInstanceByKey("simpleProcess").getId();
+
+ // reset process engine and redeploy
+ resetProcessEngineAndDbidGenerator();
+ deployTestProcess();
+
+ // There should now be 2 deployments in the database, with a different id
+ List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
+ assertEquals(2, deployments.size());
+ assertNotSame(deployments.get(0).getId(), deployments.get(1).getId());
+
+ String execId = executionService.findProcessInstanceById(pid).findActiveExecutionIn("a").getId();
+ executionService.signalExecutionById(execId);
+ assertActivityActive(pid, "b");
+
+ resetProcessEngineAndDbidGenerator();
+ execId = executionService.findProcessInstanceById(pid).findActiveExecutionIn("b").getId();
+ executionService.signalExecutionById(execId);
+ assertProcessInstanceEnded(pid);
+ }
+
+ private void deployTestProcess() {
+ NewDeployment deployment = repositoryService.createDeployment()
+ .addResourceFromClasspath(getClass().getPackage().getName().replace(".", "/")+"/process.jpdl.xml");
+ deployment.deploy();
+ registerDeployment(deployment.getId());
+ }
+
+ private void resetProcessEngineAndDbidGenerator() {
+ // Close the process engine and recreate it
+ ProcessEngine oldProcessEngine = processEngine;
+ processEngine.close();
+ processEngine = null;
+
+ initialize(); // creates a new ProcessEngine and services
+ assertNotSame(oldProcessEngine, processEngine);
+
+ // Reset the in memory generator and redeploy the process
+ DbidGenerator.getDefaultIdGenerator().reset();
+ }
+
+}
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.cfg.xml 2009-10-20 14:51:31 UTC (rev 5761)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <import resource="jbpm.businesscalendar.cfg.xml" />
+ <import resource="jbpm.tx.hibernate.cfg.xml" />
+ <import resource="jbpm.jpdl.cfg.xml" />
+ <import resource="jbpm.identity.cfg.xml" />
+
+ <process-engine-context>
+
+ <repository-service />
+ <repository-cache />
+ <execution-service />
+ <history-service />
+ <management-service />
+ <identity-service />
+ <task-service />
+
+ <hibernate-configuration>
+ <cfg resource="org/jbpm/test/idgenerator/jbpm.hibernate.cfg.xml" />
+ </hibernate-configuration>
+
+ <hibernate-session-factory />
+
+ <object class="org.jbpm.pvm.internal.id.DatabaseDbidGenerator" init="eager">
+ <field name="commandService"><ref object="newTxRequiredCommandService" /></field>
+ <invoke method="initialize" />
+ </object>
+
+ <object class="org.jbpm.pvm.internal.id.DatabaseIdComposer" init="eager" />
+
+ <script-manager default-expression-language="juel"
+ default-script-language="juel">
+ <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
+ </script-manager>
+
+ <types resource="jbpm.variable.types.xml" />
+
+ <address-resolver />
+
+ </process-engine-context>
+
+ <transaction-context>
+ <repository-session />
+ <db-session />
+
+ <message-session />
+ <timer-session />
+ <history-session />
+ <mail-session>
+ <mail-server>
+ <session-properties resource="jbpm.mail.properties" />
+ </mail-server>
+ </mail-session>
+ </transaction-context>
+
+</jbpm-configuration>
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.hibernate.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.hibernate.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/jbpm.hibernate.cfg.xml 2009-10-20 14:51:31 UTC (rev 5761)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+
+ <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+ <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
+ <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>
+ <property name="hibernate.connection.username">sa</property>
+ <property name="hibernate.connection.password"></property>
+ <property name="hibernate.format_sql">true</property>
+
+ <property name="hibernate.hbm2ddl.auto">update</property>
+
+ <mapping resource="jbpm.repository.hbm.xml" />
+ <mapping resource="jbpm.execution.hbm.xml" />
+ <mapping resource="jbpm.history.hbm.xml" />
+ <mapping resource="jbpm.task.hbm.xml" />
+ <mapping resource="jbpm.identity.hbm.xml" />
+
+ </session-factory>
+</hibernate-configuration>
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/process.jpdl.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/idgenerator/process.jpdl.xml 2009-10-20 14:51:31 UTC (rev 5761)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<process name='simpleProcess'>
+ <start>
+ <transition to='a' />
+ </start>
+ <state name='a'>
+ <transition to='b' />
+ </state>
+ <state name='b'>
+ <transition to='c' />
+ </state>
+ <end name='c' />
+</process>
\ No newline at end of file
More information about the jbpm-commits
mailing list