[jbpm-commits] JBoss JBPM SVN: r1856 - in jbpm4/pvm/trunk/modules/core/src: main/java/org/jbpm/pvm/internal/tx and 9 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Aug 8 12:04:28 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-08-08 12:04:28 -0400 (Fri, 08 Aug 2008)
New Revision: 1856
Added:
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionResource.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardResource.java
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardSynchronization.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/tx/StandardTransactionInterceptor.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/StandardTransactionInterceptorBinding.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/operation/EnlistOperation.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TestResource.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java
Removed:
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
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/wire/descriptor/HibernateSessionDescriptor.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/internal/jobexecutor/JobExecutorTest.java
jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml
Log:
reintroduced standard transaction: JBPM-1458
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-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -63,6 +63,7 @@
try {
log.debug("executing job "+job+"...");
job.execute(environment);
+ log.debug("executed job "+job);
// if this job is locked too long, it could be unlocked by the lockmonitor and
// executed by another thread.
@@ -79,8 +80,7 @@
log.error("exception while executing '"+job+"'", exception);
handleJobExecutionException(environment, job, exception);
}
-
- log.debug("executed job "+job);
+
} else {
log.debug("job " + jobDbid + " no longer exists");
}
Deleted: 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 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionInterceptor.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -1,59 +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 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();
- }
- }
-}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionResource.java (from rev 1850, 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/HibernateSessionResource.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionResource.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,79 @@
+/*
+ * 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.internal.log.Log;
+
+/**
+ * @author Tom Baeyens
+ */
+public class HibernateSessionResource implements StandardResource {
+
+ private static final Log log = Log.getLog(HibernateSessionResource.class.getName());
+
+ protected Session session;
+ protected org.hibernate.Transaction transaction;
+
+ public HibernateSessionResource(Session session) {
+ this.session = session;
+ if (log.isTraceEnabled()) log.trace("beginning transaction on hibernate session "+System.identityHashCode(session));
+
+ try {
+ this.transaction = session.beginTransaction();
+ } catch (RuntimeException e) {
+ log.error("hibernate transaction begin failed. closing hibernate session", e);
+ session.close();
+ throw e;
+ }
+
+ log.debug("begun hibernate transaction "+System.identityHashCode(transaction)+" on hibernate session "+System.identityHashCode(session));
+ }
+
+ public void prepare() {
+ log.debug("flushing hibernate session "+System.identityHashCode(session));
+ session.flush();
+ }
+
+ public void commit() {
+ log.debug("committing hibernate transaction "+System.identityHashCode(transaction));
+ try {
+ transaction.commit();
+ } finally {
+ closeSession();
+ }
+ }
+
+ private void closeSession() {
+ log.debug("closing hibernate session "+System.identityHashCode(session));
+ session.close();
+ }
+
+ public void rollback() {
+ log.debug("rolling back hibernate transaction "+System.identityHashCode(transaction));
+ try {
+ transaction.rollback();
+ } finally {
+ closeSession();
+ }
+ }
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateSessionResource.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransaction.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -1,86 +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.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)+"]";
- }
-}
Deleted: 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/tx/HibernateTransactionInterceptor.java 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/HibernateTransactionInterceptor.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -1,66 +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 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();
- }
- }
-}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardResource.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardResource.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardResource.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,36 @@
+/*
+ * 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 StandardResource {
+
+ void prepare();
+
+ void commit();
+
+ void rollback();
+
+}
Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardSynchronization.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardSynchronization.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardSynchronization.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,54 @@
+/*
+ * 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.Status;
+import javax.transaction.Synchronization;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class StandardSynchronization {
+
+ Synchronization synchronization;
+
+ public StandardSynchronization(Synchronization synchronization) {
+ this.synchronization = synchronization;
+ }
+
+ public void afterCompletion(StandardTransaction.State transactionState) {
+ if (transactionState==StandardTransaction.State.COMMITTED) {
+ synchronization.afterCompletion(Status.STATUS_COMMITTED);
+
+ } else if (transactionState==StandardTransaction.State.ROLLEDBACK) {
+ synchronization.afterCompletion(Status.STATUS_ROLLEDBACK);
+
+ } else {
+ throw new TransactionException("invalid transaction state: "+transactionState);
+ }
+ }
+
+ public void beforeCompletion() {
+ synchronization.beforeCompletion();
+ }
+}
Added: 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 (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransaction.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,243 @@
+/*
+ * 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 javax.transaction.Synchronization;
+
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.log.Log;
+
+
+/** simple 2 phase commit transaction.
+ * no logging or recovery.
+ * non thread safe (which is ok).
+ * @author Tom Baeyens
+ */
+public class StandardTransaction implements Transaction, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private static Log log = Log.getLog(StandardTransaction.class.getName());
+
+ enum State {
+ CREATED,
+ ACTIVE,
+ ROLLBACKONLY,
+ COMMITTED,
+ ROLLEDBACK
+ }
+
+ protected List<StandardResource> resources;
+ protected List<StandardSynchronization> synchronizations;
+ protected State state = State.CREATED;
+
+ // methods for interceptor //////////////////////////////////////////////////
+
+ public void begin() {
+ log.debug("beginning "+this);
+ state = State.ACTIVE;
+ }
+
+ public void complete() {
+ if (state==State.ACTIVE) {
+ commit();
+ } else if (state==State.ROLLBACKONLY){
+ rollback();
+ } else {
+ throw new TransactionException("complete on transaction in state "+state);
+ }
+ }
+
+ // public tx methods ////////////////////////////////////////////////////////
+
+ public void setRollbackOnly() {
+ if (state!=State.ACTIVE) {
+ throw new TransactionException("transaction was not active: "+state);
+ }
+ state = State.ROLLBACKONLY;
+ }
+
+ public boolean isRollbackOnly() {
+ return ( (state==State.ROLLBACKONLY)
+ || (state==State.ROLLEDBACK)
+ );
+ }
+
+ // commit ///////////////////////////////////////////////////////////////////
+
+ /** implements simplest two phase commit. */
+ public void commit() {
+ if (state!=State.ACTIVE) {
+ throw new TransactionException("commit on transaction in state "+state);
+ }
+
+ log.trace("committing "+this);
+
+ try {
+ beforeCompletion();
+
+ if (resources!=null) {
+ // prepare //////////////////////////////////////////////////////////////
+ // the prepare loop will be skipped at the first exception
+ for (StandardResource standardResource: resources) {
+ log.trace("preparing resource "+standardResource);
+ standardResource.prepare();
+ }
+ }
+
+ // for any exception in the prepare phase, we'll rollback
+ } catch (Exception exception) {
+ try {
+ log.debug("resource threw exception in prepare. rolling back.");
+ rollbackResources();
+ } catch (Exception rollbackException) {
+ log.error("rollback failed as well", rollbackException);
+ }
+
+ // rethrow
+ if (exception instanceof RuntimeException) {
+ throw (RuntimeException) exception;
+ }
+ throw new TransactionException("prepare failed", exception);
+ }
+
+ // here is the point of no return :-)
+
+ // commit ///////////////////////////////////////////////////////////////
+ Throwable commitException = null;
+ if (resources!=null) {
+ // 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
+ for (StandardResource standardResource: resources) {
+ try {
+ log.trace("committing resource "+standardResource);
+ standardResource.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 "+standardResource, t);
+ if (commitException==null) {
+ commitException = t;
+ }
+ }
+ }
+ }
+
+ state = State.COMMITTED;
+ afterCompletion();
+ log.debug("committed "+this);
+
+ if (commitException!=null) {
+ if (commitException instanceof RuntimeException) {
+ throw (RuntimeException) commitException;
+ } else if (commitException instanceof Error) {
+ throw (Error) commitException;
+ }
+ throw new TransactionException("resource failed to commit", commitException);
+ }
+ }
+
+ // rollback /////////////////////////////////////////////////////////////////
+
+ public void rollback() {
+ if ( (state!=State.ACTIVE)
+ && (state!=State.ROLLBACKONLY)
+ ) {
+ throw new TransactionException("rollback on transaction in state "+state);
+ }
+
+ log.trace("rolling back "+this);
+
+ beforeCompletion();
+ rollbackResources();
+ }
+
+
+ void rollbackResources() {
+ if (resources!=null) {
+ for (StandardResource resource: resources) {
+ try {
+ log.trace("rolling back resource "+resource);
+ resource.rollback();
+ } catch (Exception e) {
+ log.error("rollback failed for resource "+resource);
+ }
+ }
+ }
+
+ state = State.ROLLEDBACK;
+
+ afterCompletion();
+
+ log.debug("rolled back");
+ }
+
+ // synchronizations /////////////////////////////////////////////////////////
+
+ public void registerSynchronization(Synchronization synchronization) {
+ if (synchronizations==null) {
+ synchronizations = new ArrayList<StandardSynchronization>();
+ }
+ synchronizations.add(new StandardSynchronization(synchronization));
+ }
+
+ public void afterCompletion() {
+ if (synchronizations!=null) {
+ for (StandardSynchronization synchronization: synchronizations) {
+ synchronization.afterCompletion(state);
+ }
+ }
+ }
+
+ public void beforeCompletion() {
+ if (synchronizations!=null) {
+ for (StandardSynchronization synchronization: synchronizations) {
+ synchronization.beforeCompletion();
+ }
+ }
+ }
+
+ // resource enlisting ///////////////////////////////////////////////////////
+
+ public void enlistResource(StandardResource standardResource) {
+ if (resources==null) {
+ resources = new ArrayList<StandardResource>();
+ }
+ log.trace("enlisting resource "+standardResource+" to standard transaction");
+ resources.add(standardResource);
+ }
+
+ List<StandardResource> getResources() {
+ return resources;
+ }
+
+ public String toString() {
+ return "StandardTransaction["+System.identityHashCode(this)+"]";
+ }
+}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java (from rev 1850, 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/tx/StandardTransactionInterceptor.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/tx/StandardTransactionInterceptor.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,64 @@
+/*
+ * 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.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 StandardTransactionInterceptor extends Interceptor {
+
+ private static final Log log = Log.getLog(StandardTransactionInterceptor.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");
+ }
+
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ if (standardTransaction==null) {
+ throw new PvmException("no standard-transaction in environment");
+ }
+
+ standardTransaction.begin();
+
+ try {
+ return next.execute(command);
+
+ } catch (RuntimeException e) {
+ standardTransaction.setRollbackOnly();
+ throw e;
+
+ } finally {
+ standardTransaction.complete();
+ }
+ }
+}
Added: 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 (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnlistBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,50 @@
+/*
+ * 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
Deleted: 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 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionInterceptorBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -1,45 +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.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);
- }
-
-}
Deleted: 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/HibernateTransactionBinding.java 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -1,49 +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.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;
- }
-}
Deleted: 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/internal/wire/binding/HibernateTransactionInterceptorBinding.java 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateTransactionInterceptorBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -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.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);
- }
-}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/StandardTransactionInterceptorBinding.java (from rev 1850, 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/internal/wire/binding/StandardTransactionInterceptorBinding.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/StandardTransactionInterceptorBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -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.StandardTransactionInterceptor;
+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 StandardTransactionInterceptor}.
+ *
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class StandardTransactionInterceptorBinding extends WireInterceptorBinding {
+
+ public StandardTransactionInterceptorBinding() {
+ super("standard-transaction-interceptor");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ StandardTransactionInterceptor standardTransactionInterceptor = new StandardTransactionInterceptor();
+ return new ProvidedObjectDescriptor(standardTransactionInterceptor);
+ }
+}
Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java (from rev 1850, 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/TransactionBinding.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/TransactionBinding.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -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.wire.binding;
+
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.tx.StandardTransaction;
+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 TransactionBinding extends WireDescriptorBinding {
+
+ public TransactionBinding() {
+ super("transaction");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ ObjectDescriptor transactionDescriptor = null;
+
+ String type = "standard";
+ if (element.hasAttribute("type")) {
+ type = element.getAttribute("type");
+ }
+
+ if ("standard".equals(type)) {
+ transactionDescriptor = new ObjectDescriptor(StandardTransaction.class);
+ } else {
+ parse.addProblem("unsupported transaction type: "+type);
+ }
+
+ return transactionDescriptor;
+ }
+}
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-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateSessionDescriptor.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -27,6 +27,8 @@
import org.hibernate.SessionFactory;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.internal.log.Log;
+import org.jbpm.pvm.internal.tx.HibernateSessionResource;
+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;
@@ -47,17 +49,17 @@
protected String connectionName;
public Object construct(WireContext wireContext) {
+ Environment environment = Environment.getCurrent();
+ if (environment==null) {
+ throw new WireException("no environment");
+ }
+
// get the hibernate-session-factory
SessionFactory sessionFactory = null;
if (factoryName!=null) {
sessionFactory = (SessionFactory) wireContext.get(factoryName);
} else {
- Environment environment = Environment.getCurrent();
- if (environment!=null) {
- sessionFactory = environment.get(SessionFactory.class);
- } else {
- sessionFactory = wireContext.get(SessionFactory.class);
- }
+ sessionFactory = environment.get(SessionFactory.class);
}
if (sessionFactory==null) {
throw new WireException("couldn't find hibernate-session-factory "+(factoryName!=null ? "'"+factoryName+"'" : "by type ")+"to open a hibernate-session");
@@ -78,6 +80,12 @@
log.debug("creating hibernate session");
session = sessionFactory.openSession();
}
+
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ if (standardTransaction!=null) {
+ HibernateSessionResource hibernateSessionResource = new HibernateSessionResource(session);
+ standardTransaction.enlistResource(hibernateSessionResource);
+ }
return session;
}
Added: 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 (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/operation/EnlistOperation.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,74 @@
+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.StandardResource;
+import org.jbpm.pvm.internal.tx.StandardTransaction;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireException;
+
+
+/**
+ * enlists this {@link StandardResource} 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 StandardResource} 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 StandardResource)) {
+ throw new WireException("operation enlist can only be applied on objects that implement "+StandardResource.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((StandardResource)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;
+ }
+}
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-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml 2008-08-08 16:04:28 UTC (rev 1856)
@@ -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.HibernateTransactionBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.TransactionBinding" />
<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,8 +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.HibernateTransactionInterceptorBinding" />
- <binding class="org.jbpm.pvm.internal.wire.binding.HibernateSessionInterceptorBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.StandardTransactionInterceptorBinding" />
+ <binding class="org.jbpm.pvm.internal.wire.binding.EnlistBinding" />
<!-- ########################## -->
<!-- ### Operation bindings ### -->
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-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -56,7 +56,7 @@
static Map<String, Set<Long>> exclusiveThreadIds;
static List<Integer> failOnceMessageIds;
- static int nbrOfTestMessages = 10;
+ static int nbrOfTestMessages = 50;
static int timeoutMillis = 10000;
static int checkInterval = 400;
static int nbrOfTestMessagesPerExecution = 7;
@@ -162,8 +162,6 @@
for (Comment comment: comments) {
Integer messageId = new Integer(comment.getMessage());
assertTrue("message "+messageId+" committed twice", failOnceMessageIds.remove(messageId));
- // clean up for next tests
- session.delete(comment);
}
assertTrue("not all messages made a successful commit: "+failOnceMessageIds, failOnceMessageIds.isEmpty());
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,241 @@
+package org.jbpm.pvm.internal.tx;
+
+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.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireException;
+import org.jbpm.pvm.internal.wire.WireTestCase;
+
+/**
+ * @author Guillaume Porcher
+ */
+public class EnlistTest extends WireTestCase {
+
+ public void setUp() throws Exception {
+ super.setUp();
+ MyResource.events = new ArrayList<String>();
+ }
+
+ public void tearDown() throws Exception {
+ MyResource.events = null;
+ super.tearDown();
+ }
+
+ public static class MyResource implements StandardResource {
+ public static List<String> events = null;
+ public void commit() { events.add("commit"); }
+ public void flush() { events.add("flush"); }
+ public void prepare() { events.add("prepare"); }
+ public void rollback() { events.add("rollback"); }
+ }
+
+ public void testEnlist() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction name='tx' />" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ Object o = environment.get("o");
+ assertNotNull(o);
+
+ StandardTransaction t = (StandardTransaction) environment.get("tx");
+ t.begin();
+
+ assertNotNull(t);
+ assertTrue(t.getResources().contains(o));
+ assertEquals(MyResource.events.toString(), 0, MyResource.events.size());
+
+ t.complete();
+
+ assertEquals(MyResource.events.toString(), 2, MyResource.events.size());
+ assertEquals("prepare", MyResource.events.get(0));
+ assertEquals("commit", MyResource.events.get(1));
+ }
+
+ public void testEnlistRollback() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction name='tx' />" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ Object o = environment.get("o");
+ assertNotNull(o);
+
+ StandardTransaction t = (StandardTransaction) environment.get("tx");
+ t.begin();
+
+ assertNotNull(t);
+ assertTrue(t.getResources().contains(o));
+ assertEquals(MyResource.events.toString(), 0, MyResource.events.size());
+
+ t.setRollbackOnly();
+
+ t.complete();
+
+ assertEquals(MyResource.events.toString(), 1, MyResource.events.size());
+ assertEquals("rollback", MyResource.events.get(0));
+ }
+
+ public void testEnlistInOtherContext() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction name='tx' />" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ WireContext context = createWireContext(
+ "<objects>" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>"+
+ "</objects>"
+ );
+ environment.addContext(context);
+ Object o = environment.get("o");
+
+ assertNotNull(o);
+
+ StandardTransaction t = (StandardTransaction) environment.get("tx");
+ t.begin();
+
+ assertNotNull(t);
+ assertTrue(t.getResources().contains(o));
+ assertEquals(MyResource.events.toString(), 0, MyResource.events.size());
+
+ t.complete();
+
+ assertEquals(MyResource.events.toString(), 2, MyResource.events.size());
+ assertEquals("prepare", MyResource.events.get(0));
+ assertEquals("commit", MyResource.events.get(1));
+ }
+
+ public void testEnlistInOtherContextWithRollback() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction name='tx' />" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ WireContext context = createWireContext(
+ "<objects>" +
+ " <object name='o' class='"+ MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>"+
+ "</objects>"
+ );
+ environment.addContext(context);
+ Object o = environment.get("o");
+
+ assertNotNull(o);
+
+ StandardTransaction t = (StandardTransaction) environment.get("tx");
+ t.begin();
+
+ assertNotNull(t);
+ assertTrue(t.getResources().contains(o));
+ assertEquals(MyResource.events.toString(), 0, MyResource.events.size());
+
+ t.setRollbackOnly();
+
+ t.complete();
+
+ assertEquals(MyResource.events.toString(), 1, MyResource.events.size());
+ assertEquals("rollback", MyResource.events.get(0));
+ }
+
+ public void testEnlistNotAResource() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction name='transaction' />" +
+ " <object name='o' class='java.lang.Object'>" +
+ " <enlist transaction='transaction'/>" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ try{
+ environment.get("o");
+ fail("expected exeption");
+ } catch (WireException e) {
+ assertTextPresent("couldn't initialize object 'o':", e.getMessage());
+ assertTextPresent("operation enlist can only be applied on objects that implement org.jbpm.pvm.internal.tx.StandardResource", e.getMessage());
+ } finally {
+ environment.close();
+ }
+ }
+
+ public void testEnlistNotATransaction() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <object name='o' class='"+MyResource.class.getName()+"'>" +
+ " <enlist transaction='tx'/>" +
+ " </object>" +
+ " <object name='tx' class='java.lang.Object'/>" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ try{
+ environment.get("o");
+ fail("expected exeption");
+ } catch (WireException e) {
+ assertTextPresent("couldn't initialize object 'o':", e.getMessage());
+ assertTextPresent("couldn't find org.jbpm.pvm.internal.tx.StandardTransaction 'tx' to enlist resource ", e.getMessage());
+ } finally {
+ environment.close();
+ }
+ }
+
+ public void testMissingTransactionName() {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " </environment>" +
+ "</contexts>"
+ );
+
+ try{
+ assertNotNull(environment.get(Transaction.class));
+ assertNotNull(environment.get(StandardTransaction.class));
+ } finally {
+ environment.close();
+ }
+ }
+
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TestResource.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TestResource.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TestResource.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+
+public class TestResource implements StandardResource {
+
+ boolean isPrepared;
+ boolean isCommitted;
+ boolean isRolledBack;
+
+ public void prepare() {
+ isPrepared = true;
+ }
+ public void commit() {
+ isCommitted = true;
+ }
+ public void rollback() {
+ isRolledBack = true;
+ }
+}
\ No newline at end of file
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,182 @@
+/*
+ * 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.jbpm.pvm.test.base.JbpmTestCase;
+import org.jbpm.pvm.env.Environment;
+
+/**
+ * @author Tom Baeyens
+ */
+public class TransactionFailingCommitTest extends JbpmTestCase {
+
+ public static class CommitException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+ public CommitException(String msg) {
+ super(msg);
+ }
+ }
+
+ public static class FailingPrepareResource extends TestResource {
+ public void prepare() {
+ super.prepare();
+ throw new CommitException("resource couldn't prepare");
+ }
+ }
+
+ public void testMultipleResourcesFailingPrepare() {
+ TestResource resourceOne = null;
+ TestResource resourceTwo = null;
+ TestResource resourceThree = null;
+
+ try {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+FailingPrepareResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ resourceThree = (TestResource) environment.get("resourceThree");
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+ fail("expected exception");
+ } catch (CommitException e) {
+ // OK
+ }
+
+ assertTrue(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertTrue(resourceOne.isRolledBack);
+
+ assertTrue(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertTrue(resourceTwo.isRolledBack);
+
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertTrue(resourceThree.isRolledBack);
+ }
+
+ public static class FailingCommitResource extends TestResource {
+ public void commit() {
+ super.commit();
+ throw new CommitException("resource couldn't commit");
+ }
+ }
+
+ public void testMultipleResourcesFailingCommit() {
+ TestResource resourceOne = null;
+ TestResource resourceTwo = null;
+ TestResource resourceThree = null;
+
+ try {
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+FailingCommitResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ resourceThree = (TestResource) environment.get("resourceThree");
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+ fail("expected exception");
+ } catch (CommitException e) {
+ // OK
+ }
+
+ assertTrue(resourceOne.isPrepared);
+ assertTrue(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ assertTrue(resourceTwo.isPrepared);
+ assertTrue(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ assertTrue(resourceThree.isPrepared);
+ assertTrue(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,173 @@
+/*
+ * 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.jbpm.pvm.test.base.JbpmTestCase;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.tx.StandardTransaction;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TransactionResourcesCommitTest extends JbpmTestCase {
+
+ public void testOneResourceCommit() {
+
+ TestResource resourceOne = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertTrue(resourceOne.isPrepared);
+ assertTrue(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+ }
+
+ public void testMultipleResourcesCommit() {
+ TestResource resourceOne = null;
+ TestResource resourceTwo = null;
+ TestResource resourceThree = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ resourceThree = (TestResource) environment.get("resourceThree");
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertTrue(resourceOne.isPrepared);
+ assertTrue(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ assertTrue(resourceTwo.isPrepared);
+ assertTrue(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ assertTrue(resourceThree.isPrepared);
+ assertTrue(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+ }
+
+ public void testFetchOneResourceOutOfManyCommit() {
+ TestResource resourceTwo = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ assertEquals(1, environment.get(StandardTransaction.class).resources.size());
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertEquals(1, environment.get(StandardTransaction.class).resources.size());
+
+ assertTrue(resourceTwo.isPrepared);
+ assertTrue(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,180 @@
+/*
+ * 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.jbpm.pvm.test.base.JbpmTestCase;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.tx.StandardTransaction;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TransactionResourcesSetRollbackOnlyTest extends JbpmTestCase {
+
+ public void testOneResourceSetRollbackOnly() {
+
+ TestResource resourceOne = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+
+ environment.get(Transaction.class).setRollbackOnly();
+
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertTrue(resourceOne.isRolledBack);
+ }
+
+ public void testMultipleResourcesSetRollbackOnly() {
+ TestResource resourceOne = null;
+ TestResource resourceTwo = null;
+ TestResource resourceThree = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceOne = (TestResource) environment.get("resourceOne");
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertFalse(resourceOne.isRolledBack);
+
+ environment.get(Transaction.class).setRollbackOnly();
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ resourceThree = (TestResource) environment.get("resourceThree");
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertFalse(resourceThree.isRolledBack);
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertFalse(resourceOne.isPrepared);
+ assertFalse(resourceOne.isCommitted);
+ assertTrue(resourceOne.isRolledBack);
+
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertTrue(resourceTwo.isRolledBack);
+
+ assertFalse(resourceThree.isPrepared);
+ assertFalse(resourceThree.isCommitted);
+ assertTrue(resourceThree.isRolledBack);
+ }
+
+ public void testFetchOneResourceOutOfManySetRollbackOnly() {
+ TestResource resourceTwo = null;
+
+ Environment environment = openEnvironment(
+ "<contexts>" +
+ " <environment-factory/>"+
+ " <environment>" +
+ " <transaction />" +
+ " <object name='resourceOne' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceTwo' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " <object name='resourceThree' class='"+TestResource.class.getName()+"'>" +
+ " <enlist />" +
+ " </object>" +
+ " </environment>" +
+ "</contexts>"
+ );
+ try {
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ standardTransaction.begin();
+
+ resourceTwo = (TestResource) environment.get("resourceTwo");
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertFalse(resourceTwo.isRolledBack);
+
+ environment.get(Transaction.class).setRollbackOnly();
+
+ assertEquals(1, environment.get(StandardTransaction.class).resources.size());
+
+ standardTransaction.complete();
+
+ } finally {
+ environment.close();
+ }
+
+ assertEquals(1, environment.get(StandardTransaction.class).resources.size());
+
+ assertFalse(resourceTwo.isPrepared);
+ assertFalse(resourceTwo.isCommitted);
+ assertTrue(resourceTwo.isRolledBack);
+ }
+}
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java 2008-08-08 16:04:28 UTC (rev 1856)
@@ -0,0 +1,44 @@
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TxTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("org.jbpm.pvm.internal.tx");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TransactionResourcesCommitTest.class);
+ suite.addTestSuite(TransactionResourcesSetRollbackOnlyTest.class);
+ suite.addTestSuite(EnlistTest.class);
+ suite.addTestSuite(TransactionFailingCommitTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml 2008-08-08 16:04:28 UTC (rev 1856)
@@ -18,8 +18,7 @@
<command-service>
<retry-interceptor />
<environment-interceptor />
- <hibernate-session-interceptor />
- <hibernate-transaction-interceptor />
+ <standard-transaction-interceptor />
</command-service>
<job-executor threads="1" auto-start="false" />
@@ -38,7 +37,7 @@
<environment>
<hibernate-session />
- <hibernate-transaction />
+ <transaction />
<pvm-db-session />
<job-db-session />
<message-session />
Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml 2008-08-08 15:21:20 UTC (rev 1855)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml 2008-08-08 16:04:28 UTC (rev 1856)
@@ -18,8 +18,7 @@
<command-service>
<retry-interceptor />
<environment-interceptor />
- <hibernate-session-interceptor />
- <hibernate-transaction-interceptor />
+ <standard-transaction-interceptor />
</command-service>
<hibernate-configuration>
@@ -37,7 +36,7 @@
<environment>
<hibernate-session />
- <hibernate-transaction />
+ <transaction />
<pvm-db-session />
<object class="org.jbpm.pvm.internal.db.langext.AddressSession" />
</environment>
More information about the jbpm-commits
mailing list