Author: alex.guizar(a)jboss.com
Date: 2009-01-27 22:17:25 -0500 (Tue, 27 Jan 2009)
New Revision: 3724
Removed:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java
jbpm3/trunk/modules/core/src/main/resources/hibernate.properties.postgresql.xml
jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Invocation.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Recorded.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/persistence/db/PersistenceServiceDbTest.java
Log:
JBPM-1988 throw JbpmPersistenceException from JtaDbPersistenceService
improve inheritance between JtaDbPersistenceService and its superclass
treat stale state exceptions uniformly
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -59,8 +59,7 @@
if (!acquiredJobs.isEmpty()) {
for (Job job : acquiredJobs) {
executeJob(job);
- if (!isActive)
- break;
+ if (!isActive) break;
}
}
else if (isActive) {
@@ -144,10 +143,9 @@
catch (JbpmPersistenceException e) {
// if this is a stale object exception, keep it quiet
if (Services.isCausedByStaleState(e)) {
- log.debug("problem acquiring jobs " + acquiredJobs + ":
optimistic locking failed");
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("problem
acquiring jobs "
- + acquiredJobs
- + ": optimistic locking failed", e);
+ log.debug("optimistic locking failed, could not acquire jobs " +
acquiredJobs);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed, could not acquire jobs " +
acquiredJobs, e);
acquiredJobs = Collections.emptyList();
}
else {
@@ -198,7 +196,9 @@
catch (JbpmPersistenceException e) {
// if this is a stale state exception, keep it quiet
if (Services.isCausedByStaleState(e)) {
- log.debug("optimistic locking failed, couldn't complete job " +
job);
+ log.debug("optimistic locking failed, could not complete job " +
job);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed, could not complete job " + job, e);
}
else {
throw e;
@@ -209,8 +209,7 @@
private static boolean isPersistenceException(Throwable throwable) {
do {
- if (throwable instanceof HibernateException)
- return true;
+ if (throwable instanceof HibernateException) return true;
throwable = throwable.getCause();
} while (throwable != null);
return false;
@@ -235,7 +234,9 @@
catch (JbpmPersistenceException e) {
// if this is a stale object exception, keep it quiet
if (Services.isCausedByStaleState(e)) {
- log.debug("optimistic locking failed, couldn't get next due
date");
+ log.debug("optimistic locking failed, could not return next due date:
" + nextDueDate);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed, could not return next due date: " +
nextDueDate, e);
nextDueDate = null;
}
else {
@@ -266,8 +267,7 @@
* @deprecated As of jBPM 3.2.3, replaced by {@link #deactivate()}
*/
public void setActive(boolean isActive) {
- if (isActive == false)
- deactivate();
+ if (isActive == false) deactivate();
}
/**
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -10,10 +10,11 @@
import org.jbpm.db.JobSession;
import org.jbpm.job.Job;
import org.jbpm.persistence.JbpmPersistenceException;
+import org.jbpm.persistence.db.StaleObjectLogConfigurer;
import org.jbpm.svc.Services;
public class LockMonitorThread extends Thread {
-
+
JbpmConfiguration jbpmConfiguration;
int lockMonitorInterval;
int maxLockTime;
@@ -21,7 +22,8 @@
boolean isActive = true;
- public LockMonitorThread(JbpmConfiguration jbpmConfiguration, int lockMonitorInterval,
int maxLockTime, int lockBufferTime) {
+ public LockMonitorThread(JbpmConfiguration jbpmConfiguration, int lockMonitorInterval,
+ int maxLockTime, int lockBufferTime) {
this.jbpmConfiguration = jbpmConfiguration;
this.lockMonitorInterval = lockMonitorInterval;
this.maxLockTime = maxLockTime;
@@ -33,51 +35,59 @@
while (isActive) {
try {
unlockOverdueJobs();
- if ( (isActive)
- && (lockMonitorInterval>0)
- ) {
+ if ((isActive) && (lockMonitorInterval > 0)) {
sleep(lockMonitorInterval);
}
- } catch (InterruptedException e) {
- log.info("lock monitor thread '"+getName()+"' got
interrupted");
- } catch (Exception e) {
- log.error("exception in lock monitor thread. waiting
"+lockMonitorInterval+" milliseconds", e);
+ }
+ catch (InterruptedException e) {
+ log.info("lock monitor thread '" + getName() + "' got
interrupted");
+ }
+ catch (Exception e) {
+ log.error("exception in lock monitor thread. waiting "
+ + lockMonitorInterval
+ + " milliseconds", e);
try {
sleep(lockMonitorInterval);
- } catch (InterruptedException e2) {
+ }
+ catch (InterruptedException e2) {
log.debug("delay after exception got interrupted", e2);
}
}
}
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.error("exception in lock monitor thread", e);
- } finally {
- log.info(getName()+" leaves cyberspace");
}
+ finally {
+ log.info(getName() + " leaves cyberspace");
+ }
}
-
protected void unlockOverdueJobs() {
+ List<Job> overdueJobs = null;
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
+ Date treshold = new Date(System.currentTimeMillis() - maxLockTime -
lockBufferTime);
JobSession jobSession = jbpmContext.getJobSession();
-
- Date treshold = new Date(System.currentTimeMillis()-maxLockTime-lockBufferTime);
- List<Job> jobsWithOverdueLockTime =
jobSession.findJobsWithOverdueLockTime(treshold);
- for (Job job : jobsWithOverdueLockTime) {
- log.debug("unlocking "+job+ " owned by thread
"+job.getLockOwner());
+ overdueJobs = jobSession.findJobsWithOverdueLockTime(treshold);
+ for (Job job : overdueJobs) {
+ log.debug("unlocking " + job + " owned by thread " +
job.getLockOwner());
job.setLockOwner(null);
job.setLockTime(null);
- jobSession.saveJob(job);
}
- } finally {
+ }
+ finally {
try {
jbpmContext.close();
- } catch (JbpmPersistenceException e) {
+ }
+ catch (JbpmPersistenceException e) {
// if this is a stale object exception, keep it quiet
if (Services.isCausedByStaleState(e)) {
- log.debug("optimistic locking failed, couldn't unlock overdue
jobs");
- } else {
+ log.debug("optimistic locking failed, could not unlock overdue jobs:
" + overdueJobs);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "problem unlocking overdue jobs: optimistic locking failed", e);
+ }
+ else {
throw e;
}
}
@@ -88,18 +98,16 @@
* @deprecated As of jBPM 3.2.3, replaced by {@link #deactivate()}
*/
public void setActive(boolean isActive) {
- if (isActive == false)
- deactivate();
+ if (isActive == false) deactivate();
}
/**
- * Indicates that this thread should stop running.
- * Execution will cease shortly afterwards.
+ * Indicates that this thread should stop running. Execution will cease shortly
afterwards.
*/
public void deactivate() {
if (isActive) {
isActive = false;
- interrupt();
+ interrupt();
}
}
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -45,60 +45,44 @@
import org.jbpm.tx.TxService;
public class DbPersistenceService implements Service, PersistenceService {
-
+
private static final long serialVersionUID = 1L;
- protected DbPersistenceServiceFactory persistenceServiceFactory = null;
+ protected final DbPersistenceServiceFactory persistenceServiceFactory;
- protected Connection connection = null;
- protected boolean mustConnectionBeClosed = false;
+ protected Connection connection;
+ protected boolean mustConnectionBeClosed;
- protected Transaction transaction = null;
+ protected Transaction transaction;
protected boolean isTransactionEnabled = true;
- protected boolean isCurrentSessionEnabled = false;
+ protected boolean isCurrentSessionEnabled;
- // boolean isRollbackOnly = false;
-
protected Session session;
- protected boolean mustSessionBeFlushed = false;
- protected boolean mustSessionBeClosed = false;
+ protected boolean mustSessionBeFlushed;
+ protected boolean mustSessionBeClosed;
- protected Services services = null;
+ protected GraphSession graphSession;
+ protected TaskMgmtSession taskMgmtSession;
+ protected JobSession jobSession;
+ protected ContextSession contextSession;
+ protected LoggingSession loggingSession;
- protected GraphSession graphSession = null;
- protected TaskMgmtSession taskMgmtSession = null;
- protected JobSession jobSession = null;
- protected ContextSession contextSession = null;
- protected LoggingSession loggingSession = null;
+ /** @deprecated for access to other services, invoke {@link JbpmContext#getServices()}
*/
+ protected Services services;
public DbPersistenceService(DbPersistenceServiceFactory persistenceServiceFactory) {
- this(persistenceServiceFactory, getCurrentServices());
- }
-
- static Services getCurrentServices() {
- Services services = null;
- JbpmContext currentJbpmContext = JbpmContext.getCurrentJbpmContext();
- if (currentJbpmContext!=null) {
- services = currentJbpmContext.getServices();
- }
- return services;
- }
-
- DbPersistenceService(DbPersistenceServiceFactory persistenceServiceFactory, Services
services) {
this.persistenceServiceFactory = persistenceServiceFactory;
this.isTransactionEnabled = persistenceServiceFactory.isTransactionEnabled();
this.isCurrentSessionEnabled = persistenceServiceFactory.isCurrentSessionEnabled();
- this.services = services;
}
public SessionFactory getSessionFactory() {
- return session != null ? session.getSessionFactory() :
persistenceServiceFactory.getSessionFactory();
+ return session != null ? session.getSessionFactory()
+ : persistenceServiceFactory.getSessionFactory();
}
public Session getSession() {
- if ( (session==null)
- && (getSessionFactory()!=null)
- ) {
+ if (session == null && getSessionFactory() != null) {
Connection connection = getConnection(false);
if (isCurrentSessionEnabled) {
log.debug("using current hibernate session");
@@ -106,20 +90,22 @@
mustSessionBeClosed = false;
mustSessionBeFlushed = false;
mustConnectionBeClosed = false;
- } else if (connection!=null) {
- log.debug("creating hibernate session with connection "+connection);
+ }
+ else if (connection != null) {
+ log.debug("creating hibernate session on " + connection);
session = getSessionFactory().openSession(connection);
mustSessionBeClosed = true;
mustSessionBeFlushed = true;
mustConnectionBeClosed = false;
- } else {
+ }
+ else {
log.debug("creating hibernate session");
session = getSessionFactory().openSession();
mustSessionBeClosed = true;
mustSessionBeFlushed = true;
mustConnectionBeClosed = false;
}
-
+
if (isTransactionEnabled) {
beginTransaction();
}
@@ -130,41 +116,34 @@
public void beginTransaction() {
log.debug("beginning hibernate transaction");
transaction = session.beginTransaction();
- log.debug("begun hibernate transaction " + transaction.toString());
+ log.debug("begun " + transaction);
}
public void endTransaction() {
- if ( (isTransactionEnabled)
- && (transaction!=null)
- ) {
- if (isRollbackOnly()) {
- try {
- log.debug("rolling back hibernate transaction " +
transaction.toString());
- mustSessionBeFlushed = false; // flushing updates that will be rolled back is
not very clever :-)
- transaction.rollback();
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and
mask the original Error.
- throw new JbpmPersistenceException("couldn't rollback hibernate
session", e);
- }
- } else {
- try {
- log.debug("committing hibernate transaction " +
transaction.toString());
- mustSessionBeFlushed = false; // commit does a flush anyway
- transaction.commit();
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and
mask the original Error.
- try {
- // if the commit fails, we must do a rollback
- transaction.rollback();
- } catch (Exception e2) {
- // if the rollback fails, we did what we could and you're in
- // deep shit :-(
- log.error("problem rolling back after failed commit", e2);
- }
- throw new JbpmPersistenceException("couldn't commit hibernate
session", e);
- }
+ if (isTransactionManagedExternally()) {
+ if (session != null && getTxService().isRollbackOnly()) {
+ throw new JbpmException("cannot mark externally managed transaction for
rollback");
}
+ return;
}
+
+ if (!isTransactionRollbackOnly()) {
+ Exception commitException = commit();
+ if (commitException != null) {
+ rollback();
+ closeSession();
+ closeConnection();
+ throw new JbpmPersistenceException("transaction commit failed",
commitException);
+ }
+ }
+ else { // isRollbackOnly==true
+ Exception rollbackException = rollback();
+ if (rollbackException != null) {
+ closeSession();
+ closeConnection();
+ throw new JbpmPersistenceException("transaction rollback failed",
rollbackException);
+ }
+ }
}
public Connection getConnection() {
@@ -172,119 +151,120 @@
}
public Connection getConnection(boolean resolveSession) {
- if (connection==null) {
- if (persistenceServiceFactory.getDataSource()!=null) {
+ if (connection == null) {
+ if (persistenceServiceFactory.getDataSource() != null) {
try {
log.debug("fetching jdbc connection from datasource");
connection = persistenceServiceFactory.getDataSource().getConnection();
mustConnectionBeClosed = true;
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and
mask the original Error.
- throw new JbpmException("couldn't obtain connection from
datasource", e);
}
- } else {
+ catch (Exception e) {
+ // NOTE that Errors are not caught because that might halt the JVM
+ // and mask the original Error.
+ throw new JbpmException("could not obtain connection from
datasource", e);
+ }
+ }
+ else {
if (resolveSession) {
// initializes the session member
getSession();
}
- if (session!=null) {
+ if (session != null) {
connection = session.connection();
- log.debug("fetching connection from hibernate session. this transfers
responsibility for closing the jdbc connection to the user! "+connection);
+ log.debug("fetched "
+ + connection
+ + " from hibernate session, client is responsible for closing
it!");
mustConnectionBeClosed = false;
}
}
}
return connection;
}
-
+
public boolean isTransactionActive() {
return transaction != null && transaction.isActive();
}
- protected boolean isTransactionExternallyManaged() {
- return !(isTransactionEnabled && transaction != null);
+ protected boolean isTransactionManagedExternally() {
+ return !isTransactionEnabled || transaction == null;
}
+ protected boolean isTransactionRollbackOnly() {
+ return getTxService().isRollbackOnly();
+ }
+
public void close() {
+ endTransaction();
- if ( (session!=null)
- && isTransactionExternallyManaged()
- && (isRollbackOnly())
- ) {
- throw new JbpmException("setRollbackOnly was invoked while transaction is
being managed externally");
- }
-
- if ( (isTransactionEnabled)
- && (transaction!=null)
- ) {
-
- if (! isRollbackOnly()) {
- Exception commitException = commit();
- if (commitException!=null) {
- rollback();
- closeSession();
- closeConnection();
- throw new JbpmPersistenceException("hibernate commit failed",
commitException);
- }
-
- } else { // isRollbackOnly==true
- Exception rollbackException = rollback();
- if (rollbackException!=null) {
- closeSession();
- closeConnection();
- throw new JbpmPersistenceException("hibernate rollback failed",
rollbackException);
- }
- }
- }
-
Exception flushException = flushSession();
- if (flushException!=null) {
- // JBPM-1465: transaction is either committed or rolled back at this point;
- // it is also possible that the transaction was initiated externally
+ if (flushException != null) {
+ // JBPM-1465: at this point, the transaction is already committed or rolled back
+ // alternatively, the transaction is being managed externally
// hence rolling back here is redundant and possibly dangerous
closeSession();
closeConnection();
- throw new JbpmPersistenceException("hibernate flush failed",
flushException);
+ throw new JbpmPersistenceException("hibernate flush session failed",
flushException);
}
Exception closeSessionException = closeSession();
- if (closeSessionException!=null) {
+ if (closeSessionException != null) {
closeConnection();
throw new JbpmPersistenceException("hibernate close session failed",
closeSessionException);
}
Exception closeConnectionException = closeConnection();
- if (closeConnectionException!=null) {
- throw new JbpmPersistenceException("hibernate close connection failed",
closeConnectionException);
+ if (closeConnectionException != null) {
+ throw new JbpmPersistenceException("hibernate close connection failed",
+ closeConnectionException);
}
}
- Exception commit() {
+ protected Exception commit() {
try {
log.debug("committing " + transaction);
- mustSessionBeFlushed = false; // commit does a flush anyway
+ mustSessionBeFlushed = false; // commit does a flush anyway
transaction.commit();
- } catch (StaleStateException e) {
+ }
+ catch (StaleStateException e) {
log.info("problem committing transaction: optimistic locking failed");
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("optimistic
locking failed while committing " + transaction, e);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed while committing " + transaction, e);
return e;
- } catch (Exception e) {
- log.error("hibernate commit failed", e);
+ }
+ catch (Exception e) {
+ log.error("transaction commit failed", e);
return e;
}
return null;
}
- Exception flushSession() {
+ protected Exception rollback() {
+ try {
+ log.debug("rolling back " + transaction);
+ // flushing updates that will be rolled back is not very clever :-)
+ mustSessionBeFlushed = false;
+ transaction.rollback();
+ }
+ catch (Exception e) {
+ log.error("transaction rollback failed", e);
+ return e;
+ }
+ return null;
+ }
+
+ private Exception flushSession() {
if (mustSessionBeFlushed) {
try {
log.debug("flushing " + session);
session.flush();
- } catch (StaleStateException e) {
+ }
+ catch (StaleStateException e) {
log.info("problem flushing session: optimistic locking failed");
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("optimistic
locking failed while flushing " + session, e);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed while flushing " + session, e);
return e;
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.error("hibernate flush failed", e);
return e;
}
@@ -292,47 +272,37 @@
return null;
}
- Exception closeConnection() {
- if (mustConnectionBeClosed) {
+ private Exception closeSession() {
+ if (mustSessionBeClosed) {
try {
- if ( (connection!=null)
- && (! connection.isClosed())
- ) {
- log.debug("closing jdbc connection");
- connection.close();
- } else {
- log.warn("jdbc connection was already closed");
+ if (session.isOpen()) {
+ log.debug("closing hibernate session");
+ session.close();
}
- } catch (Exception e) {
- log.error("hibernate session close failed", e);
+ else {
+ log.warn("hibernate session was already closed");
+ }
+ }
+ catch (Exception e) {
return e;
}
}
return null;
}
- Exception rollback() {
- try {
- log.debug("rolling back hibernate transaction");
- mustSessionBeFlushed = false; // flushing updates that will be rolled back is not
very clever :-)
- transaction.rollback();
- } catch (Exception e) {
- log.error("hibernate rollback failed", e);
- return e;
- }
- return null;
- }
-
- Exception closeSession() {
- if (mustSessionBeClosed) {
+ private Exception closeConnection() {
+ if (mustConnectionBeClosed) {
try {
- if(session.isOpen()) {
- log.debug("closing hibernate session");
- session.close();
- } else {
- log.warn("hibernate session was already closed");
+ if (connection != null) {
+ log.debug("closing jdbc connection");
+ connection.close();
}
- } catch (Exception e) {
+ else {
+ log.warn("jdbc connection was already closed");
+ }
+ }
+ catch (Exception e) {
+ log.error("hibernate session close failed", e);
return e;
}
}
@@ -342,54 +312,60 @@
public void assignId(Object object) {
try {
getSession().save(object);
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and mask
the original Error.
- throw new JbpmPersistenceException("couldn't assign id to "+object,
e);
}
+ catch (Exception e) {
+ // NOTE that Errors are not caught because that might halt the JVM
+ // and mask the original Error.
+ throw new JbpmPersistenceException("couldn't assign id to " + object,
e);
+ }
}
// getters and setters //////////////////////////////////////////////////////
public GraphSession getGraphSession() {
- if (graphSession==null) {
+ if (graphSession == null) {
Session session = getSession();
- if (session!=null) {
+ if (session != null) {
graphSession = new GraphSession(session);
}
}
return graphSession;
}
+
public LoggingSession getLoggingSession() {
- if (loggingSession==null) {
+ if (loggingSession == null) {
Session session = getSession();
- if (session!=null) {
+ if (session != null) {
loggingSession = new LoggingSession(session);
}
}
return loggingSession;
}
+
public JobSession getJobSession() {
- if (jobSession==null) {
+ if (jobSession == null) {
Session session = getSession();
- if (session!=null) {
+ if (session != null) {
jobSession = new JobSession(session);
}
}
return jobSession;
}
+
public ContextSession getContextSession() {
- if (contextSession==null) {
+ if (contextSession == null) {
Session session = getSession();
- if (session!=null) {
+ if (session != null) {
contextSession = new ContextSession(session);
}
}
return contextSession;
}
+
public TaskMgmtSession getTaskMgmtSession() {
- if (taskMgmtSession==null) {
+ if (taskMgmtSession == null) {
Session session = getSession();
- if (session!=null) {
+ if (session != null) {
taskMgmtSession = new TaskMgmtSession(session);
}
}
@@ -401,77 +377,132 @@
}
/**
- * @deprecated use {@link org.jbpm.tx.TxService} instead.
+ * @deprecated use {@link TxService#isRollbackOnly()} instead
*/
public boolean isRollbackOnly() {
- TxService txService = (services!=null ? services.getTxService() : null);
- if (txService==null) {
- throw new JbpmException("no jbpm tx service configured");
- }
- return txService.isRollbackOnly();
+ return getTxService().isRollbackOnly();
}
+
/**
- * @deprecated use {@link org.jbpm.tx.TxService} instead.
+ * @deprecated use {@link TxService#setRollbackOnly()} instead
*/
- public void setRollbackOnly(boolean isRollbackOnly) {
- throw new UnsupportedOperationException("method setRollbackOnly has been
removed. Use TxService instead.");
+ public void setRollbackOnly() {
+ getTxService().setRollbackOnly();
}
+
/**
- * @deprecated use {@link org.jbpm.tx.TxService} instead.
+ * @throws UnsupportedOperationException if <code>rollbackOnly</code> is
<code>false</code>
+ * @deprecated use {@link TxService#setRollbackOnly()} instead
*/
- public void setRollbackOnly() {
- TxService txService = (services!=null ? services.getTxService() : null);
- if (txService==null) {
- throw new JbpmException("no jbpm tx service configured");
+ public void setRollbackOnly(boolean rollbackOnly) {
+ if (!rollbackOnly) {
+ throw new UnsupportedOperationException();
}
- txService.setRollbackOnly();
+ setRollbackOnly();
}
+ private TxService getTxService() {
+ return (TxService) Services.getCurrentService(Services.SERVICENAME_TX);
+ }
+
+ /**
+ * Injects an external Hibernate session, disabling transaction management.
+ */
public void setSession(Session session) {
- this.session = session;
- log.debug("injecting a session disables transaction");
- isTransactionEnabled = false;
+ setSession(session, false);
}
+ /**
+ * Injects an external Hibernate session without affecting transaction management.
+ *
+ * @deprecated use {@link #setSession(Session, boolean) setSession(session, true)}
instead
+ */
public void setSessionWithoutDisablingTx(Session session) {
+ setSession(session, true);
+ }
+
+ /**
+ * Injects an external Hibernate session. Injecting a session would normally disable
transaction
+ * management. The <code>keepTransactionEnabled</code> parameter can be
used to prevent
+ * transaction management from being disabled, according to the following table.
+ * <table border="1">
+ * <tr>
+ * <th>is currently enabled?</th>
+ * <th>keep enabled?</th>
+ * <th>enabled onward</th>
+ * </tr>
+ * <tr>
+ * <td>true</td>
+ * <td>true</td>
+ * <td>true (no change)</td>
+ * </tr>
+ * <tr>
+ * <td>true</td>
+ * <td>false</td>
+ * <td>false</td>
+ * </tr>
+ * <tr>
+ * <td>false</td>
+ * <td>n/a</td>
+ * <td>false (no change)</td>
+ * </tr>
+ * </table>
+ */
+ public void setSession(Session session, boolean keepTransactionEnabled) {
this.session = session;
+ if (isTransactionEnabled && !keepTransactionEnabled) {
+ log.debug("disabling transaction due to session injection");
+ isTransactionEnabled = false;
+ }
}
public void setConnection(Connection connection) {
this.connection = connection;
}
+
public void setContextSession(ContextSession contextSession) {
this.contextSession = contextSession;
}
+
public void setDataSource(DataSource dataSource) {
this.persistenceServiceFactory.dataSource = dataSource;
}
+
public void setGraphSession(GraphSession graphSession) {
this.graphSession = graphSession;
}
+
public void setLoggingSession(LoggingSession loggingSession) {
this.loggingSession = loggingSession;
}
+
public void setJobSession(JobSession jobSession) {
this.jobSession = jobSession;
}
+
public void setTaskMgmtSession(TaskMgmtSession taskMgmtSession) {
this.taskMgmtSession = taskMgmtSession;
}
+
public void setSessionFactory(SessionFactory sessionFactory) {
this.persistenceServiceFactory.sessionFactory = sessionFactory;
}
+
public Transaction getTransaction() {
return transaction;
}
+
public void setTransaction(Transaction transaction) {
this.transaction = transaction;
}
+
public boolean isTransactionEnabled() {
return isTransactionEnabled;
}
+
public void setTransactionEnabled(boolean isTransactionEnabled) {
this.isTransactionEnabled = isTransactionEnabled;
}
+
private static Log log = LogFactory.getLog(DbPersistenceService.class);
}
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -21,6 +21,7 @@
*/
package org.jbpm.persistence.jta;
+import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
@@ -30,82 +31,93 @@
import org.hibernate.util.JTAHelper;
import org.jbpm.JbpmException;
import org.jbpm.persistence.db.DbPersistenceService;
+import org.jbpm.persistence.db.StaleObjectLogConfigurer;
+import org.jbpm.svc.Services;
public class JtaDbPersistenceService extends DbPersistenceService {
+ private UserTransaction transaction;
+
private static final long serialVersionUID = 1L;
private static Log log = LogFactory.getLog(JtaDbPersistenceService.class);
- private UserTransaction userTransaction;
-
public JtaDbPersistenceService(JtaDbPersistenceServiceFactory
persistenceServiceFactory) {
super(persistenceServiceFactory);
- if (!isJtaTransactionInProgress()) {
- beginUserTransaction();
+ if (!isTransactionActive()) {
+ beginTransaction();
}
}
public boolean isTransactionActive() {
- return isJtaTransactionInProgress();
+ SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor)
getSessionFactory();
+ return JTAHelper.isTransactionInProgress(sessionFactory);
}
- protected boolean isTransactionExternallyManaged() {
- return !isJtaTxCreated();
+ protected boolean isTransactionManagedExternally() {
+ return transaction == null;
}
- public void close() {
- super.close();
+ protected boolean isTransactionRollbackOnly() {
+ return super.isTransactionRollbackOnly()
+ || JTAHelper.isMarkedForRollback(getTransactionStatus());
+ }
- if (userTransaction != null) {
- endUserTransaction();
+ public void beginTransaction() {
+ try {
+ log.debug("beginning " + transaction);
+ JtaDbPersistenceServiceFactory jtaFactory = (JtaDbPersistenceServiceFactory)
persistenceServiceFactory;
+ transaction = jtaFactory.getUserTransaction();
+ transaction.begin();
}
+ catch (Exception e) {
+ throw new JbpmException("transaction begin failed", e);
+ }
}
- boolean isJtaTransactionInProgress() {
- SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor)
getSessionFactory();
- return JTAHelper.isTransactionInProgress(sessionFactory);
+ private int getTransactionStatus() {
+ try {
+ return transaction.getStatus();
+ }
+ catch (SystemException e) {
+ log.error("could not get transaction status", e);
+ return Status.STATUS_UNKNOWN;
+ }
}
- void beginUserTransaction() {
+ protected Exception commit() {
+ log.debug("committing " + transaction);
try {
- log.debug("begin user transaction");
- userTransaction = ((JtaDbPersistenceServiceFactory) persistenceServiceFactory)
- .getUserTransaction();
- userTransaction.begin();
- } catch (Exception e) {
- throw new JbpmException("couldn't begin user transaction", e);
+ transaction.commit();
+ return null;
}
- }
-
- void endUserTransaction() {
- if (isRollbackOnly() || JTAHelper.isRollback(getUserTransactionStatus())) {
- log.debug("rolling back user transaction");
- try {
- userTransaction.rollback();
- } catch (Exception e) {
- throw new JbpmException("couldn't rollback user transaction", e);
+ catch (Exception e) {
+ if (Services.isCausedByStaleState(e)) {
+ log.info("optimistic locking failed, could not commit " +
transaction);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed, could not commit " + transaction, e);
}
- } else {
- log.debug("committing user transaction");
- try {
- userTransaction.commit();
- } catch (Exception e) {
- throw new JbpmException("couldn't commit user transaction", e);
+ else {
+ log.error("transaction commit failed", e);
}
+ return e;
}
}
- int getUserTransactionStatus() {
+ protected Exception rollback() {
+ log.debug("rolling back " + transaction);
try {
- return userTransaction.getStatus();
- } catch (SystemException e) {
- throw new JbpmException("couldn't get status for user transaction",
e);
+ transaction.rollback();
+ return null;
}
+ catch (Exception e) {
+ log.error("transaction rollback failed", e);
+ return e;
+ }
}
public boolean isJtaTxCreated() {
- return userTransaction != null;
+ return !isTransactionManagedExternally();
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java 2009-01-27 10:14:30
UTC (rev 3723)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java 2009-01-28 03:17:25
UTC (rev 3724)
@@ -68,11 +68,11 @@
private static List<SaveOperation> createDefaultSaveOperations() {
SaveOperation[] operations = new SaveOperation[4];
operations[0] = new CheckUnpersistableVariablesOperation();
- // first we save the runtime data (process instance)
+ // first, save the execution data (process instance)
operations[1] = new HibernateSaveOperation();
- // then we insert the logs cause the logs can have references
- // to the runtime data
+ // then, insert the logs, which may have references to the execution data
operations[2] = new SaveLogsOperation();
+ // last, save subprocess instances in cascade
operations[3] = new CascadeSaveOperation();
return Arrays.asList(operations);
}
@@ -246,9 +246,9 @@
// if this is a stale state exception, the jbpm configuration has control
over the
// logging
if (isCausedByStaleState(e)) {
- log.info("problem closing service '" + serviceName +
"': optimistic locking failed");
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
- .error("problem closing service '" + serviceName +
"': optimistic locking failed", e);
+ log.info("optimistic locking failed, could not close service: " +
serviceName);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+ "optimistic locking failed, could not close service: " +
serviceName, e);
}
else {
log.error("problem closing service '" + serviceName +
"'", e);
@@ -258,8 +258,8 @@
}
}
catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and
mask the
- // original Error.
+ // NOTE that Error's are not caught because that might halt the JVM
+ // and mask the original Error.
log.error("problem closing service '" + serviceName +
"'", e);
if (firstException == null) {
firstException = e;
@@ -274,10 +274,9 @@
}
}
- public static boolean isCausedByStaleState(JbpmPersistenceException
persistenceException) {
- for (Throwable cause = persistenceException.getCause(); cause != null; cause =
cause.getCause()) {
- if (cause instanceof StaleStateException)
- return true;
+ public static boolean isCausedByStaleState(Exception exception) {
+ for (Throwable cause = exception.getCause(); cause != null; cause = cause.getCause())
{
+ if (cause instanceof StaleStateException) return true;
}
return false;
}
@@ -285,7 +284,7 @@
public static void assignId(Object object) {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext != null) {
- // give this process instance an id
+ // assign id to the given object
Services services = jbpmContext.getServices();
if (services.hasService(Services.SERVICENAME_PERSISTENCE)) {
PersistenceService persistenceService = services.getPersistenceService();
Deleted: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java 2009-01-27
10:14:30 UTC (rev 3723)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -1,52 +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.util;
-
-public class ArrayUtil {
-
- private ArrayUtil() {
- // hide default constructor to prevent instantiation
- }
-
- public static String toString(Object[] array) {
- if (array==null) {
- return "null";
- } else {
- StringBuffer buffer = new StringBuffer();
- buffer.append("<[");
- for (int i=0; i<array.length; i++) {
- Object o = array[i];
- if (o!=null) {
- buffer.append(o);
- } else {
- buffer.append("null");
- }
- if (i!=array.length-1) {
- buffer.append("|");
- }
- }
- buffer.append("]>");
- return buffer.toString();
- }
- }
-
-}
Modified: jbpm3/trunk/modules/core/src/main/resources/hibernate.properties.postgresql.xml
===================================================================
---
jbpm3/trunk/modules/core/src/main/resources/hibernate.properties.postgresql.xml 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/main/resources/hibernate.properties.postgresql.xml 2009-01-28
03:17:25 UTC (rev 3724)
@@ -15,4 +15,3 @@
<property
name="hibernate.connection.username">${jdbc.postgresql.username}</property>
<property
name="hibernate.connection.password">${jdbc.postgresql.password}</property>
<!-- JDBC connection properties (end) -->
-
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Invocation.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Invocation.java 2009-01-27
10:14:30 UTC (rev 3723)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Invocation.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -21,55 +21,52 @@
*/
package org.jbpm.mock;
-import java.util.Iterator;
+import java.util.Arrays;
import java.util.List;
-import org.jbpm.util.ArrayUtil;
-
public class Invocation {
String methodName = null;
Object[] args = null;
-
+
public Invocation(String method) {
this.methodName = method;
}
+
public Invocation(String method, Object[] args) {
this.methodName = method;
this.args = args;
}
-
+
public String getMethodName() {
return methodName;
}
-
+
public Object getArg(int i) {
return args[i];
}
-
+
public String toString() {
- if (args!=null) {
- return methodName+ArrayUtil.toString(args);
- } else {
- return methodName+"()";
+ if (args != null) {
+ return methodName + Arrays.toString(args);
}
+ else {
+ return methodName + "[]";
+ }
}
-
- public static Invocation getInvocation(List invocations, String methodName, int index)
{
- Invocation i = null;
+
+ public static Invocation getInvocation(List<Invocation> invocations, String
methodName, int index) {
int count = 0;
- Iterator iter = invocations.iterator();
- while (i==null && iter.hasNext()) {
- Invocation invocation = (Invocation) iter.next();
+ for (Invocation invocation : invocations) {
if (methodName.equals(invocation.getMethodName())) {
-
- if (count==index) {
- i = invocation;
- } else {
+ if (count == index) {
+ return invocation;
+ }
+ else {
count++;
}
}
}
- return i;
+ return null;
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Recorded.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Recorded.java 2009-01-27 10:14:30
UTC (rev 3723)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/mock/Recorded.java 2009-01-28 03:17:25
UTC (rev 3724)
@@ -25,5 +25,6 @@
public interface Recorded {
- List getInvocations();
+ List<Invocation> getInvocations();
+
}
Modified:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/persistence/db/PersistenceServiceDbTest.java
===================================================================
---
jbpm3/trunk/modules/core/src/test/java/org/jbpm/persistence/db/PersistenceServiceDbTest.java 2009-01-27
10:14:30 UTC (rev 3723)
+++
jbpm3/trunk/modules/core/src/test/java/org/jbpm/persistence/db/PersistenceServiceDbTest.java 2009-01-28
03:17:25 UTC (rev 3724)
@@ -22,6 +22,7 @@
package org.jbpm.persistence.db;
import java.sql.Connection;
+import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
@@ -38,21 +39,20 @@
import org.jbpm.svc.Services;
public class PersistenceServiceDbTest extends AbstractJbpmTestCase {
-
- public void testDefaults() throws Exception {
+
+ public void testDefaults() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceServiceFactory persistenceServiceFactory = null;
DbPersistenceService persistenceService = null;
-
try {
persistenceServiceFactory = (DbPersistenceServiceFactory)
jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
-
+
assertNotNull(persistenceService);
assertSame(persistenceServiceFactory,
persistenceService.persistenceServiceFactory);
-
+
assertNull(persistenceServiceFactory.configuration);
assertNull(persistenceServiceFactory.dataSource);
assertNull(persistenceServiceFactory.dataSourceJndiName);
@@ -67,12 +67,12 @@
assertNull(persistenceService.loggingSession);
assertNull(persistenceService.jobSession);
assertNull(persistenceService.taskMgmtSession);
-
+
Session session = persistenceService.getSession();
assertSame(session, persistenceService.session);
assertNull(persistenceService.connection);
-
+
assertNotNull(persistenceServiceFactory.configuration);
assertNotNull(persistenceServiceFactory.sessionFactory);
assertNotNull(persistenceService.transaction);
@@ -88,13 +88,13 @@
assertNull(persistenceService.loggingSession);
assertNull(persistenceService.jobSession);
assertNull(persistenceService.taskMgmtSession);
-
+
assertTrue(persistenceService.transaction.isActive());
assertTrue(persistenceService.session.isOpen());
assertFalse(persistenceService.transaction.wasCommitted());
assertFalse(persistenceService.transaction.wasRolledBack());
-
- } finally {
+ }
+ finally {
jbpmContext.close();
}
@@ -108,33 +108,32 @@
assertFalse(persistenceService.session.isConnected());
}
- public void testRollbackWithoutSessionCreation() throws Exception {
+ public void testRollbackWithoutSessionCreation() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceService persistenceService = null;
-
try {
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
-
jbpmContext.setRollbackOnly();
- } finally {
+ }
+ finally {
jbpmContext.close();
}
assertNull(persistenceService.transaction);
}
- public void testRollback() throws Exception {
+ public void testRollback() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceService persistenceService = null;
-
try {
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
jbpmContext.setRollbackOnly();
persistenceService.getSession();
- } finally {
+ }
+ finally {
jbpmContext.close();
}
@@ -143,14 +142,13 @@
assertTrue(persistenceService.transaction.wasRolledBack());
assertFalse(persistenceService.session.isOpen());
}
-
- public void testUserSuppliedConnection() throws Exception {
+
+ public void testUserSuppliedConnection() throws SQLException {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceService persistenceService = null;
- Recorded recordedConnection = null;
-
+ Recorded recordedConnection = null;
try {
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
@@ -159,29 +157,28 @@
persistenceService.setConnection(connection);
Session session = persistenceService.getSession();
-
+
assertNotNull(persistenceService.transaction);
assertSame(session, persistenceService.session);
recordedConnection = (Recorded) connection;
- List invocations = recordedConnection.getInvocations();
+ List<Invocation> invocations = recordedConnection.getInvocations();
assertNull(Invocation.getInvocation(invocations, "commit", 0));
-
- } finally {
+ }
+ finally {
jbpmContext.close();
}
- List invocations = recordedConnection.getInvocations();
+ List<Invocation> invocations = recordedConnection.getInvocations();
assertNotNull(Invocation.getInvocation(invocations, "commit", 0));
assertNull(Invocation.getInvocation(invocations, "close", 0));
}
-
- public void testUserSuppliedConnectionWithRollback() throws Exception {
+
+ public void testUserSuppliedConnectionWithRollback() throws SQLException {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceService persistenceService = null;
- Recorded recordedConnection = null;
-
+ Recorded recordedConnection = null;
try {
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
@@ -191,92 +188,93 @@
Session session = persistenceService.getSession();
jbpmContext.setRollbackOnly();
-
+
assertNotNull(persistenceService.transaction);
assertSame(session, persistenceService.session);
- recordedConnection = (Recorded)connection;
- List invocations = recordedConnection.getInvocations();
+ recordedConnection = (Recorded) connection;
+ List<Invocation> invocations = recordedConnection.getInvocations();
assertNull(Invocation.getInvocation(invocations, "commit", 0));
assertNull(Invocation.getInvocation(invocations, "rollback", 0));
- } finally {
+ }
+ finally {
jbpmContext.close();
}
-
- List invocations = recordedConnection.getInvocations();
+
+ List<Invocation> invocations = recordedConnection.getInvocations();
assertNull(Invocation.getInvocation(invocations, "commit", 0));
assertNotNull(Invocation.getInvocation(invocations, "rollback", 0));
}
-
- public void testUserSuppliedSession() throws Exception {
+
+ public void testUserSuppliedSession() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
DbPersistenceService persistenceService = null;
-
try {
persistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
DbPersistenceServiceFactory persistenceServiceFactory =
(DbPersistenceServiceFactory)
jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
- SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
- Session session = sessionFactory.openSession();
-
+ Session session = persistenceServiceFactory.getSessionFactory().openSession();
+
jbpmContext.setSession(session);
-
+
persistenceService.getSession();
assertNull(persistenceService.transaction);
-
- } finally {
+ }
+ finally {
jbpmContext.close();
}
- persistenceService.close();
assertNull(persistenceService.transaction);
assertNotNull(persistenceService.session);
assertTrue(persistenceService.session.isOpen());
}
- public void testUserSuppliedSessionWithRollback() throws Exception {
+ public void testUserSuppliedSessionWithRollback() throws SQLException {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
+
try {
DbPersistenceServiceFactory persistenceServiceFactory =
(DbPersistenceServiceFactory)
jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
-
+
DataSource dataSource = Jdbc.createRecordedDataSource();
Connection connection = dataSource.getConnection();
Session session = sessionFactory.openSession(connection);
jbpmContext.setSession(session);
jbpmContext.setRollbackOnly();
-
- } finally {
+ }
+ finally {
try {
jbpmContext.close();
fail("expected exception");
- } catch (JbpmException e) {
+ }
+ catch (JbpmException e) {
// OK
}
}
}
- public void testTransferResponsibility() throws Exception {
+ public void testTransferResponsibility() throws SQLException {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
- DbPersistenceService dbPersistenceService = null;
- Connection connection = null;
+
+ DbPersistenceService dbPersistenceService;
+ Connection connection;
try {
- dbPersistenceService = (DbPersistenceService)
jbpmContext.getServices().getPersistenceService();
+ dbPersistenceService = (DbPersistenceService) jbpmContext.getServices()
+ .getPersistenceService();
connection = jbpmContext.getConnection();
- } finally {
+ }
+ finally {
jbpmContext.close();
}
assertFalse(dbPersistenceService.session.isOpen());
assertFalse(dbPersistenceService.session.isConnected());
- // Since 3.2.1, hibernate hides direct access to the connecion after session has
closed. Bummer...
- // assertFalse(connection.isClosed());
+
+ connection.close();
}
}