Author: alex.guizar(a)jboss.com
Date: 2010-12-06 22:15:04 -0500 (Mon, 06 Dec 2010)
New Revision: 6862
Added:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm2983/
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm2983/SaveOperationsDbTest.java
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/ContextInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/GraphElement.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/PersistenceService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/save/HibernateSaveOperation.java
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm1952/JBPM1952Test.java
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
jbpm3/branches/jbpm-3.2-soa/pom.xml
Log:
JBPM-2983 check if transaction is active before performing save operations
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java 2010-12-03
21:11:52 UTC (rev 6861)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -590,7 +590,7 @@
/**
* gets the jdbc connection from the default configured persistence service.
*
- * @return the jdbc connectoin, or <code>null</code> if a nonstandard
persistence service is
+ * @return the jdbc connection, or <code>null</code> if a nonstandard
persistence service is
* configured.
*/
public Connection getConnection() {
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/ContextInstance.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/ContextInstance.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/ContextInstance.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -135,10 +135,9 @@
* the same as the {@link #addVariables(Map, Token)}, but it was added for more
consistency.
*/
public void setVariables(Map variables, Token token) {
- // [JBPM-1778] Empty map variables on process creation is set as null
+ // [JBPM-1778] empty variable map is set as null on process creation
TokenVariableMap tokenVariableMap = getOrCreateTokenVariableMap(token);
- Iterator iter = variables.entrySet().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = variables.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -50,7 +50,7 @@
setVariableLocally(name, value);
}
else {
- // so let's action to the parent token's TokenVariableMap
+ // propagate to parent variable container
parent.setVariable(name, value);
}
}
@@ -143,12 +143,11 @@
public void setVariableLocally(String name, Object value) {
if (name == null) {
- throw new JbpmException("name is null");
+ throw new IllegalArgumentException("variable name is null");
}
VariableInstance variableInstance = getVariableInstance(name);
- // if there is already a variable instance
- // and it does not support the new value
+ // if variable instance already exists and it does not support the new value
if (variableInstance != null && !variableInstance.supports(value)) {
// delete the old variable instance
if (log.isDebugEnabled()) {
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/GraphElement.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -43,9 +43,9 @@
import org.jbpm.instantiation.UserCodeInterceptorConfig;
import org.jbpm.job.ExecuteActionJob;
import org.jbpm.msg.MessageService;
+import org.jbpm.persistence.PersistenceService;
import org.jbpm.persistence.db.DbPersistenceService;
import org.jbpm.signal.EventService;
-import org.jbpm.svc.Service;
import org.jbpm.util.ClassUtil;
public abstract class GraphElement implements Identifiable, Serializable {
@@ -387,11 +387,10 @@
// see
https://jira.jboss.org/browse/JBPM-1775
JbpmContext jbpmContext = executionContext.getJbpmContext();
if (jbpmContext != null) {
- Service service = jbpmContext.getServices().getPersistenceService();
- if (service instanceof DbPersistenceService) {
- DbPersistenceService persistenceService = (DbPersistenceService) service;
- return persistenceService.isTransactionActive()
- || !persistenceService.isTransactionPresent();
+ PersistenceService persistenceService =
jbpmContext.getServices().getPersistenceService();
+ if (persistenceService instanceof DbPersistenceService) {
+ DbPersistenceService dbPersistenceService = (DbPersistenceService)
persistenceService;
+ return dbPersistenceService.isTransactionActive();
}
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -131,12 +131,12 @@
this.rootToken = new Token(this);
this.key = key;
- // if this is created in the context of a persistent operation
- Services.assignId(this);
-
// create the optional definitions
addInitialModuleDefinitions(processDefinition);
+ // if this is created in the context of a persistent operation
+ Services.assignId(this);
+
// add the creation log
rootToken.addLog(new ProcessInstanceCreateLog());
@@ -148,9 +148,9 @@
}
public void addInitialContextVariables(Map variables) {
- ContextInstance contextInstance = getContextInstance();
- if ((contextInstance != null) && (variables != null)) {
- contextInstance.addVariables(variables);
+ if (variables != null) {
+ ContextInstance contextInstance = getContextInstance();
+ if (contextInstance != null) contextInstance.addVariables(variables);
}
}
@@ -158,21 +158,18 @@
Map definitions = processDefinition.getDefinitions();
// if the state-definition has optional definitions
if (definitions != null) {
- instances = new HashMap();
// loop over each optional definition
for (Iterator i = definitions.values().iterator(); i.hasNext();) {
ModuleDefinition definition = (ModuleDefinition) i.next();
// and create the corresponding optional instance
ModuleInstance instance = definition.createInstance();
- if (instance != null) {
- addInstance(instance);
- }
+ if (instance != null) addInstance(instance);
}
}
}
public void fireStartEvent(Node initialNode) {
- this.start = Clock.getCurrentTime();
+ start = Clock.getCurrentTime();
// fire the process start event
if (initialNode != null) {
@@ -187,69 +184,60 @@
// optional module instances ////////////////////////////////////////////////
/**
- * adds the given optional moduleinstance (bidirectional).
+ * adds the given optional module instance (bidirectional).
*/
public ModuleInstance addInstance(ModuleInstance moduleInstance) {
if (moduleInstance == null) {
throw new IllegalArgumentException("module instance is null");
}
- if (instances == null)
- instances = new HashMap();
+ if (instances == null) instances = new HashMap();
instances.put(moduleInstance.getClass().getName(), moduleInstance);
moduleInstance.setProcessInstance(this);
return moduleInstance;
}
/**
- * removes the given optional moduleinstance (bidirectional).
+ * removes the given optional module instance (bidirectional).
*/
public ModuleInstance removeInstance(ModuleInstance moduleInstance) {
if (moduleInstance == null) {
throw new IllegalArgumentException("module instance is null");
}
- ModuleInstance removedModuleInstance = null;
- if (instances != null) {
- removedModuleInstance = (ModuleInstance)
instances.remove(moduleInstance.getClass()
- .getName());
- if (removedModuleInstance != null) {
- moduleInstance.setProcessInstance(null);
- }
+ if (instances != null &&
instances.remove(moduleInstance.getClass().getName()) != null) {
+ moduleInstance.setProcessInstance(null);
+ return moduleInstance;
}
- return removedModuleInstance;
+ return null;
}
/**
* looks up an optional module instance by its class.
*/
public ModuleInstance getInstance(Class moduleClass) {
- ModuleInstance moduleInstance = null;
String className = moduleClass.getName();
if (instances != null) {
- moduleInstance = (ModuleInstance) instances.get(className);
+ ModuleInstance moduleInstance = (ModuleInstance) instances.get(className);
+ if (moduleInstance != null) return moduleInstance;
}
+ // client requested a module instance that is not in the persistent map;
+ // assume the client wants a transient instance
+ if (transientInstances == null) transientInstances = new HashMap();
+ ModuleInstance moduleInstance = (ModuleInstance) transientInstances.get(className);
if (moduleInstance == null) {
- if (transientInstances == null)
- transientInstances = new HashMap();
-
- // client requested an instance that is not in the map of instances.
- // so we can safely assume that the client wants a transient instance
- moduleInstance = (ModuleInstance) transientInstances.get(className);
- if (moduleInstance == null) {
- try {
- moduleInstance = (ModuleInstance) moduleClass.newInstance();
- moduleInstance.setProcessInstance(this);
- }
- catch (InstantiationException e) {
- throw new JbpmException("failed to instantiate " + moduleClass, e);
- }
- catch (IllegalAccessException e) {
- throw new JbpmException(getClass() + " has no access to " +
moduleClass, e);
- }
- transientInstances.put(className, moduleInstance);
+ try {
+ moduleInstance = (ModuleInstance) moduleClass.newInstance();
+ moduleInstance.setProcessInstance(this);
}
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + moduleClass, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " +
moduleClass, e);
+ }
+ transientInstances.put(className, moduleInstance);
}
return moduleInstance;
@@ -287,9 +275,7 @@
* @throws IllegalStateException if the token is not active.
*/
public void signal() {
- if (hasEnded()) {
- throw new IllegalStateException("token has ended");
- }
+ if (hasEnded()) throw new IllegalStateException("process instance has
ended");
rootToken.signal();
}
@@ -300,9 +286,7 @@
* @throws IllegalStateException if the token is not active.
*/
public void signal(String transitionName) {
- if (hasEnded()) {
- throw new IllegalStateException("token has ended");
- }
+ if (hasEnded()) throw new IllegalStateException("process instance has
ended");
rootToken.signal(transitionName);
}
@@ -313,9 +297,7 @@
* @throws IllegalStateException if the token is not active.
*/
public void signal(Transition transition) {
- if (hasEnded()) {
- throw new IllegalStateException("token has ended");
- }
+ if (hasEnded()) throw new IllegalStateException("process instance has
ended");
rootToken.signal(transition);
}
@@ -324,8 +306,7 @@
*/
public void end() {
// if already ended, do nothing
- if (end != null)
- return;
+ if (end != null) return;
// record the end time
// the end time also indicates that this process instance has ended
@@ -340,10 +321,9 @@
// add the process instance end log
rootToken.addLog(new ProcessInstanceEndLog());
-
- //Fetch this higher, rather than doing the work twice.
+ // Fetch this higher, rather than doing the work twice.
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
-
+
// is this a sub-process?
if (superProcessToken != null && !superProcessToken.hasEnded()) {
// is message service available?
@@ -368,7 +348,7 @@
}
// cancel jobs associated to this process instance
-
+
// is there an active context?
if (jbpmContext != null) {
Services services = jbpmContext.getServices();
@@ -444,17 +424,14 @@
* removes a runtime action.
*/
public RuntimeAction removeRuntimeAction(RuntimeAction runtimeAction) {
- RuntimeAction removedRuntimeAction = null;
if (runtimeAction == null) {
throw new IllegalArgumentException("runtime action is null");
}
- if (runtimeActions != null) {
- if (runtimeActions.remove(runtimeAction)) {
- removedRuntimeAction = runtimeAction;
- runtimeAction.processInstance = null;
- }
+ if (runtimeActions != null && runtimeActions.remove(runtimeAction)) {
+ runtimeAction.processInstance = null;
+ return runtimeAction;
}
- return removedRuntimeAction;
+ return null;
}
/**
@@ -470,18 +447,14 @@
* tells if this process instance is still active or not.
*/
public boolean hasEnded() {
- return (end != null);
+ return end != null;
}
/**
* calculates if this process instance has still options to continue.
*/
public boolean isTerminatedImplicitly() {
- boolean isTerminatedImplicitly = true;
- if (end == null) {
- isTerminatedImplicitly = rootToken.isTerminatedImplicitly();
- }
- return isTerminatedImplicitly;
+ return !hasEnded() ? rootToken.isTerminatedImplicitly() : true;
}
/**
@@ -491,7 +464,7 @@
* @return the specified token or null if the token is not found.
*/
public Token findToken(String tokenPath) {
- return (rootToken != null ? rootToken.findToken(tokenPath) : null);
+ return rootToken != null ? rootToken.findToken(tokenPath) : null;
}
/**
@@ -505,9 +478,7 @@
}
void addCascadeProcessInstance(ProcessInstance cascadeProcessInstance) {
- if (cascadeProcessInstances == null) {
- cascadeProcessInstances = new ArrayList();
- }
+ if (cascadeProcessInstances == null) cascadeProcessInstances = new ArrayList();
cascadeProcessInstances.add(cascadeProcessInstance);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -35,8 +35,8 @@
import org.jbpm.JbpmException;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.persistence.PersistenceService;
import org.jbpm.persistence.db.DbPersistenceService;
-import org.jbpm.svc.Service;
public class ProcessClassLoader extends ClassLoader {
@@ -119,12 +119,13 @@
// is there an active context?
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if (jbpmContext != null) {
- // is a database persistence service present?
- Service service = jbpmContext.getServices().getPersistenceService();
- if (service instanceof DbPersistenceService) {
- // confirm transaction is still active before loading process definition
- DbPersistenceService persistenceService = (DbPersistenceService) service;
- if (persistenceService.isTransactionActive()) {
+ // check if transaction is still active before loading process definition
+ //
https://jira.jboss.org/browse/JBPM-2918
+ PersistenceService persistenceService = jbpmContext.getServices()
+ .getPersistenceService();
+ if (persistenceService instanceof DbPersistenceService) {
+ DbPersistenceService dbPersistenceService = (DbPersistenceService)
persistenceService;
+ if (dbPersistenceService.isTransactionActive()) {
return persistenceService.getGraphSession()
.loadProcessDefinition(processDefinitionId);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -21,33 +21,37 @@
*/
package org.jbpm.logging.db;
-import org.hibernate.Session;
import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
import org.jbpm.logging.LoggingService;
import org.jbpm.logging.log.ProcessLog;
+import org.jbpm.persistence.PersistenceService;
+import org.jbpm.persistence.db.DbPersistenceService;
public class DbLoggingService implements LoggingService {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
- private final Session session;
+ private final PersistenceService persistenceService;
public DbLoggingService() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext == null) {
- throw new JbpmException("no active jbpm context");
- }
- session = jbpmContext.getSession();
+ if (jbpmContext == null) throw new JbpmException("no active jbpm
context");
+ persistenceService = jbpmContext.getServices().getPersistenceService();
}
public void log(ProcessLog processLog) {
- if (session != null) {
- // Improvement suggestions by Max :
- // db-level: use hilo based id strategy to avoid repetitive insert (dependent on
db-lock)
- // session: use stateless session or at least different session
- // can we borrow connection safely. (open on top of another session)
- session.save(processLog);
+ // check if transaction is active before saving log
+ //
https://jira.jboss.org/browse/JBPM-2983
+ if (persistenceService instanceof DbPersistenceService) {
+ DbPersistenceService dbPersistenceService = (DbPersistenceService)
persistenceService;
+ if (dbPersistenceService.isTransactionActive()) {
+ // Improvement suggestions:
+ // db-level: use hi-lo id strategy to avoid repetitive insert (dependent on
db-lock)
+ // session: use stateless session or at least different session
+ // can we borrow connection safely? (open on top of another session)
+ dbPersistenceService.getSession().save(processLog);
+ }
}
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/PersistenceService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/PersistenceService.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/PersistenceService.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -42,10 +42,8 @@
/** @deprecated call {@link TxService#isRollbackOnly()} instead */
boolean isRollbackOnly();
-
/** @deprecated call {@link TxService#setRollbackOnly()} instead */
void setRollbackOnly();
-
/** @deprecated call {@link TxService#setRollbackOnly()} instead */
void setRollbackOnly(boolean isRollbackOnly);
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -185,10 +185,6 @@
return transaction != null && transaction.isActive();
}
- public boolean isTransactionPresent() {
- return transaction != null;
- }
-
protected boolean isTransactionManagedExternally() {
return !isTransactionEnabled;
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -32,8 +32,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.Session;
import org.hibernate.engine.SessionFactoryImplementor;
+
import org.jbpm.JbpmException;
import org.jbpm.persistence.db.DbPersistenceService;
@@ -46,17 +46,14 @@
public JtaDbPersistenceService(JtaDbPersistenceServiceFactory
persistenceServiceFactory) {
super(persistenceServiceFactory);
+ // if no transaction is underway, begin one
+ if (getTransactionStatus() == Status.STATUS_NO_TRANSACTION) beginTransaction();
}
public boolean isTransactionActive() {
return getTransactionStatus() == Status.STATUS_ACTIVE;
}
- public boolean isTransactionPresent() {
- int status = getTransactionStatus();
- return status != Status.STATUS_NO_TRANSACTION && status !=
Status.STATUS_UNKNOWN;
- }
-
protected boolean isTransactionManagedExternally() {
return userTransaction == null;
}
@@ -68,6 +65,7 @@
public void beginTransaction() {
try {
+ if (log.isDebugEnabled()) log.debug("beginning user transaction");
JtaDbPersistenceServiceFactory jtaFactory =
(JtaDbPersistenceServiceFactory) persistenceServiceFactory;
userTransaction = jtaFactory.getUserTransaction();
@@ -81,11 +79,6 @@
}
}
- public Session getSession() {
- if (!isTransactionPresent()) beginTransaction();
- return super.getSession();
- }
-
private int getTransactionStatus() {
try {
if (userTransaction != null) {
@@ -110,6 +103,7 @@
protected Exception commit() {
if (userTransaction != null) {
+ if (log.isDebugEnabled()) log.debug("committing user transaction");
try {
userTransaction.commit();
}
@@ -131,6 +125,7 @@
protected Exception rollback() {
if (userTransaction != null) {
+ if (log.isDebugEnabled()) log.debug("rolling back user transaction");
try {
userTransaction.rollback();
}
@@ -143,6 +138,7 @@
if (transactionManager == null) {
throw new JbpmException("cannot honor rollback request without transaction
manager");
}
+ if (log.isDebugEnabled()) log.debug("marking external transaction for
rollback");
try {
transactionManager.setRollbackOnly();
}
@@ -153,7 +149,6 @@
return null;
}
- /** @deprecated use !{@link #isTransactionManagedExternally()} instead */
public boolean isJtaTxCreated() {
return !isTransactionManagedExternally();
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-03
21:11:52 UTC (rev 6861)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -263,6 +263,7 @@
if (firstException != null) throw firstException;
}
+ /** @deprecated call {@link DbPersistenceService#isLockingException(Exception)} instead
*/
public static boolean isCausedByStaleState(JbpmPersistenceException
persistenceException) {
return DbPersistenceService.isLockingException(persistenceException);
}
@@ -270,7 +271,7 @@
/** assigns an identifier to the given object */
public static void assignId(Object object) {
PersistenceService service =
- (PersistenceService) Services.getCurrentService(SERVICENAME_PERSISTENCE, false);
+ (PersistenceService) getCurrentService(SERVICENAME_PERSISTENCE, false);
if (service != null) service.assignId(object);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/save/HibernateSaveOperation.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/save/HibernateSaveOperation.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/save/HibernateSaveOperation.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -21,23 +21,24 @@
*/
package org.jbpm.svc.save;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.Session;
import org.jbpm.JbpmContext;
import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.PersistenceService;
+import org.jbpm.persistence.db.DbPersistenceService;
public class HibernateSaveOperation implements SaveOperation {
private static final long serialVersionUID = 1L;
public void save(ProcessInstance processInstance, JbpmContext jbpmContext) {
- Session session = jbpmContext.getSession();
- if (session != null) {
- if (log.isDebugEnabled()) log.debug("saving " + processInstance);
- session.save(processInstance);
+ // check if transaction is active before saving process instance
+ //
https://jira.jboss.org/browse/JBPM-2983
+ PersistenceService persistenceService =
jbpmContext.getServices().getPersistenceService();
+ if (persistenceService instanceof DbPersistenceService) {
+ DbPersistenceService dbPersistenceService = (DbPersistenceService)
persistenceService;
+ if (dbPersistenceService.isTransactionActive()) {
+ dbPersistenceService.getSession().save(processInstance);
+ }
}
}
-
- private static final Log log = LogFactory.getLog(HibernateSaveOperation.class);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -31,7 +31,6 @@
import org.jbpm.ejb.impl.JobListenerBean;
import org.jbpm.svc.Service;
import org.jbpm.svc.ServiceFactory;
-import org.jbpm.svc.Services;
import org.jbpm.util.JndiUtil;
/**
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -26,9 +26,7 @@
import java.util.Iterator;
import java.util.List;
-import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
import org.apache.cactus.ServletTestCase;
import org.apache.commons.logging.Log;
@@ -57,11 +55,8 @@
protected CommandService commandService;
private List processDefinitions = new ArrayList();
-
private final Log log = LogFactory.getLog(getClass());
- private static Context environment;
-
protected AbstractEnterpriseTestCase() {
}
@@ -81,15 +76,15 @@
}
protected CommandService createCommandService() throws Exception {
- Object object = getEnvironment().lookup("ejb/CommandServiceBean");
- CommandService commandService;
+ Object bean = new
InitialContext().lookup("java:comp/env/ejb/CommandServiceBean");
- if (object instanceof CommandService) {
+ CommandService commandService;
+ if (bean instanceof CommandService) {
// compatibility with EJB3 homeless beans
- commandService = (CommandService) object;
+ commandService = (CommandService) bean;
}
else {
- LocalCommandServiceHome home = (LocalCommandServiceHome) object;
+ LocalCommandServiceHome home = (LocalCommandServiceHome) bean;
commandService = home.create();
}
@@ -150,19 +145,6 @@
commandService.execute(new DeleteProcessDefinitionCommand(processDefinitionId));
}
- private static Context getEnvironment() throws NamingException {
- if (environment == null) {
- Context initial = new InitialContext();
- try {
- environment = (Context) initial.lookup("java:comp/env");
- }
- finally {
- initial.close();
- }
- }
- return environment;
- }
-
private static final class RetryCommandService implements CommandService {
private final CommandService delegate;
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm1952/JBPM1952Test.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm1952/JBPM1952Test.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm1952/JBPM1952Test.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -8,8 +8,8 @@
import org.jbpm.graph.def.EventCallback;
/**
- * Use JMS instead of DBMS for storing jobs, so that each job is not taken by multiple
job executor
- * threads.
+ * Use JMS instead of DBMS for storing jobs, so that each job is not taken by multiple
job
+ * executor threads.
*
* @see <a
href="https://jira.jboss.org/jira/browse/JBPM-1952">JBPM-195...
* @author Alejandro Guizar
@@ -24,40 +24,40 @@
public void testStaleStateInAsyncFork() {
deployProcessDefinition("<process-definition
name='jbpm1952'>"
- + " <event type='process-end'>"
- + " <action expression='#{eventCallback.processEnd}'
/>"
- + " </event>"
- + " <start-state>"
- + " <transition to='a' />"
- + " </start-state>"
- + " <node name='a' async='true'>"
- + " <transition to='b' />"
- + " </node>"
- + " <node name='b' async='true'>"
- + " <transition to='fork' />"
- + " </node>"
- + " <fork name='fork'>"
- + " <transition to='c1' name='to_c1'/>"
- + " <transition to='c2' name='to_c2'/>"
- + " <transition to='c3' name='to_c3'/>"
- + " </fork>"
- + " <node name='c1' async='true'>"
- + " <transition to='join' />"
- + " </node>"
- + " <node name='c2' async='true'>"
- + " <transition to='join' />"
- + " </node>"
- + " <node name='c3' async='true'>"
- + " <transition to='join' />"
- + " </node>"
- + " <join name='join' async='exclusive'>"
- + " <transition to='d' />"
- + " </join>"
- + " <node name='d' async='true'>"
- + " <transition to='end' />"
- + " </node>"
- + " <end-state name='end'/>"
- + "</process-definition>");
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}'
/>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b' async='true'>"
+ + " <transition to='fork' />"
+ + " </node>"
+ + " <fork name='fork'>"
+ + " <transition to='c1' name='to_c1'/>"
+ + " <transition to='c2' name='to_c2'/>"
+ + " <transition to='c3' name='to_c3'/>"
+ + " </fork>"
+ + " <node name='c1' async='true'>"
+ + " <transition to='join' />"
+ + " </node>"
+ + " <node name='c2' async='true'>"
+ + " <transition to='join' />"
+ + " </node>"
+ + " <node name='c3' async='true'>"
+ + " <transition to='join' />"
+ + " </node>"
+ + " <join name='join' async='exclusive'>"
+ + " <transition to='d' />"
+ + " </join>"
+ + " <node name='d' async='true'>"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end'/>"
+ + "</process-definition>");
long[] processInstanceIds = new long[PROCESS_EXECUTION_COUNT];
for (int i = 0; i < PROCESS_EXECUTION_COUNT; i++) {
Added:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm2983/SaveOperationsDbTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm2983/SaveOperationsDbTest.java
(rev 0)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jbpm2983/SaveOperationsDbTest.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -0,0 +1,114 @@
+/*
+ * 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.enterprise.jbpm2983;
+
+import javax.transaction.UserTransaction;
+
+import junit.framework.Test;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
+import org.jbpm.command.Command;
+import org.jbpm.command.CommandService;
+import org.jbpm.enterprise.AbstractEnterpriseTestCase;
+import org.jbpm.enterprise.IntegrationTestSetup;
+import org.jbpm.graph.def.DelegationException;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory;
+import org.jbpm.svc.Services;
+
+/**
+ * Check if transaction is active before performing save operations.
+ *
+ * @see <a
href="https://jira.jboss.org/browse/JBPM-2983">JBPM-2983<...
+ * @author Alejandro Guizar
+ */
+public class SaveOperationsDbTest extends AbstractEnterpriseTestCase {
+
+ public static Test suite() {
+ return new IntegrationTestSetup(SaveOperationsDbTest.class,
"enterprise-test.war");
+ }
+
+ protected CommandService createCommandService() throws Exception {
+ return new CommandService() {
+ public Object execute(Command command) {
+ JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
+ UserTransaction tx = null;
+ try {
+ JtaDbPersistenceServiceFactory persistenceServiceFactory =
+ (JtaDbPersistenceServiceFactory)
jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+ tx = persistenceServiceFactory.getUserTransaction();
+ tx.begin();
+
+ Object result = command.execute(jbpmContext);
+ tx.commit();
+ return result;
+ }
+ catch (Exception e) {
+ if (tx != null) {
+ try {
+ tx.rollback();
+ }
+ catch (Exception re) {
+ // ignore
+ }
+ }
+ throw e instanceof RuntimeException ? (RuntimeException) e : new
JbpmException(e);
+ }
+ finally {
+ jbpmContext.close();
+ }
+ }
+ };
+ }
+
+ public void testSaveOperations() {
+ deployProcessDefinition("<?xml version='1.0'?>"
+ + "<process-definition name='jbpm2983'>"
+ + " <start-state name='start'>"
+ + " <transition to='midway' />"
+ + " </start-state>"
+ + " <state name='midway'>"
+ + " <transition to='end'>"
+ + " <script>"
+ + " throw new UnsupportedOperationException(\"you did not see me
coming\");"
+ + " </script>"
+ + " </transition>"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+
+ ProcessInstance processInstance = startProcessInstance("jbpm2983");
+ try {
+ signalToken(processInstance.getRootToken().getId());
+ fail("expected exception");
+ }
+ catch (DelegationException e) {
+ assert e.getCause() instanceof UnsupportedOperationException : e.getCause();
+ }
+
+ long processInstanceId = processInstance.getId();
+ assertTrue("expected process instance " + processInstanceId + " to
have ended",
+ !hasProcessInstanceEnded(processInstanceId));
+ }
+}
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-12-03
21:11:52 UTC (rev 6861)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-12-07
03:15:04 UTC (rev 6862)
@@ -115,7 +115,7 @@
+ " <start-state name='start'>"
+ " <transition to='end'>"
+ " <script>"
- + "
executionContext.getJbpmContext().getSessionFactory().getTransactionManager().setRollbackOnly();"
+ + "
executionContext.jbpmContext.sessionFactory.transactionManager.setRollbackOnly();"
+ " throw new org.hibernate.TransactionException(\"transaction
marked for rollback\");"
+ " </script>"
+ " </transition>"
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml 2010-12-03 21:11:52 UTC (rev
6861)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml 2010-12-07 03:15:04 UTC (rev
6862)
@@ -21,24 +21,14 @@
<version>3.2.10-SNAPSHOT</version>
</parent>
+ <properties>
+ <maven.compiler.source>1.5</maven.compiler.source>
+ <maven.compiler.target>1.5</maven.compiler.target>
+ </properties>
+
<build>
<plugins>
<plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
-
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- </configuration>
- </plugin>
-
- <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
@@ -57,7 +47,7 @@
</plugin>
</plugins>
</build>
-
+
<dependencies>
<dependency>
<groupId>org.jbpm.jbpm3</groupId>
Modified: jbpm3/branches/jbpm-3.2-soa/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-12-03 21:11:52 UTC (rev 6861)
+++ jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-12-07 03:15:04 UTC (rev 6862)
@@ -33,16 +33,17 @@
<!-- Modules -->
<modules>
<module>core</module>
- <module>identity</module>
<module>enterprise</module>
<module>examples</module>
+ <module>identity</module>
<module>simulation</module>
+ <module>tomcat</module>
</modules>
<!-- Properties -->
<properties>
+ <maven.compiler.source>1.4</maven.compiler.source>
<maven.compiler.target>1.4</maven.compiler.target>
- <maven.compiler.source>1.4</maven.compiler.source>
<!-- Dependency versions -->
<cargo.version>1.0.3</cargo.version>
@@ -597,7 +598,6 @@
<jdk>[1.5,1.7)</jdk>
</activation>
<modules>
- <module>tomcat</module>
<module>enterprise-jee5</module>
</modules>
</profile>