[jbpm-commits] JBoss JBPM SVN: r1820 - in jbpm4/pvm/trunk/modules/core/src: main/java/org/jbpm/pvm/internal/env and 24 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Aug 5 03:28:15 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-08-05 03:28:14 -0400 (Tue, 05 Aug 2008)
New Revision: 1820
Added:
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionInterceptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransaction.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionInterceptorBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentDbTestCase.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/BasicTransactionTest.java
jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
Removed:
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/DefaultEnvironment.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTransactionResource.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/TransactionInterceptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/EnterpriseTransaction.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/Resource.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransaction.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnlistBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionInterceptorBinding.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnterpriseTransactionDescriptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/StandardTransactionDescriptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/operation/EnlistOperation.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ConfigurationHelper.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ServiceTestCase.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/
Modified:
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Context.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Transaction.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/VariableDefinitionImpl.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/DefaultCommandService.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateSessionDescriptor.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/DbTestCase.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentFactoryTestCase.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentTestCase.java
jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ManagementServiceTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/BasicEnvironmentTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/langext/LanguageExtensionsDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessExecutionDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSessionTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireObservableTest.java
Log:
refactored transaction support, started simplifying test suite configurations
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Context.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Context.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Context.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -30,6 +30,12 @@
*/
public interface Context {
+ /** key of the environment-factory context in the environment */
+ String CONTEXTNAME_ENVIRONMENT_FACTORY = "environment-factory";
+
+ /** key of the block context in the environment */
+ String CONTEXTNAME_ENVIRONMENT = "environment";
+
String getName();
Object get(String key);
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -26,7 +26,7 @@
import java.net.URL;
import java.util.Set;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
+import org.jbpm.pvm.internal.env.PvmEnvironment;
import org.jbpm.pvm.internal.env.PvmEnvironmentFactoryParser;
import org.jbpm.pvm.internal.log.Log;
import org.jbpm.pvm.internal.stream.FileStreamSource;
@@ -109,7 +109,7 @@
}
public Environment openEnvironment() {
- DefaultEnvironment environment = new DefaultEnvironment(this);
+ PvmEnvironment environment = new PvmEnvironment(this);
log.debug("opening "+environment);
@@ -123,7 +123,7 @@
environment.addContext(applicationWireContext);
// add the environment block context
- WireContext blockContext = new WireContext(blockWireDefinition, DefaultEnvironment.CONTEXTNAME_ENVIRONMENT, environment, true);
+ WireContext blockContext = new WireContext(blockWireDefinition, Context.CONTEXTNAME_ENVIRONMENT, environment, true);
// add the environment block context to the environment
environment.addContext(blockContext);
@@ -136,7 +136,7 @@
blockContext.create();
// fire an open environment event
- applicationWireContext.fire(DefaultEnvironment.EVENT_OPENENVIRONMENT, environment);
+ applicationWireContext.fire(PvmEnvironment.EVENT_OPENENVIRONMENT, environment);
} catch (RuntimeException e) {
// On exception, pop environment
@@ -151,10 +151,10 @@
applicationWireContext.fire(WireContext.EVENT_CLOSE, null);
}
- public void handleException(DefaultEnvironment defaultEnvironment, Throwable exception) {
+ public void handleException(PvmEnvironment pvmEnvironment, Throwable exception) {
log.error("exception in environment block:"+exception.getMessage(), exception);
- WireContext wireContext = (WireContext) defaultEnvironment.getEnvironmentContext();
- wireContext.fire(DefaultEnvironment.EVENT_EXCEPTION, this);
+ WireContext wireContext = (WireContext) pvmEnvironment.getEnvironmentContext();
+ wireContext.fire(PvmEnvironment.EVENT_EXCEPTION, this);
}
// environment-factory context delegation methods ///////////////////////////////////
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Transaction.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Transaction.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Transaction.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,40 +21,23 @@
*/
package org.jbpm.pvm.env;
-import org.jbpm.pvm.util.Listener;
-import org.jbpm.pvm.util.Observable;
+import javax.transaction.Synchronization;
-/**
+
+/** provides access to the transaction in the environment.
+ *
* @author Tom Baeyens
*/
-public interface Transaction extends Listener, Observable {
+public interface Transaction {
- /**
- * is fired when the wiring environment is being flushed. No event info provided.
- */
- String EVENT_FLUSH = "flush";
-
- /**
- * is fired when the wiring environment is being committed. No event info provided.
- * It is the Transaction that will listen to the close of this wiring environment.
- * Upon close, the transaction will fire a commit or rollback event depending on
- * the state of the isRollback property in the transaction.
- */
- String EVENT_BEFORECOMPLETION = "before-completion";
-
- /**
- * is fired when the wiring environment is being rolled back. No event info provided.
- * It is the Transaction that will listen to the close of this wiring environment.
- * Upon close, the transaction will fire a commit or rollback event depending on
- * the state of the isRollback property in the transaction.
- */
- String EVENT_AFTERCOMPLETION = "after-completion";
-
/** marks a transaction for rollback only.
* The transaction will be rolled back upon closing the environment. */
void setRollbackOnly();
- boolean isRolledBack();
- boolean isCommitted();
+ /** is this transaction marked for rollback only ? */
boolean isRollbackOnly();
+
+ /** register a transaction listener. This method will have no
+ * effect if the transactionListener is null. */
+ void registerSynchronization(Synchronization synchronization);
}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/DefaultEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/DefaultEnvironment.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/DefaultEnvironment.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,245 +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.pvm.internal.env;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import org.jbpm.pvm.PvmException;
-import org.jbpm.pvm.env.Context;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.EnvironmentFactory;
-import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.util.Closable;
-
-
-/**
- * @author Tom Baeyens
- */
-public class DefaultEnvironment extends Environment {
-
- private static final long serialVersionUID = 1L;
-
- private static final Log log = Log.getLog(DefaultEnvironment.class.getName());
-
- /** key of the environment-factory context in the environment */
- public static final String CONTEXTNAME_ENVIRONMENT_FACTORY = "environment-factory";
-
- /** key of the block context in the environment */
- public static final String CONTEXTNAME_ENVIRONMENT = "environment";
-
- /** is fired for each exception reported in an environment block with
- * {@link Environment#setException(Throwable)}. */
- public static final String EVENT_EXCEPTION = "exception";
-
- /** is fired when a environment created by this factory is being closed. The
- * info object is the environment that was just opened. */
- public static final String EVENT_CLOSEENVIRONMENT = "close-environment";
-
- /** is fired when a new environment is being opened with this environment factory. The
- * info object is the environment that was just opened. */
- public static final String EVENT_OPENENVIRONMENT = "open-environment";
-
-
- protected String userId;
- protected PvmEnvironmentFactory pvmEnvironmentFactory;
- protected Map<String, Context> contexts;
- protected ArrayList<String> defaultSearchOrderList;
- protected String[] defaultSearchOrder;
- protected transient ClassLoader classLoader;
- protected Throwable exception;
-
- public DefaultEnvironment(PvmEnvironmentFactory pvmEnvironmentFactory) {
- this.pvmEnvironmentFactory = pvmEnvironmentFactory;
- contexts = new HashMap<String, Context>();
- defaultSearchOrderList = new ArrayList<String>();
- defaultSearchOrder = null;
- }
-
- // context methods ////////////////////////////////////////////////////////////
-
- public Context getContext(String contextName) {
- return contexts.get(contextName);
- }
-
- public void addContext(Context context) {
- String key = context.getName();
- contexts.put(key, context);
- defaultSearchOrderList.add(key);
- defaultSearchOrder = null;
- }
-
- public void removeContext(Context context) {
- String contextName = context.getName();
- Context removedContext = contexts.remove(contextName);
- if (removedContext!=null) {
- defaultSearchOrderList.remove(contextName);
- defaultSearchOrder = null;
- }
- }
-
- public Context getEnvironmentFactoryContext() {
- return getContext(CONTEXTNAME_ENVIRONMENT_FACTORY);
- }
-
- public Context getEnvironmentContext() {
- return getContext(CONTEXTNAME_ENVIRONMENT);
- }
-
- public EnvironmentFactory getEnvironmentFactory() {
- return pvmEnvironmentFactory;
- }
-
- // userId methods ///////////////////////////////////////////////////////////
-
- public String getUserId() {
- // if the authenticated user was explicitely set
- if (userId!=null) {
- // return that one
- return userId;
- }
-
- // if an Authentication was specified
- Authentication authentication = get(Authentication.class);
- if (authentication!=null) {
- // let the authentication do the work
- return authentication.getUserId();
- }
-
- return null;
- }
-
- public void setUserId(String userId) {
- this.userId = userId;
- }
-
- // classloader methods //////////////////////////////////////////////////////
-
- public ClassLoader getClassLoader() {
- return classLoader;
- }
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- // search methods ///////////////////////////////////////////////////////////
-
- public Object get(String name) {
- return get(name, null);
- }
-
- public Object get(String name, String[] searchOrder) {
- if (searchOrder==null) {
- searchOrder = getDefaultSearchOrder();
- }
- for (int i=0; i<searchOrder.length; i++){
- Context context = contexts.get(searchOrder[i]);
- if (context.has(name)) {
- return context.get(name);
- }
- }
- return null;
- }
-
- public <T> T get(Class<T> type) {
- return find(type, null);
- }
-
- public <T> T find(Class<T> type, String[] searchOrder) {
- if (searchOrder==null) {
- searchOrder = getDefaultSearchOrder();
- }
- for (int i=0; i<searchOrder.length; i++){
- Context context = contexts.get(searchOrder[i]);
- T o = context.get(type);
- if (o!=null) {
- return o;
- }
- }
- return null;
- }
-
- // exception ////////////////////////////////////////////////////////////////
-
- public void setException(Throwable exception) {
- this.exception = exception;
- pvmEnvironmentFactory.handleException(this, exception);
-
- // if an exception was thrown
- if (exception!=null) {
- rethrow(exception);
- }
- }
-
- public Throwable getException() {
- return exception;
- }
-
- // close ////////////////////////////////////////////////////////////////////
-
- public void close() {
- log.debug("closing "+this+"...");
-
- pvmEnvironmentFactory.getApplicationWireContext().fire(DefaultEnvironment.EVENT_CLOSEENVIRONMENT, this);
-
- Environment popped = Environment.popEnvironment();
- if (this!=popped) {
- throw new PvmException("environment nesting problem");
- }
-
- Context context = getEnvironmentContext();
- if (context instanceof Closable) {
- ((Closable)context).close();
- }
- log.debug("closed "+this);
- }
-
- public String toString() {
- return "Environment["+System.identityHashCode(this)+"]";
- }
-
- protected static void rethrow(Throwable exception) throws Error {
- if (exception instanceof Error) {
- throw (Error) exception;
- }
- if (exception instanceof RuntimeException) {
- throw (RuntimeException) exception;
- }
- throw new PvmException(exception);
- }
-
- // private methods //////////////////////////////////////////////////////////
-
- private String[] getDefaultSearchOrder() {
- if (defaultSearchOrder==null) {
- int size = defaultSearchOrderList.size();
- defaultSearchOrder = (String[]) new String[size];
- for (int i=0; i<size; i++) {
- defaultSearchOrder[i] = defaultSearchOrderList.get(size-1-i);
- }
- }
- return defaultSearchOrder;
- }
-
-}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java (from rev 1788, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/DefaultEnvironment.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,239 @@
+/*
+ * 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.pvm.internal.env;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Context;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.EnvironmentFactory;
+import org.jbpm.pvm.env.PvmEnvironmentFactory;
+import org.jbpm.pvm.internal.log.Log;
+import org.jbpm.pvm.internal.util.Closable;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class PvmEnvironment extends Environment {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log = Log.getLog(PvmEnvironment.class.getName());
+
+ /** is fired for each exception reported in an environment block with
+ * {@link Environment#setException(Throwable)}. */
+ public static final String EVENT_EXCEPTION = "exception";
+
+ /** is fired when a environment created by this factory is being closed. The
+ * info object is the environment that was just opened. */
+ public static final String EVENT_CLOSEENVIRONMENT = "close-environment";
+
+ /** is fired when a new environment is being opened with this environment factory. The
+ * info object is the environment that was just opened. */
+ public static final String EVENT_OPENENVIRONMENT = "open-environment";
+
+
+ protected String userId;
+ protected PvmEnvironmentFactory pvmEnvironmentFactory;
+ protected Map<String, Context> contexts;
+ protected ArrayList<String> defaultSearchOrderList;
+ protected String[] defaultSearchOrder;
+ protected transient ClassLoader classLoader;
+ protected Throwable exception;
+
+ public PvmEnvironment(PvmEnvironmentFactory pvmEnvironmentFactory) {
+ this.pvmEnvironmentFactory = pvmEnvironmentFactory;
+ contexts = new HashMap<String, Context>();
+ defaultSearchOrderList = new ArrayList<String>();
+ defaultSearchOrder = null;
+ }
+
+ // context methods ////////////////////////////////////////////////////////////
+
+ public Context getContext(String contextName) {
+ return contexts.get(contextName);
+ }
+
+ public void addContext(Context context) {
+ String key = context.getName();
+ contexts.put(key, context);
+ defaultSearchOrderList.add(key);
+ defaultSearchOrder = null;
+ }
+
+ public void removeContext(Context context) {
+ String contextName = context.getName();
+ Context removedContext = contexts.remove(contextName);
+ if (removedContext!=null) {
+ defaultSearchOrderList.remove(contextName);
+ defaultSearchOrder = null;
+ }
+ }
+
+ public Context getEnvironmentFactoryContext() {
+ return getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
+ }
+
+ public Context getEnvironmentContext() {
+ return getContext(Context.CONTEXTNAME_ENVIRONMENT);
+ }
+
+ public EnvironmentFactory getEnvironmentFactory() {
+ return pvmEnvironmentFactory;
+ }
+
+ // userId methods ///////////////////////////////////////////////////////////
+
+ public String getUserId() {
+ // if the authenticated user was explicitely set
+ if (userId!=null) {
+ // return that one
+ return userId;
+ }
+
+ // if an Authentication was specified
+ Authentication authentication = get(Authentication.class);
+ if (authentication!=null) {
+ // let the authentication do the work
+ return authentication.getUserId();
+ }
+
+ return null;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ // classloader methods //////////////////////////////////////////////////////
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ // search methods ///////////////////////////////////////////////////////////
+
+ public Object get(String name) {
+ return get(name, null);
+ }
+
+ public Object get(String name, String[] searchOrder) {
+ if (searchOrder==null) {
+ searchOrder = getDefaultSearchOrder();
+ }
+ for (int i=0; i<searchOrder.length; i++){
+ Context context = contexts.get(searchOrder[i]);
+ if (context.has(name)) {
+ return context.get(name);
+ }
+ }
+ return null;
+ }
+
+ public <T> T get(Class<T> type) {
+ return find(type, null);
+ }
+
+ public <T> T find(Class<T> type, String[] searchOrder) {
+ if (searchOrder==null) {
+ searchOrder = getDefaultSearchOrder();
+ }
+ for (int i=0; i<searchOrder.length; i++){
+ Context context = contexts.get(searchOrder[i]);
+ T o = context.get(type);
+ if (o!=null) {
+ return o;
+ }
+ }
+ return null;
+ }
+
+ // exception ////////////////////////////////////////////////////////////////
+
+ public void setException(Throwable exception) {
+ this.exception = exception;
+ pvmEnvironmentFactory.handleException(this, exception);
+
+ // if an exception was thrown
+ if (exception!=null) {
+ rethrow(exception);
+ }
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ // close ////////////////////////////////////////////////////////////////////
+
+ public void close() {
+ log.debug("closing "+this+"...");
+
+ pvmEnvironmentFactory.getApplicationWireContext().fire(PvmEnvironment.EVENT_CLOSEENVIRONMENT, this);
+
+ Environment popped = Environment.popEnvironment();
+ if (this!=popped) {
+ throw new PvmException("environment nesting problem");
+ }
+
+ Context context = getEnvironmentContext();
+ if (context instanceof Closable) {
+ ((Closable)context).close();
+ }
+ log.debug("closed "+this);
+ }
+
+ public String toString() {
+ return "Environment["+System.identityHashCode(this)+"]";
+ }
+
+ protected static void rethrow(Throwable exception) throws Error {
+ if (exception instanceof Error) {
+ throw (Error) exception;
+ }
+ if (exception instanceof RuntimeException) {
+ throw (RuntimeException) exception;
+ }
+ throw new PvmException(exception);
+ }
+
+ // private methods //////////////////////////////////////////////////////////
+
+ private String[] getDefaultSearchOrder() {
+ if (defaultSearchOrder==null) {
+ int size = defaultSearchOrderList.size();
+ defaultSearchOrder = (String[]) new String[size];
+ for (int i=0; i<size; i++) {
+ defaultSearchOrder[i] = defaultSearchOrderList.get(size-1-i);
+ }
+ }
+ return defaultSearchOrder;
+ }
+
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ LF
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,6 +21,7 @@
*/
package org.jbpm.pvm.internal.env;
+import org.jbpm.pvm.env.Context;
import org.jbpm.pvm.env.EnvironmentFactory;
import org.jbpm.pvm.env.PvmEnvironmentFactory;
import org.jbpm.pvm.internal.stream.StreamSource;
@@ -79,7 +80,7 @@
WireDefinition environmentWireDefinition = getBlockWireDefinition(documentElement, parse);
// create the application wire context from the definition
- WireContext environmentFactoryWireContext = new WireContext(environmentFactoryWireDefinition, DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY, pvmEnvironmentFactory);
+ WireContext environmentFactoryWireContext = new WireContext(environmentFactoryWireDefinition, Context.CONTEXTNAME_ENVIRONMENT_FACTORY, pvmEnvironmentFactory);
// propagate the parser classloader to the application context
environmentFactoryWireContext.setClassLoader(classLoader);
@@ -93,7 +94,7 @@
}
WireDefinition getApplicationWireDefinition(Element documentElement, Parse parse) {
- Element applicationElement = XmlUtil.element(documentElement, DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY);
+ Element applicationElement = XmlUtil.element(documentElement, Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
if (applicationElement != null) {
return (WireDefinition) environmentFactoryXmlParser.parseDocumentElement(applicationElement, parse);
}
@@ -101,7 +102,7 @@
}
WireDefinition getBlockWireDefinition(Element documentElement, Parse parse) {
- Element blockElement = XmlUtil.element(documentElement, DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ Element blockElement = XmlUtil.element(documentElement, Context.CONTEXTNAME_ENVIRONMENT);
if (blockElement != null) {
return (WireDefinition) environmentXmlParser.parseDocumentElement(blockElement, parse);
}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTransactionResource.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTransactionResource.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTransactionResource.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,67 +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.pvm.internal.hibernate;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.tx.Resource;
-
-/**
- * @author Tom Baeyens
- */
-public class HibernateTransactionResource implements Resource {
-
- private static final Log log = Log.getLog(HibernateTransactionResource.class.getName());
-
- Session session;
- Transaction transaction;
-
- public HibernateTransactionResource(Transaction transaction, Session session) {
- this.transaction = transaction;
- this.session = session;
- }
-
- public void flush() {
- log.debug("flushing hibernate session");
- session.flush();
- }
-
- public void prepare() {
- log.debug("flushing hibernate session");
- session.flush();
- }
-
- public void commit() {
- log.debug("committing hibernate session");
- transaction.commit();
- }
-
- public void rollback() {
- log.debug("rolling back hibernate session");
- transaction.rollback();
- }
-
- public String toString() {
- return "HibernateTransactionResource";
- }
-}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -37,7 +37,6 @@
import org.jbpm.pvm.job.Timer;
import org.jbpm.pvm.model.ObservableElement;
import org.jbpm.pvm.session.DbSession;
-import org.jbpm.pvm.util.Listener;
/** a runtime timer instance.
*
@@ -147,8 +146,8 @@
if (transaction==null) {
throw new PvmException("no transaction in environment");
}
- Listener jobNotificator = new JobAddedNotification(jobExecutor);
- transaction.addListener(jobNotificator);
+ JobAddedNotification jobNotificator = new JobAddedNotification(jobExecutor);
+ transaction.registerSynchronization(jobNotificator);
}
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -39,6 +39,7 @@
* @author Tom Baeyens
*/
public class ExecuteJobCmd implements Command<Job> {
+
private static final long serialVersionUID = 1L;
private static final Log log = Log.getLog(ExecuteJobCmd.class.getName());
@@ -96,6 +97,6 @@
CommandService commandService = (CommandService) environment.get(CommandService.class);
JobExceptionHandler jobExceptionHandler = new JobExceptionHandler(job.getDbid(), exception, commandService);
- transaction.addListener(jobExceptionHandler, Transaction.EVENT_AFTERCOMPLETION);
+ transaction.registerSynchronization(jobExceptionHandler);
}
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,10 +21,9 @@
*/
package org.jbpm.pvm.internal.jobexecutor;
-import org.jbpm.pvm.env.Transaction;
+import javax.transaction.Synchronization;
+
import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
-import org.jbpm.pvm.util.Listener;
/** listener that can be registered as a listener to the transaction
* to notify the jobImpl executor of added jobs so that the dispatcher
@@ -32,7 +31,7 @@
*
* @author Tom Baeyens
*/
-public class JobAddedNotification implements Listener {
+public class JobAddedNotification implements Synchronization {
private static final Log log = Log.getLog(JobAddedNotification.class.getName());
@@ -42,12 +41,11 @@
this.jobExecutor = jobExecutor;
}
- public void event(Object source, String eventName, Object info) {
- if ( (Transaction.EVENT_AFTERCOMPLETION.equals(eventName))
- && (StandardTransaction.STATE_COMMITTED.equals(info))
- ) {
- log.trace("notifying jobImpl executor of added message");
- jobExecutor.jobWasAdded();
- }
+ public void afterCompletion(int arg0) {
+ log.trace("notifying jobImpl executor of added message");
+ jobExecutor.jobWasAdded();
}
+
+ public void beforeCompletion() {
+ }
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -24,6 +24,8 @@
import java.io.PrintWriter;
import java.io.StringWriter;
+import javax.transaction.Synchronization;
+
import org.hibernate.Session;
import org.jbpm.pvm.PvmException;
import org.jbpm.pvm.env.Environment;
@@ -32,12 +34,11 @@
import org.jbpm.pvm.internal.cmd.CommandService;
import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.util.Listener;
-/**
+/**
* @author Tom Baeyens
*/
-public class JobExceptionHandler implements Listener, Command<Object> {
+public class JobExceptionHandler implements Synchronization, Command<Object> {
private static final Log log = Log.getLog(JobExceptionHandler.class.getName());
private static final long serialVersionUID = 1L;
@@ -52,7 +53,15 @@
this.exception = exception;
}
- public void event(Object source, String eventName, Object info) {
+
+ public void beforeCompletion() {
+ }
+
+ public void afterCompletion(int status) {
+ // after the transaction rolled back,
+ // execute this job exception handler object as a command with
+ // the command service so that this gets done in a separate
+ // transaction
commandService.execute(this);
}
@@ -85,10 +94,9 @@
&& (jobExecutor!=null)
) {
log.trace("registering job executor notifier with "+transaction);
- transaction.addListener(new JobAddedNotification(jobExecutor));
+ transaction.registerSynchronization(new JobAddedNotification(jobExecutor));
}
}
return null;
}
-
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -59,7 +59,7 @@
if (jobExecutor==null) {
throw new PvmException("no job executor configured to execute "+message);
}
- transaction.addListener(new JobAddedNotification(jobExecutor));
+ transaction.registerSynchronization(new JobAddedNotification(jobExecutor));
}
}
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -48,7 +48,7 @@
jobDbSession.save(timer);
if (!jobExecutorNotificationScheduled) {
jobExecutorNotificationScheduled = true;
- transaction.addListener(new JobAddedNotification(jobExecutor));
+ transaction.registerSynchronization(new JobAddedNotification(jobExecutor));
}
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -25,6 +25,9 @@
import java.util.ArrayList;
import java.util.List;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
import org.jbpm.pvm.PvmException;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
@@ -37,7 +40,6 @@
import org.jbpm.pvm.listener.EventListener;
import org.jbpm.pvm.model.ProcessDefinition;
import org.jbpm.pvm.session.DbSession;
-import org.jbpm.pvm.util.Listener;
/**
* @author Tom Baeyens
@@ -130,7 +132,7 @@
exception,
environment.getEnvironmentFactory()
);
- transaction.addListener(afterTxCompletionListener, Transaction.EVENT_AFTERCOMPLETION);
+ transaction.registerSynchronization(afterTxCompletionListener);
log.trace("registering exception handler to "+transaction);
throw new PvmException("transaction exception handler registered handler after transaction completed. make sure this transaction is rolled back", exception);
} else {
@@ -214,7 +216,7 @@
}
}
- private class AfterTxCompletionListener implements Listener, Command<Object> {
+ private class AfterTxCompletionListener implements Synchronization, Command<Object> {
private static final long serialVersionUID = 1L;
@@ -228,9 +230,8 @@
this.environmentFactory = environmentFactory;
}
- public void event(Object source, String eventName, Object info) {
- Transaction transaction = (Transaction) source;
- if (! transaction.isRolledBack()) {
+ public void afterCompletion(int status) {
+ if (status!=Status.STATUS_ROLLEDBACK) {
log.info("WARNING: no rollback after transactional exception handler. did you forget to rollback the transaction ?");
}
CommandService commandService = environmentFactory.get(CommandService.class);
@@ -239,6 +240,7 @@
}
commandService.execute(this);
}
+
public Object execute(Environment environment) {
// reload the execution
DbSession dbSession = environment.get(DbSession.class);
@@ -249,6 +251,9 @@
executeHandler(execution, exception);
return null;
}
+
+ public void beforeCompletion() {
+ }
}
public static void rethrow(Exception exception, String prefixMessage) {
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/VariableDefinitionImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/VariableDefinitionImpl.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/VariableDefinitionImpl.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -25,7 +25,7 @@
import org.jbpm.pvm.env.Context;
import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
+import org.jbpm.pvm.internal.env.PvmEnvironment;
import org.jbpm.pvm.internal.type.Type;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/DefaultCommandService.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/DefaultCommandService.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/DefaultCommandService.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -37,11 +37,14 @@
public <T> T execute(Command<T> command) {
Environment environment = Environment.getCurrent();
+
try {
return command.execute(environment);
+
} catch (RuntimeException e) {
log.error("exception while executing command "+command, e);
throw e;
+
} catch (Exception e) {
log.error("exception while executing command "+command, e);
throw new PvmException("exception while executing command "+command, e);
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/TransactionInterceptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/TransactionInterceptor.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/TransactionInterceptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,54 +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.pvm.internal.svc;
-
-import org.jbpm.pvm.PvmException;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.cmd.Command;
-
-
-/** calls setRollbackOnly on the transaction in the environment
- * in case an exception occurs during execution of the command.
- *
- * @author Tom Baeyens
- */
-public class TransactionInterceptor extends Interceptor {
-
- public <T> T execute(Command<T> command) {
- Environment environment = Environment.getCurrent();
- if (environment==null) {
- throw new PvmException("no environment for verifying authorization");
- }
- Transaction transaction = environment.get(Transaction.class);
- if (transaction==null) {
- throw new PvmException("no transaction in environment");
- }
- try {
- return next.execute(command);
- } catch (RuntimeException e) {
- transaction.setRollbackOnly();
- throw e;
- }
- }
-
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/EnterpriseTransaction.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/EnterpriseTransaction.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/EnterpriseTransaction.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,165 +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.pvm.internal.tx;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
-import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.util.DefaultObservable;
-
-/**
- * @author Alejandro Guizar
- */
-public class EnterpriseTransaction extends DefaultObservable implements Transaction {
-
- private String jndiName;
- private boolean manage;
-
- private UserTransaction transaction;
- private Environment environment;
-
- private static final Log log = Log.getLog(EnterpriseTransaction.class.getName());
-
- public EnterpriseTransaction(String jndiName, boolean manage, Environment environment) {
- this.jndiName = jndiName;
- this.manage = manage;
- if (manage) {
- try {
- getTransaction().begin();
- } catch (NotSupportedException e) {
- throw new TransactionException("transaction already in course", e);
- } catch (SystemException e) {
- throw new TransactionException("begin transaction failed", e);
- }
- }
-
- this.environment = environment;
- }
-
- public void setRollbackOnly() {
- try {
- getTransaction().setRollbackOnly();
- } catch (SystemException e) {
- throw new TransactionException("failed to mark transaction for rollback", e);
- }
- }
-
- public boolean isCommitted() {
- return getStatus() == Status.STATUS_COMMITTED;
- }
-
- public boolean isRollbackOnly() {
- return getStatus() == Status.STATUS_MARKED_ROLLBACK;
- }
-
- public boolean isRolledBack() {
- return getStatus() == Status.STATUS_ROLLEDBACK;
- }
-
- private int getStatus() {
- try {
- return getTransaction().getStatus();
- } catch (SystemException e) {
- throw new TransactionException("failed to retrieve transaction status", e);
- }
- }
-
- public void event(Object source, String eventName, Object info) {
- if (WireContext.EVENT_CLOSE.equals(eventName) && manage) {
- if (getStatus() == Status.STATUS_ACTIVE) {
- commit();
- } else {
- rollback();
- }
- } else if (DefaultEnvironment.EVENT_EXCEPTION.equals(eventName)) {
- setRollbackOnly();
- }
- }
-
- public void commit() {
- fire(EVENT_BEFORECOMPLETION, Status.STATUS_COMMITTING);
- try {
- getTransaction().commit();
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_COMMITTED);
- } catch (RollbackException e) {
- log.error("transaction was rolled back", e);
- environment.setException(e);
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_ROLLEDBACK);
- } catch (HeuristicRollbackException e) {
- log.error("transaction was rolled back", e);
- environment.setException(e);
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_ROLLEDBACK);
- } catch (HeuristicMixedException e) {
- // TODO this should go to a special log for sys admin recovery
- log.error("transaction was partially committed", e);
- environment.setException(e);
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_UNKNOWN);
- } catch (SystemException e) {
- log.error("commit failed", e);
- // TODO rollback() instead?
- environment.setException(e);
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_UNKNOWN);
- }
- }
-
- public void rollback() {
- fire(EVENT_BEFORECOMPLETION, Status.STATUS_ROLLING_BACK);
- try {
- getTransaction().rollback();
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_ROLLEDBACK);
- } catch (SystemException e) {
- log.debug("rollback failed", e);
- environment.setException(e);
- fire(EVENT_AFTERCOMPLETION, Status.STATUS_UNKNOWN);
- }
- }
-
- public String toString() {
- return "EnterpriseTransaction[" + System.identityHashCode(this) + "]";
- }
-
- private UserTransaction getTransaction() {
- if (transaction == null) {
- try {
- Context initial = new InitialContext();
- transaction = (UserTransaction) initial.lookup(jndiName);
- initial.close();
- } catch (NamingException e) {
- throw new TransactionException("failed to retrieve user transaction", e);
- }
- }
- return transaction;
- }
-}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionInterceptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionInterceptor.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionInterceptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,59 @@
+/*
+ * 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.pvm.internal.tx;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.log.Log;
+import org.jbpm.pvm.internal.svc.Interceptor;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HibernateSessionInterceptor extends Interceptor {
+
+ private static final Log log = Log.getLog(HibernateSessionInterceptor.class.getName());
+
+ public <T> T execute(Command<T> command) {
+ Environment environment = Environment.getCurrent();
+ if (environment==null) {
+ throw new PvmException("no environment for managing the hibernate session");
+ }
+
+ log.debug("getting session from environment");
+ Session session = environment.get(Session.class);
+ if (session==null) {
+ throw new PvmException("no session in environment");
+ }
+
+ try {
+ return next.execute(command);
+
+ } finally {
+ log.debug("closing hibernate session");
+ session.close();
+ }
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransaction.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransaction.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransaction.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,86 @@
+/*
+ * 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.pvm.internal.tx;
+
+import javax.transaction.Synchronization;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.log.Log;
+
+/**
+ * @author Tom Baeyens
+ */
+public class HibernateTransaction implements Transaction {
+
+ private static final Log log = Log.getLog(HibernateTransaction.class.getName());
+
+ /* injected */
+ protected Session session;
+
+ /* created */
+ protected org.hibernate.Transaction transaction;
+
+ protected boolean isRollbackOnly;
+
+ public void begin() {
+ log.debug("beginning "+this);
+ transaction = session.beginTransaction();
+ }
+
+ public void complete() {
+ log.trace("completing "+this);
+
+ if (isRollbackOnly) {
+ rollback();
+ } else {
+ commit();
+ }
+ }
+
+ public void commit() {
+ log.debug("committing "+this);
+ transaction.commit();
+ }
+
+ public void rollback() {
+ log.debug("rolling back "+this);
+ transaction.rollback();
+ }
+
+ public void registerSynchronization(Synchronization synchronization) {
+ log.debug("registering synchronization "+synchronization);
+ transaction.registerSynchronization(synchronization);
+ }
+
+ public void setRollbackOnly() {
+ isRollbackOnly = true;
+ }
+
+ public boolean isRollbackOnly() {
+ return isRollbackOnly;
+ }
+
+ public String toString() {
+ return "HibernateTransaction["+System.identityHashCode(this)+"]";
+ }
+}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java (from rev 1788, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/TransactionInterceptor.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,66 @@
+/*
+ * 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.pvm.internal.tx;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.log.Log;
+import org.jbpm.pvm.internal.svc.Interceptor;
+
+
+/** calls setRollbackOnly on the transaction in the environment
+ * in case an exception occurs during execution of the command.
+ *
+ * @author Tom Baeyens
+ */
+public class HibernateTransactionInterceptor extends Interceptor {
+
+ private static final Log log = Log.getLog(HibernateTransactionInterceptor.class.getName());
+
+ public <T> T execute(Command<T> command) {
+ Environment environment = Environment.getCurrent();
+ if (environment==null) {
+ throw new PvmException("no environment for managing hibernate transaction");
+ }
+
+ HibernateTransaction hibernateTransaction = environment.get(HibernateTransaction.class);
+ if (hibernateTransaction==null) {
+ throw new PvmException("no hibernate transaction in environment");
+ }
+
+ hibernateTransaction.begin();
+
+ try {
+ return next.execute(command);
+
+ } catch (RuntimeException e) {
+ hibernateTransaction.setRollbackOnly();
+ throw e;
+
+ } finally {
+ hibernateTransaction.complete();
+ }
+ }
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ LF
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/Resource.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/Resource.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/Resource.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,32 +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.pvm.internal.tx;
-
-/**
- * @author Tom Baeyens
- */
-public interface Resource {
-
- void prepare();
- void commit();
- void rollback();
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransaction.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransaction.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransaction.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,225 +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.pvm.internal.tx;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
-import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.util.DefaultObservable;
-import org.jbpm.pvm.util.Listener;
-
-
-/** simple 2 phase commit transaction.
- * no logging or recovery.
- * non thread safe (which is ok).
- * @author Tom Baeyens
- */
-public class StandardTransaction extends DefaultObservable implements Transaction, Serializable, Listener {
-
- private static final long serialVersionUID = 1L;
- private static Log log = Log.getLog(StandardTransaction.class.getName());
-
- public static final String STATE_ACTIVE = "active";
- public static final String STATE_COMMITTING = "committing";
- public static final String STATE_COMMITTED = "committed";
- public static final String STATE_MARKED_ROLLBACK = "marked-rollback";
- public static final String STATE_ROLLING_BACK = "rolling-back";
- public static final String STATE_ROLLEDBACK = "rolled-back";
-
- // events ///////////////////////////////////////////////////////////////////
-
- protected Environment environment;
- protected List<Resource> resources;
- protected String state = STATE_ACTIVE;
-
- public StandardTransaction() {
- log.debug("starting "+this);
- }
-
- public void setRollbackOnly() {
- if (state==STATE_COMMITTED) {
- throw new TransactionException("transaction was already committed");
- }
- if (state==STATE_ACTIVE) {
- state = STATE_MARKED_ROLLBACK;
- }
- }
-
- public boolean isRollbackOnly() {
- return ( (state==STATE_MARKED_ROLLBACK)
- || (state==STATE_ROLLEDBACK)
- );
- }
-
- public boolean isCommitted() {
- return (state==STATE_COMMITTED);
- }
-
- public boolean isRolledBack() {
- return (state==STATE_ROLLEDBACK);
- }
-
- public void enlistResource(Resource resource) {
- if (resources==null) {
- resources = new ArrayList<Resource>();
- }
- log.trace("enlisting resource "+resource+" to standard transaction");
- resources.add(resource);
- }
-
- /** This transaction will always listen to the close of the block context.
- * If the transaction is still active at that time, it will be committed.
- * If it is marked for rollback it will be rolled back.
- */
- public void event(Object source, String eventName, Object info) {
- if (WireContext.EVENT_CLOSE.equals(eventName)) {
- if (state==STATE_ACTIVE) {
- commit();
- } else {
- rollback();
- }
-
- } else if (DefaultEnvironment.EVENT_EXCEPTION.equals(eventName)) {
- setRollbackOnly();
- }
- }
-
- /** implements simplest two phase commit. */
- public void commit() {
- log.trace("committing");
- event(this, EVENT_BEFORECOMPLETION, STATE_COMMITTING);
-
- if (resources!=null) {
-
- try {
- // prepare //////////////////////////////////////////////////////////////
-
- // the prepare loop will be skipped at the first exception
- for (Resource resource: resources) {
- log.trace("preparing resource "+resource);
- resource.prepare();
- }
-
- // for any exception in the prepare phase, we'll rollback
- } catch (Throwable exception) {
- try {
- log.trace("resource threw exception in prepare. rolling back.");
- rollback();
- } catch (Exception rollbackException) {
- log.error("rollback failed as well", rollbackException);
- }
- environment.setException(exception);
- return;
- }
-
- // commit ///////////////////////////////////////////////////////////////
-
- // The commit loop will try to send the commit to every resource,
- // No matter what it takes. If exceptions come out of resource.commit's
- // they will be suppressed and the first exception will be rethrown after
- // all the resources are commited
- Throwable commitException = null;
- for (Resource resource: resources) {
- try {
- log.trace("committing resource "+resource);
- resource.commit();
-
- // Exceptions in the commit phase will not lead to rollback, since some resources
- // might have committed and can't go back.
- } catch (Throwable t) {
- // TODO this should go to a special log for sys admin recovery
- log.error("commit failed for resource "+resource, t);
- if (commitException==null) {
- commitException = t;
- }
- }
- }
-
- if (commitException!=null) {
- environment.setException(commitException);
- }
- }
-
- state = STATE_COMMITTED;
- log.debug("committed "+this);
- fire(EVENT_AFTERCOMPLETION, STATE_COMMITTED);
- }
-
- public void rollback() {
- rollback(true);
- }
-
- public void rollback(boolean fireBeforeCompletionEvent) {
- log.trace("rolling back");
- if (fireBeforeCompletionEvent) {
- event(this, EVENT_BEFORECOMPLETION, STATE_ROLLING_BACK);
- }
-
- if (state==STATE_COMMITTED) {
- throw new TransactionException("transaction is already committed");
- }
-
- if (state!=STATE_ROLLEDBACK) {
- state = STATE_MARKED_ROLLBACK;
-
- if (resources!=null) {
- for (Resource resource: resources) {
- try {
- log.trace("rolling back resource "+resource);
- resource.rollback();
- } catch (Exception e) {
- log.error("rollback failed for resource "+resource);
- }
- }
- }
-
- state = STATE_ROLLEDBACK;
- log.debug("rolled back");
- fire(EVENT_AFTERCOMPLETION, STATE_ROLLEDBACK);
-
- } else {
- log.trace("transaction is already rolled back. ignoring rollback.");
- }
- }
-
- List<Resource> getResources() {
- return resources;
- }
-
- String getState() {
- return state;
- }
-
- public void setEnvironment(Environment environment) {
- this.environment = environment;
- }
-
- public String toString() {
- return "StandardTransaction["+System.identityHashCode(this)+"]";
- }
-}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -34,14 +34,11 @@
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.env.Transaction;
import org.jbpm.pvm.internal.log.Log;
import org.jbpm.pvm.internal.model.ProcessElementImpl;
-import org.jbpm.pvm.internal.tx.Resource;
import org.jbpm.pvm.internal.util.Closable;
import org.jbpm.pvm.internal.wire.descriptor.AbstractDescriptor;
import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.pvm.internal.wire.operation.EnlistOperation;
import org.jbpm.pvm.internal.wire.operation.FieldOperation;
import org.jbpm.pvm.internal.wire.operation.InvokeOperation;
import org.jbpm.pvm.internal.wire.operation.Operation;
@@ -137,7 +134,6 @@
* <li><b>{@link PropertyOperation}</b>: injects another object with a setter method.</li>
* <li><b>{@link InvokeOperation}</b>: invokes a method.</li>
* <li><b>{@link SubscribeOperation}</b>: subscribes to an {@link Observable observable}.</li>
- * <li><b>{@link EnlistOperation}</b>: enlists this {@link Resource} with the current {@link Transaction}.</li>
* </ul>
*
* <h3>Environment</h3>
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnlistBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnlistBinding.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnlistBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,50 +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.pvm.internal.wire.binding;
-
-import org.jbpm.pvm.internal.wire.operation.EnlistOperation;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
-/** parses a descriptor for creating an {@link EnlistOperation enlist operation}.
- *
- * See schema docs for more details.
- *
- * @author Tom Baeyens
- * @author Guillaume Porcher (documentation)
- */
-public class EnlistBinding extends WireOperationBinding {
-
- public EnlistBinding() {
- super("enlist");
- }
-
- public Object parse(Element element, Parse parse, Parser parser) {
- EnlistOperation enlistOperation = new EnlistOperation();
- if (element.hasAttribute("transaction")) {
- enlistOperation.setTransactionName(element.getAttribute("transaction"));
- }
- return enlistOperation;
- }
-
-}
\ No newline at end of file
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionInterceptorBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionInterceptorBinding.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionInterceptorBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,45 @@
+/*
+ * 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.pvm.internal.wire.binding;
+
+import org.jbpm.pvm.internal.tx.HibernateSessionInterceptor;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HibernateSessionInterceptorBinding extends WireInterceptorBinding {
+
+ public HibernateSessionInterceptorBinding() {
+ super("hibernate-session-interceptor");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ HibernateSessionInterceptor hibernateSessionInterceptor = new HibernateSessionInterceptor();
+ return new ProvidedObjectDescriptor(hibernateSessionInterceptor);
+ }
+
+}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java (from rev 1788, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,49 @@
+/*
+ * 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.pvm.internal.wire.binding;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.tx.HibernateTransaction;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/** parses a descriptor for creating a {@link Transaction}.
+ *
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class HibernateTransactionBinding extends WireDescriptorBinding {
+
+ public HibernateTransactionBinding() {
+ super("hibernate-transaction");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ ObjectDescriptor descriptor = new ObjectDescriptor(HibernateTransaction.class);
+ descriptor.addTypedInjection("session", Session.class);
+ return descriptor;
+ }
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ LF
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java (from rev 1788, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionInterceptorBinding.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,46 @@
+/*
+ * 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.pvm.internal.wire.binding;
+
+import org.jbpm.pvm.internal.tx.HibernateTransactionInterceptor;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/** parses a descriptor for creating a {@link HibernateTransactionInterceptor}.
+ *
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class HibernateTransactionInterceptorBinding extends WireInterceptorBinding {
+
+ public HibernateTransactionInterceptorBinding() {
+ super("hibernate-transaction-interceptor");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ HibernateTransactionInterceptor hibernateTransactionInterceptor = new HibernateTransactionInterceptor();
+ return new ProvidedObjectDescriptor(hibernateTransactionInterceptor);
+ }
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ LF
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,83 +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.pvm.internal.wire.binding;
-
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.util.XmlUtil;
-import org.jbpm.pvm.internal.wire.Descriptor;
-import org.jbpm.pvm.internal.wire.descriptor.EnterpriseTransactionDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.StandardTransactionDescriptor;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
-/** parses a descriptor for creating a {@link Transaction}.
- *
- * See schema docs for more details.
- *
- * @author Tom Baeyens
- */
-public class TransactionBinding extends WireDescriptorBinding {
-
- public TransactionBinding() {
- super("transaction");
- }
-
- public Object parse(Element element, Parse parse, Parser parser) {
- String target = "standard";
-
- if (element.hasAttribute("target")) {
- target = element.getAttribute("target");
- }
-
- Descriptor descriptor = null;
- if ("standard".equalsIgnoreCase(target)) {
- descriptor = new StandardTransactionDescriptor();
-
- } else if ("enterprise".equalsIgnoreCase(target)) {
- EnterpriseTransactionDescriptor enterpriseTransactionDescriptor = new EnterpriseTransactionDescriptor();
-
- if (element.hasAttribute("jndi")) {
- enterpriseTransactionDescriptor.setJndiName(element.getAttribute("jndi"));
- }
-
- Boolean manage = XmlUtil.attributeBoolean(element, "manage", false, parse);
- if (manage!=null) {
- enterpriseTransactionDescriptor.setManage(manage.booleanValue());
- }
-
- descriptor = enterpriseTransactionDescriptor;
-
- } else if ("seam".equalsIgnoreCase(target)) {
- parse.addProblem("seam transaction support is not yet implemented");
-
- } else if ("spring".equalsIgnoreCase(target)) {
- parse.addProblem("spring transaction support is not yet implemented");
-
- } else {
- parse.addProblem("couldn't parse transaction target '"+target+"': must be in {standard, enterprise, seam, spring}. standard is the default.");
-
- }
-
- return descriptor;
- }
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionInterceptorBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionInterceptorBinding.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionInterceptorBinding.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,46 +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.pvm.internal.wire.binding;
-
-import org.jbpm.pvm.internal.svc.TransactionInterceptor;
-import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
-/** parses a descriptor for creating a {@link TransactionInterceptor}.
- *
- * See schema docs for more details.
- *
- * @author Tom Baeyens
- */
-public class TransactionInterceptorBinding extends WireInterceptorBinding {
-
- public TransactionInterceptorBinding() {
- super("transaction-interceptor");
- }
-
- public Object parse(Element element, Parse parse, Parser parser) {
- TransactionInterceptor transactionInterceptor = new TransactionInterceptor();
- return new ProvidedObjectDescriptor(transactionInterceptor);
- }
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnterpriseTransactionDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnterpriseTransactionDescriptor.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnterpriseTransactionDescriptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,61 +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.pvm.internal.wire.descriptor;
-
-
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.internal.tx.EnterpriseTransaction;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.internal.wire.WireDefinition;
-import org.jbpm.pvm.internal.wire.WireException;
-
-/**
- * @author Tom Baeyens
- */
-public class EnterpriseTransactionDescriptor extends AbstractDescriptor {
-
- private static final long serialVersionUID = 1L;
-
- String jndiName = "java:comp/UserTransaction";
- boolean manage;
-
- public Object construct(WireContext wireContext) {
- Environment environment = Environment.getCurrent();
- if (environment==null) {
- throw new WireException("enterprise transaction requires environment");
- }
- EnterpriseTransaction enterpriseTransaction = new EnterpriseTransaction(jndiName, manage, environment);
- wireContext.addListener(enterpriseTransaction);
- return enterpriseTransaction;
- }
-
- public Class<?> getType(WireDefinition wireDefinition) {
- return EnterpriseTransaction.class;
- }
-
- public void setJndiName(String jndiName) {
- this.jndiName = jndiName;
- }
- public void setManage(boolean manage) {
- this.manage = manage;
- }
-}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateSessionDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateSessionDescriptor.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateSessionDescriptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -22,18 +22,15 @@
package org.jbpm.pvm.internal.wire.descriptor;
import java.sql.Connection;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.internal.hibernate.HibernateTransactionResource;
import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireDefinition;
import org.jbpm.pvm.internal.wire.WireException;
-import org.jbpm.pvm.util.Listener;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-
/**
* @author Tom Baeyens
*/
@@ -84,54 +81,11 @@
return session;
}
-
- public void initialize(Object object, WireContext wireContext) {
- Session session = (Session) object;
-
- // if transactions are enabled
- if (tx) {
- log.debug("beginning hibernate transaction");
- org.hibernate.Transaction hibernateTransaction = session.beginTransaction();
-
- // get the standard-transaction
- StandardTransaction standardTransaction = null;
- if (standardTransactionName!=null) {
- standardTransaction = (StandardTransaction) wireContext.get(standardTransactionName);
- } else {
- standardTransaction = wireContext.get(StandardTransaction.class);
- }
- if (standardTransaction==null) {
- throw new WireException("couldn't find standard-transaction "+(standardTransactionName!=null ? "'"+standardTransactionName+"'" : "by type ")+"to enlist the hibernate transaction");
- }
-
- // enlist the hibernate transaction to the global transaction
- HibernateTransactionResource resource = new HibernateTransactionResource(hibernateTransaction, session);
- standardTransaction.enlistResource(resource);
- }
-
- if (close) {
- // make sure that the session is closed when the context closes.
- wireContext.addListener(new SessionCloser(session));
- }
- }
public Class<?> getType(WireDefinition wireDefinition) {
return Session.class;
}
- public static class SessionCloser implements Listener {
- Session session;
- public SessionCloser(Session session) {
- this.session = session;
- }
- public void event(Object source, String eventName, Object info) {
- if (WireContext.EVENT_CLOSE.equals(eventName)) {
- log.debug("closing hibernate session");
- session.close();
- }
- }
- }
-
public void setFactoryName(String factoryName) {
this.factoryName = factoryName;
}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/StandardTransactionDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/StandardTransactionDescriptor.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/StandardTransactionDescriptor.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,51 +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.pvm.internal.wire.descriptor;
-
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.internal.wire.WireDefinition;
-import org.jbpm.pvm.internal.wire.WireException;
-
-/**
- * @author Tom Baeyens
- */
-public class StandardTransactionDescriptor extends AbstractDescriptor {
-
- private static final long serialVersionUID = 1L;
-
- public Object construct(WireContext wireContext) {
- StandardTransaction standardTransaction = new StandardTransaction();
- Environment environment = Environment.getCurrent();
- if (environment==null) {
- throw new WireException("standard transaction requires environment");
- }
- standardTransaction.setEnvironment(environment);
- wireContext.addListener(standardTransaction);
- return standardTransaction;
- }
-
- public Class< ? > getType(WireDefinition wireDefinition) {
- return StandardTransaction.class;
- }
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/operation/EnlistOperation.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/operation/EnlistOperation.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/operation/EnlistOperation.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,74 +0,0 @@
-package org.jbpm.pvm.internal.wire.operation;
-
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.log.Log;
-import org.jbpm.pvm.internal.tx.Resource;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.internal.wire.WireException;
-
-
-/**
- * enlists this {@link Resource} with the current {@link Transaction}.
- *
- * <p>This {@link Operation} specifies that the object on which this operation is applied
- * should be added as a {@link Resource} to the specified {@link Transaction}.
- * </p>
- *
- * <p>property transactionName refers to the objectName of the {@link Transaction}
- * and it may not be null.
- * </p>
- *
- * @author Tom Baeyens
- * @author Guillaume Porcher (documentation)
- */
-public class EnlistOperation implements Operation {
-
- private static final long serialVersionUID = 1L;
- private static Log log = Log.getLog(EnlistOperation.class.getName());
-
- String transactionName = null;
-
- /**
- * @throws WireException if this operation is applied on an object which is not a resource
- * or if the specified transaction cannot be found.
- */
- public void apply(Object target, WireContext wireContext) {
- if (! (target instanceof Resource)) {
- throw new WireException("operation enlist can only be applied on objects that implement "+Resource.class.getName()+": "+target+(target!=null ? " ("+target.getClass().getName()+")" : ""));
- }
-
- Object object = null;
- if (transactionName!=null) {
- object = wireContext.get(transactionName);
- } else {
- object = wireContext.get(Transaction.class);
- }
-
- if ( (object==null)
- || (! (object instanceof StandardTransaction))
- ) {
- throw new WireException("couldn't find "+StandardTransaction.class.getName()+" "+(transactionName!=null ? "'"+transactionName+"'" : "by type")+" to enlist resource "+target);
- }
-
- StandardTransaction standardTransaction = (StandardTransaction) object;
-
- log.trace("enlisting resource "+target+" with transaction");
- standardTransaction.enlistResource((Resource)target);
- }
-
- /**
- * Gets the name of the transaction to which the object should be added.
- */
- public String getTransactionName() {
- return transactionName;
- }
-
- /**
- * Sets the name of the transaction to which the object should be added.
- * @param transactionName
- */
- public void setTransactionName(String transactionName) {
- this.transactionName = transactionName;
- }
-}
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ConfigurationHelper.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ConfigurationHelper.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ConfigurationHelper.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,84 +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.pvm.test.base;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jbpm.pvm.PvmException;
-import org.jbpm.pvm.env.EnvironmentFactory;
-import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.internal.log.Log;
-
-
-/** utility to help tests with managing configuration resources.
- *
- * @author Tom Baeyens
- */
-public class ConfigurationHelper {
-
- private static final Log log = Log.getLog(ConfigurationHelper.class.getName());
-
- static Map<String, EnvironmentFactory> environmentFactories = new HashMap<String, EnvironmentFactory>();
-
- public EnvironmentFactory getEnvironmentFactory() {
- return getEnvironmentFactory(getClass().getPackage());
- }
-
- static EnvironmentFactory getEnvironmentFactory(Package testPackage) {
- String packageName = testPackage.getName();
- if (! environmentFactories.containsKey(packageName)) {
- createEnvironmentFactory(testPackage);
- }
- return environmentFactories.get(packageName);
- }
-
- static EnvironmentFactory createEnvironmentFactory(Package testPackage) {
- String packageName = testPackage.getName();
- try {
- String resourceName = getConfigurationResourceName(packageName);
- log.debug("creating environment factory for package ["+packageName+"]");
- EnvironmentFactory environmentFactory = new PvmEnvironmentFactory(resourceName);
- environmentFactories.put(packageName, environmentFactory);
- return environmentFactory;
- } catch (Exception e) {
- throw new PvmException("Exception during creation of environment factory for package "+packageName, e);
- }
- }
-
- static String getConfigurationResourceName(String packageName) {
- return packageName.replace('.','/')+"/environment.cfg.xml";
- }
-
- static void setUpPackage(Package testPackage) {
- createEnvironmentFactory(testPackage);
- }
-
- static void tearDownPackage(Package testPackage) {
- String packageName = testPackage.getName();
- EnvironmentFactory environmentFactory = environmentFactories.remove(packageName);
- if (environmentFactory!=null) {
- log.debug("closing environment factory for package ["+packageName+"]");
- environmentFactory.close();
- }
- }
-}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,127 @@
+/*
+ * 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.pvm.test.base;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.MySQLDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.mapping.ForeignKey;
+import org.hibernate.mapping.Table;
+import org.jbpm.pvm.env.Context;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.EnvironmentFactory;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class Db {
+
+ private static final String CLEAN_SQL_KEY = "cleanSql";
+
+ public static void clean(EnvironmentFactory environmentFactory) {
+ Environment environment = environmentFactory.openEnvironment();
+ try {
+ SessionFactory sessionFactory = environment.get(SessionFactory.class);
+ String[] cleanSql = (String[]) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY).get(CLEAN_SQL_KEY);
+
+ if (cleanSql == null) {
+ Configuration configuration = environment.get(Configuration.class);
+
+ SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+ Dialect dialect = sessionFactoryImplementor.getDialect();
+
+ // loop over all foreign key constraints
+ List<String> dropForeignKeysSql = new ArrayList<String>();
+ List<String> createForeignKeysSql = new ArrayList<String>();
+ Iterator<Table> iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ String catalog = table.getCatalog();
+ String schema = table.getSchema();
+ Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
+ while (subIter.hasNext()) {
+ ForeignKey fk = (ForeignKey) subIter.next();
+ if (fk.isPhysicalConstraint()) {
+ // collect the drop foreign key constraint sql
+ dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
+ // MySQLDialect creates an index for each foreign key.
+ // see
+ // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
+ // This index should be dropped or an error will be thrown during
+ // the creation phase
+ if (dialect instanceof MySQLDialect) {
+ dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
+ }
+ // and collect the create foreign key constraint sql
+ createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
+ }
+ }
+ }
+ }
+
+ List<String> deleteSql = new ArrayList<String>();
+ iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ deleteSql.add("delete from " + table.getName());
+ }
+ }
+
+ // glue
+ // - drop foreign key constraints
+ // - delete contents of all tables
+ // - create foreign key constraints
+ // together to form the clean script
+ List<String> cleanSqlList = new ArrayList<String>();
+ cleanSqlList.addAll(dropForeignKeysSql);
+ cleanSqlList.addAll(deleteSql);
+ cleanSqlList.addAll(createForeignKeysSql);
+
+ cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
+
+ environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY).set(CLEAN_SQL_KEY, cleanSql);
+ }
+
+ Session session = sessionFactory.openSession();
+ try {
+ for (String query : cleanSql) {
+ session.createSQLQuery(query).executeUpdate();
+ }
+ } finally {
+ session.close();
+ }
+ } finally {
+ environment.close();
+ }
+ }
+
+}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/DbTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/DbTestCase.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/DbTestCase.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,193 +21,44 @@
*/
package org.jbpm.pvm.test.base;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.mapping.ForeignKey;
-import org.hibernate.mapping.Table;
-import org.jbpm.pvm.test.base.EnvironmentTestCase;
-import org.jbpm.pvm.Execution;
-import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.ExecutionService;
+import org.jbpm.pvm.ManagementService;
+import org.jbpm.pvm.ProcessService;
import org.jbpm.pvm.env.EnvironmentFactory;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
-import org.jbpm.pvm.internal.util.ReflectUtil;
-import org.jbpm.pvm.model.ProcessDefinition;
-import org.jbpm.pvm.session.DbSession;
-import org.jbpm.pvm.session.PvmDbSession;
+import org.jbpm.pvm.internal.cmd.CommandService;
-/**
+
+/** for tests that use persistence through a command service.
+ *
+ * The DB is cleaned inbetween tests. No environment is created.
+ *
* @author Tom Baeyens
*/
-public abstract class DbTestCase extends EnvironmentTestCase
-{
-
- private static final String CLEAN_SQL_KEY = "cleanSql";
-
- @Override
- public void setUp() throws Exception {
- if (isSamePackage()) {
- cleanDb(getEnvironmentFactory());
- }
- super.setUp();
- }
+public abstract class DbTestCase extends EnvironmentFactoryTestCase {
- public DbSession getDbSession() {
- return environment.get(DbSession.class);
- }
-
- public void rollbackAndBeginNewTransaction() {
- Transaction transaction = environment.get(Transaction.class);
- transaction.setRollbackOnly();
- environment.close();
- environment = null;
- }
-
- public void newTransaction() {
- try {
- environment.close();
- } finally {
- log.debug("### new transaction ###################################################");
- environment = getEnvironmentFactory().openEnvironment();
- }
- }
-
- public void beginCacheTest() {
- SessionFactory sessionFactory = environment.get(SessionFactory.class);
- if (sessionFactory != null) {
- log.debug("=================================================================");
- log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test");
- log.debug("=================================================================");
+ protected CommandService commandService;
+ protected ProcessService processService;
+ protected ExecutionService executionService;
+ protected ManagementService managementService;
- sessionFactory.getStatistics().clear();
- sessionFactory.getStatistics().setStatisticsEnabled(true);
- }
+ public DbTestCase() {
+ super();
}
- public void endCacheTest() {
- SessionFactory sessionFactory = environment.get(SessionFactory.class);
- if (sessionFactory != null) {
- assertEquals(0, sessionFactory.getStatistics().getEntityLoadCount());
- assertEquals(0, sessionFactory.getStatistics().getCollectionLoadCount());
- }
+ public DbTestCase(String configResource) {
+ super(configResource);
}
- public ProcessDefinitionImpl reload(ProcessDefinition processDefinition) {
- environment.get(PvmDbSession.class).save(processDefinition);
- newTransaction();
- return environment.get(PvmDbSession.class).get(ProcessDefinitionImpl.class, processDefinition.getDbid());
- }
+ public void setUp() throws Exception {
+ super.setUp();
- public <T> T reload(T object, Class<T> persistentClass) {
- environment.get(DbSession.class).save(object);
- newTransaction();
-
- Long dbid = null;
- try {
- Field dbidField = ReflectUtil.getField(persistentClass, "dbid");
- dbidField.setAccessible(true);
- dbid = (Long) dbidField.get(object);
- } catch (Exception e) {
- e.printStackTrace();
+ if (isEnvironmentFactoryCached()) {
+ Db.clean(getEnvironmentFactory());
}
-
- return environment.get(DbSession.class).get(persistentClass, dbid);
- }
- public ExecutionImpl reload(Execution execution) {
- environment.get(PvmDbSession.class).save(execution);
- newTransaction();
- return environment.get(PvmDbSession.class).get(ExecutionImpl.class, execution.getDbid());
+ commandService = getEnvironmentFactory().get(CommandService.class);
+ processService = getEnvironmentFactory().get(ProcessService.class);
+ executionService = getEnvironmentFactory().get(ExecutionService.class);
+ managementService = getEnvironmentFactory().get(ManagementService.class);
}
-
- public static void cleanDb(EnvironmentFactory environmentFactory) {
-
- Environment environment = environmentFactory.openEnvironment();
- try {
- SessionFactory sessionFactory = environment.get(SessionFactory.class);
- String[] cleanSql = (String[]) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY).get(CLEAN_SQL_KEY);
-
- if (cleanSql == null) {
- Configuration configuration = environment.get(Configuration.class);
-
- SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
- Dialect dialect = sessionFactoryImplementor.getDialect();
-
- // loop over all foreign key constraints
- List<String> dropForeignKeysSql = new ArrayList<String>();
- List<String> createForeignKeysSql = new ArrayList<String>();
- Iterator<Table> iter = configuration.getTableMappings();
- while (iter.hasNext()) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- String catalog = table.getCatalog();
- String schema = table.getSchema();
- Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
- while (subIter.hasNext()) {
- ForeignKey fk = (ForeignKey) subIter.next();
- if (fk.isPhysicalConstraint()) {
- // collect the drop foreign key constraint sql
- dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
- // MySQLDialect creates an index for each foreign key.
- // see
- // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
- // This index should be dropped or an error will be thrown during
- // the creation phase
- if (dialect instanceof MySQLDialect) {
- dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
- }
- // and collect the create foreign key constraint sql
- createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
- }
- }
- }
- }
-
- List<String> deleteSql = new ArrayList<String>();
- iter = configuration.getTableMappings();
- while (iter.hasNext()) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- deleteSql.add("delete from " + table.getName());
- }
- }
-
- // glue
- // - drop foreign key constraints
- // - delete contents of all tables
- // - create foreign key constraints
- // together to form the clean script
- List<String> cleanSqlList = new ArrayList<String>();
- cleanSqlList.addAll(dropForeignKeysSql);
- cleanSqlList.addAll(deleteSql);
- cleanSqlList.addAll(createForeignKeysSql);
-
- cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
-
- environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY).set(CLEAN_SQL_KEY, cleanSql);
- }
-
- Session session = sessionFactory.openSession();
- try {
- for (String query : cleanSql) {
- session.createSQLQuery(query).executeUpdate();
- }
- } finally {
- session.close();
- }
- } finally {
- environment.close();
- }
- }
}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentDbTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentDbTestCase.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentDbTestCase.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,122 @@
+/*
+ * 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.pvm.test.base;
+
+import java.lang.reflect.Field;
+
+import org.hibernate.SessionFactory;
+import org.jbpm.pvm.Execution;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.pvm.model.ProcessDefinition;
+import org.jbpm.pvm.session.DbSession;
+import org.jbpm.pvm.session.PvmDbSession;
+
+
+/** for tests that use persistence inside environment blocks.
+ *
+ * An environment is opened in the setUp and closed in the tearDown.
+ * DB is cleaned inbetween tests. Extra convenience methods for usage
+ * inside an environment block are provided.
+ *
+ * @author Tom Baeyens
+ */
+public class EnvironmentDbTestCase extends EnvironmentTestCase {
+
+ public void setUp() throws Exception {
+ if (isEnvironmentFactoryCached()) {
+ Db.clean(getEnvironmentFactory());
+ }
+ super.setUp();
+ }
+
+ public DbSession getDbSession() {
+ return environment.get(DbSession.class);
+ }
+
+ public void rollbackAndBeginNewTransaction() {
+ Transaction transaction = environment.get(Transaction.class);
+ transaction.setRollbackOnly();
+ environment.close();
+ environment = null;
+ }
+
+ public void newTransaction() {
+ try {
+ environment.close();
+ } finally {
+ log.debug("### new transaction ###################################################");
+ environment = getEnvironmentFactory().openEnvironment();
+ }
+ }
+
+ public void beginCacheTest() {
+ SessionFactory sessionFactory = environment.get(SessionFactory.class);
+ if (sessionFactory != null) {
+ log.debug("=================================================================");
+ log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test");
+ log.debug("=================================================================");
+
+ sessionFactory.getStatistics().clear();
+ sessionFactory.getStatistics().setStatisticsEnabled(true);
+ }
+ }
+
+ public void endCacheTest() {
+ SessionFactory sessionFactory = environment.get(SessionFactory.class);
+ if (sessionFactory != null) {
+ assertEquals(0, sessionFactory.getStatistics().getEntityLoadCount());
+ assertEquals(0, sessionFactory.getStatistics().getCollectionLoadCount());
+ }
+ }
+
+ public ProcessDefinitionImpl reload(ProcessDefinition processDefinition) {
+ environment.get(PvmDbSession.class).save(processDefinition);
+ newTransaction();
+ return environment.get(PvmDbSession.class).get(ProcessDefinitionImpl.class, processDefinition.getDbid());
+ }
+
+ public <T> T reload(T object, Class<T> persistentClass) {
+ environment.get(DbSession.class).save(object);
+ newTransaction();
+
+ Long dbid = null;
+ try {
+ Field dbidField = ReflectUtil.getField(persistentClass, "dbid");
+ dbidField.setAccessible(true);
+ dbid = (Long) dbidField.get(object);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return environment.get(DbSession.class).get(persistentClass, dbid);
+ }
+
+ public ExecutionImpl reload(Execution execution) {
+ environment.get(PvmDbSession.class).save(execution);
+ newTransaction();
+ return environment.get(PvmDbSession.class).get(ExecutionImpl.class, execution.getDbid());
+ }
+
+}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentFactoryTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentFactoryTestCase.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentFactoryTestCase.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,7 +21,12 @@
*/
package org.jbpm.pvm.test.base;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.pvm.PvmException;
import org.jbpm.pvm.env.EnvironmentFactory;
+import org.jbpm.pvm.env.PvmEnvironmentFactory;
/**
@@ -29,19 +34,57 @@
*/
public abstract class EnvironmentFactoryTestCase extends JbpmTestCase {
- static Package lastPackage = null;
+ String configResource;
+
+ static Map<String, EnvironmentFactory> environmentFactories = new HashMap<String, EnvironmentFactory>();
+ public EnvironmentFactoryTestCase() {
+ this("environment.cfg.xml");
+ }
+
+ public EnvironmentFactoryTestCase(String configResource) {
+ this.configResource = configResource;
+ }
+
public EnvironmentFactory getEnvironmentFactory() {
- Package testPackage = this.getClass().getPackage();
- if (lastPackage != null && lastPackage != testPackage) {
- ConfigurationHelper.tearDownPackage(lastPackage);
+ if (isEnvironmentFactoryCached()) {
+ return environmentFactories.get(configResource);
}
- lastPackage = testPackage;
- return ConfigurationHelper.getEnvironmentFactory(testPackage);
+ return createEnvironmentFactory();
}
+
+ boolean isEnvironmentFactoryCached() {
+ return environmentFactories.containsKey(configResource);
+ }
+
+ EnvironmentFactory createEnvironmentFactory() {
+ try {
+ log.debug("creating environment factory for ["+configResource+"]");
+ EnvironmentFactory newEnvironmentFactory = new PvmEnvironmentFactory(configResource);
+ environmentFactories.put(configResource, newEnvironmentFactory);
+ return newEnvironmentFactory;
+ } catch (Exception e) {
+ throw new PvmException("Exception during creation of environment factory for "+configResource, e);
+ }
+ }
+
+ /*
+ static String getConfigResource(Package p) {
+ return p.getName().replace('.','/')+"/environment.cfg.xml";
+ }
- public boolean isSamePackage() {
- Package testPackage = this.getClass().getPackage();
- return lastPackage == testPackage;
+ static void setUpPackage(Package testPackage) {
+ String packageName = testPackage.getName();
+ createEnvironmentFactory(testPackage);
}
+
+ static void tearDownPackage(Package testPackage) {
+ String packageName = testPackage.getName();
+ EnvironmentFactory environmentFactory = environmentFactories.remove(packageName);
+ if (environmentFactory!=null) {
+ log.debug("closing environment factory for package ["+packageName+"]");
+ environmentFactory.close();
+ }
+ }
+ */
}
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentTestCase.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/EnvironmentTestCase.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -30,6 +30,13 @@
protected Environment environment;
+ public EnvironmentTestCase() {
+ }
+
+ public EnvironmentTestCase(String configResource) {
+ super(configResource);
+ }
+
public void setUp() throws Exception {
super.setUp();
environment = getEnvironmentFactory().openEnvironment();
Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ServiceTestCase.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ServiceTestCase.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/ServiceTestCase.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -1,37 +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.pvm.test.base;
-
-import org.jbpm.pvm.test.base.EnvironmentFactoryTestCase;
-
-
-/**
- * @author Tom Baeyens
- */
-public abstract class ServiceTestCase extends EnvironmentFactoryTestCase
-{
-
- public void tearDown() throws Exception {
- super.tearDown();
- DbTestCase.cleanDb(getEnvironmentFactory());
- }
-}
Modified: jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml 2008-08-05 07:28:14 UTC (rev 1820)
@@ -31,7 +31,7 @@
<binding class="org.jbpm.pvm.internal.wire.binding.ContextRefBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.TransactionRefBinding" />
<!-- various specials -->
- <binding class="org.jbpm.pvm.internal.wire.binding.TransactionBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.HibernateTransactionBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.JobExecutorBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.JobTestHelperBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.ScriptManagerBinding" />
@@ -67,7 +67,8 @@
<binding class="org.jbpm.pvm.internal.wire.binding.EnvironmentInterceptorBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.AuthorizationInterceptorBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.RetryInterceptorBinding" />
- <binding class="org.jbpm.pvm.internal.wire.binding.TransactionInterceptorBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.HibernateTransactionInterceptorBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.HibernateSessionInterceptorBinding" />
<!-- ########################## -->
<!-- ### Operation bindings ### -->
@@ -76,6 +77,5 @@
<binding class="org.jbpm.pvm.internal.wire.binding.FieldBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.InvokeBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.SubscribeBinding" />
- <binding class="org.jbpm.pvm.internal.wire.binding.EnlistBinding" />
</wire-bindings>
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -26,19 +26,19 @@
import java.util.List;
import java.util.Map;
-import org.jbpm.pvm.test.base.ServiceTestCase;
+import org.jbpm.pvm.Deployment;
import org.jbpm.pvm.Execution;
-import org.jbpm.pvm.Deployment;
import org.jbpm.pvm.ExecutionService;
import org.jbpm.pvm.ProcessService;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.model.ProcessDefinition;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
/**
* @author Tom Baeyens
*/
-public class ExecutionServiceTest extends ServiceTestCase {
+public class ExecutionServiceTest extends EnvironmentDbTestCase {
public void testStartExecutionByName() {
ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ManagementServiceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ManagementServiceTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ManagementServiceTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,15 +21,14 @@
*/
package org.jbpm.pvm.api.db.svc;
-import org.jbpm.pvm.test.base.ServiceTestCase;
import org.jbpm.pvm.ManagementService;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
/**
* @author Tom Baeyens
*/
-public class ManagementServiceTest extends ServiceTestCase
-{
+public class ManagementServiceTest extends EnvironmentDbTestCase {
public void testGetJobs() {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -24,17 +24,17 @@
import java.util.ArrayList;
import java.util.List;
-import org.jbpm.pvm.test.base.ServiceTestCase;
import org.jbpm.pvm.Deployment;
+import org.jbpm.pvm.ProcessService;
import org.jbpm.pvm.PvmException;
-import org.jbpm.pvm.ProcessService;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.model.ProcessDefinition;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
/**
* @author Tom Baeyens
*/
-public class ProcessServiceTest extends ServiceTestCase {
+public class ProcessServiceTest extends EnvironmentDbTestCase {
public void testDuplicateDeployment() {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/BasicEnvironmentTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/BasicEnvironmentTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/BasicEnvironmentTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -26,7 +26,6 @@
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
/**
* @author Tom Baeyens
@@ -138,9 +137,9 @@
Environment environment = environmentFactory.openEnvironment();
try {
- Context environmentFactoryCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY);
+ Context environmentFactoryCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
assertNotNull(environmentFactoryCtxt);
- Context environmentCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ Context environmentCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environmentCtxt);
} finally {
@@ -160,9 +159,9 @@
Environment environment = environmentFactory.openEnvironment();
try {
assertNotNull(environment);
- Context environmentFactoryCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY);
+ Context environmentFactoryCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
assertNotNull(environmentFactoryCtxt);
- Context environmentCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ Context environmentCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environmentCtxt);
} finally {
@@ -180,9 +179,9 @@
Environment environment = environmentFactory.openEnvironment();
try {
assertNotNull(environment);
- Context environmentFactoryCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT_FACTORY);
+ Context environmentFactoryCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
assertNotNull(environmentFactoryCtxt);
- Context environmentCtxt = environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ Context environmentCtxt = environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environmentCtxt);
} finally {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -35,12 +35,12 @@
import org.jbpm.pvm.samples.activities.AutomaticActivity;
import org.jbpm.pvm.session.DbSession;
import org.jbpm.pvm.session.PvmDbSession;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
/**
* @author Pascal Verdage
*/
-public class TimerIntegrationTest extends DbTestCase {
+public class TimerIntegrationTest extends EnvironmentDbTestCase {
public static class WaitState implements ExternalActivity {
private static final long serialVersionUID = 1L;
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/langext/LanguageExtensionsDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/langext/LanguageExtensionsDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/langext/LanguageExtensionsDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -24,7 +24,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.Execution;
import org.jbpm.pvm.model.ProcessDefinition;
import org.jbpm.pvm.model.ProcessFactory;
@@ -35,7 +35,7 @@
/**
* @author Tom Baeyens
*/
-public class LanguageExtensionsDbTest extends DbTestCase
+public class LanguageExtensionsDbTest extends EnvironmentDbTestCase
{
/**
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -24,7 +24,7 @@
import java.util.Date;
import java.util.List;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.internal.model.CommentImpl;
import org.jbpm.pvm.model.Comment;
import org.jbpm.pvm.session.DbSession;
@@ -32,7 +32,7 @@
/**
* @author Tom Baeyens
*/
-public class CommentDbTest extends DbTestCase {
+public class CommentDbTest extends EnvironmentDbTestCase {
public void testComment() {
Date now = new Date();
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -16,7 +16,7 @@
import java.util.List;
import org.hibernate.Session;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.client.ClientProcessDefinition;
import org.jbpm.pvm.internal.model.NodeImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
@@ -31,7 +31,7 @@
* @author Guillaume Porcher
*
*/
-public class ProcessCacheDbTest extends DbTestCase
+public class ProcessCacheDbTest extends EnvironmentDbTestCase
{
/**
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -16,7 +16,7 @@
import java.util.Date;
import java.util.List;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.internal.model.EventImpl;
import org.jbpm.pvm.internal.model.EventListenerReference;
import org.jbpm.pvm.internal.model.ExceptionHandlerImpl;
@@ -32,7 +32,7 @@
* @author Charles Souillard
* @author Guillaume Porcher
*/
-public class ProcessDefinitionDbTest extends DbTestCase
+public class ProcessDefinitionDbTest extends EnvironmentDbTestCase
{
public void testProcessDefinitionBasicProperties() {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessExecutionDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessExecutionDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/ProcessExecutionDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -13,7 +13,7 @@
**/
package org.jbpm.pvm.internal.db.model;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.model.ProcessDefinition;
@@ -22,7 +22,7 @@
* @author Guillaume Porcher
*
*/
-public class ProcessExecutionDbTest extends DbTestCase {
+public class ProcessExecutionDbTest extends EnvironmentDbTestCase {
public void testExecutionProperties() {
ProcessDefinition processDefinition = new ProcessDefinitionImpl();
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -22,13 +22,13 @@
package org.jbpm.pvm.internal.db.model;
import org.hibernate.SessionFactory;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
/**
* @author Tom Baeyens
*/
-public class SessionFactoryDbTest extends DbTestCase
+public class SessionFactoryDbTest extends EnvironmentDbTestCase
{
public void testSessionFactory() {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -21,7 +21,7 @@
import java.util.TreeMap;
import java.util.TreeSet;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.internal.model.EventImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.model.VariableDefinitionImpl;
@@ -58,7 +58,7 @@
*
* This class uses process annotations to test wire descriptors persistence
*/
-public class WireDbTest extends DbTestCase {
+public class WireDbTest extends EnvironmentDbTestCase {
public void testCharacterDescriptor() {
DbSession dbSession = environment.get(DbSession.class);
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -22,7 +22,7 @@
package org.jbpm.pvm.internal.db.model;
import org.hibernate.Session;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
@@ -32,7 +32,7 @@
/**
* @author Tom Baeyens
*/
-public class WireTest extends DbTestCase {
+public class WireTest extends EnvironmentDbTestCase {
public void testObjectDescriptor() {
DbSession persistenceSession = (DbSession) environment.get(DbSession.class);
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/BasicTransactionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/BasicTransactionTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/BasicTransactionTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,83 @@
+/*
+ * 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.pvm.internal.db.tx;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.pvm.test.base.DbTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class BasicTransactionTest extends DbTestCase {
+
+ public void testCommit() {
+ commandService.execute(new Command<Object>(){
+ public Object execute(Environment environment) {
+ Session session = environment.get(Session.class);
+ session.save(new CommentImpl("if i only had the time to write code"));
+ return null;
+ }
+ });
+
+ commandService.execute(new Command<Object>(){
+ public Object execute(Environment environment) {
+ Session session = environment.get(Session.class);
+ List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+ assertEquals("if i only had the time to write code", comments.get(0).getMessage());
+ return null;
+ }
+ });
+ }
+
+
+ public static class MyOwnException extends RuntimeException {
+ }
+
+ public void testRollback() {
+ try {
+ commandService.execute(new Command<Object>(){
+ public Object execute(Environment environment) {
+ Session session = environment.get(Session.class);
+ session.save(new CommentImpl("if i only had the time to write code"));
+ throw new MyOwnException();
+ }
+ });
+ fail("expected exception");
+ } catch (MyOwnException e) {
+ // OK
+ }
+
+ commandService.execute(new Command<Object>(){
+ public Object execute(Environment environment) {
+ Session session = environment.get(Session.class);
+ List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+ assertEquals(0, comments.size());
+ return null;
+ }
+ });
+ }
+}
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -49,6 +49,10 @@
public class JobExecutorTest extends EnvironmentFactoryTestCase {
private static final Log log = Log.getLog(JobExecutorTest.class.getName());
+
+ public JobExecutorTest() {
+ super("org/jbpm/pvm/internal/jobexecutor/environment.cfg.xml");
+ }
/**
* test the case where the jobExecutor is start and shortly after stopped.
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSessionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSessionTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSessionTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -18,7 +18,7 @@
import java.util.Map;
import java.util.Map.Entry;
-import org.jbpm.pvm.test.base.DbTestCase;
+import org.jbpm.pvm.test.base.EnvironmentDbTestCase;
import org.jbpm.pvm.PvmException;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.internal.job.JobImpl;
@@ -34,7 +34,7 @@
/**
* @author Pascal Verdage
*/
-public class JobExecutorTimerSessionTest extends DbTestCase
+public class JobExecutorTimerSessionTest extends EnvironmentDbTestCase
{
public void setUp() throws Exception {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -45,8 +45,12 @@
/**
* @author Tom Baeyens
*/
-public class VariableAutoTypeResolutionTest extends EnvironmentTestCase
-{
+public class VariableAutoTypeResolutionTest extends EnvironmentTestCase {
+
+ public VariableAutoTypeResolutionTest() {
+ super("org/jbpm/pvm/internal/type/environment.cfg.xml");
+ }
+
public static class WaitState implements ExternalActivity {
private static final long serialVersionUID = 1L;
public void execute(ActivityExecution execution) {
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -22,10 +22,10 @@
package org.jbpm.pvm.internal.wire;
+import org.jbpm.pvm.env.Context;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireDefinition;
@@ -89,7 +89,7 @@
Environment environment = environmentFactory.openEnvironment();
try {
- WireContext contextBlockContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext contextBlockContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environment.get("recorder"));
// The recorder object will be subscribed to the environment WireScope
@@ -216,7 +216,7 @@
try {
assertEquals(events.toString(), 0, events.size());
- WireContext contextBlockContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext contextBlockContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
contextBlockContext.fire("interestingevent", null);
assertEquals(events.toString(), 1, events.size());
@@ -250,7 +250,7 @@
Environment environment = environmentFactory.openEnvironment();
try {
- WireContext contextBlockContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext contextBlockContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertEquals(events.toString(), 2, events.size());
int index=0;
@@ -461,7 +461,7 @@
Environment environment = environmentFactory.openEnvironment();
try {
- WireContext contextBlockContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext contextBlockContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environment.get("a"));
// The recorder object will be subscribed to the environment WireContext
@@ -524,7 +524,7 @@
Environment environment = environmentFactory.openEnvironment();
try {
- WireContext contextBlockContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext contextBlockContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
assertNotNull(environment.get("a"));
// The recorder object will be subscribed to the environment WireContext
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireObservableTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireObservableTest.java 2008-08-04 13:08:47 UTC (rev 1819)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireObservableTest.java 2008-08-05 07:28:14 UTC (rev 1820)
@@ -25,10 +25,10 @@
import org.jbpm.pvm.test.base.JbpmTestCase;
import org.jbpm.pvm.util.Listener;
+import org.jbpm.pvm.env.Context;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
import org.jbpm.pvm.env.PvmEnvironmentFactory;
-import org.jbpm.pvm.internal.env.DefaultEnvironment;
import org.jbpm.pvm.internal.wire.WireContext;
/**
@@ -59,7 +59,7 @@
Environment environment = environmentFactory.openEnvironment();
try {
- WireContext environmentContext = (WireContext) environment.getContext(DefaultEnvironment.CONTEXTNAME_ENVIRONMENT);
+ WireContext environmentContext = (WireContext) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT);
// this test also checks non-eager-initialized subscription
// subscription should only be done when the object is created the first time
Added: jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml 2008-08-05 07:28:14 UTC (rev 1820)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<contexts xmlns="http://jbpm.org/pvm/1.0/wire">
+
+ <environment-factory>
+
+ <deployer-manager resource="pvm.language.deployers.xml">
+ <language name="api">
+ <verify-version />
+ <save-process />
+ </language>
+ </deployer-manager>
+
+ <process-service />
+ <execution-service />
+ <management-service />
+
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <hibernate-session-interceptor />
+ <hibernate-transaction-interceptor />
+ </command-service>
+
+ <hibernate-configuration>
+ <properties resource="hibernate.properties" />
+ <mappings resource="org/jbpm/pvm/pvm.hibernate.mappings.xml" />
+ <cache-configuration resource="org/jbpm/pvm/pvm.cache.xml" usage="nonstrict-read-write" />
+ </hibernate-configuration>
+
+ <hibernate-session-factory />
+
+ <variable-types resource="org/jbpm/pvm/pvm.types.xml" />
+
+ </environment-factory>
+
+ <environment>
+ <hibernate-session />
+ <hibernate-transaction />
+ <pvm-db-session />
+ </environment>
+
+</contexts>
More information about the jbpm-commits
mailing list