Consistent reset of resource holders on doBegin failure

Issue: SPR-12280
master
Juergen Hoeller 10 years ago
parent 1e9e6c9f6b
commit e58b33a593
  1. 12
      spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java
  2. 1
      spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateTransactionManager.java
  3. 3
      spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTransactionManager.java
  4. 10
      spring-orm/src/main/java/org/springframework/orm/jdo/JdoTransactionManager.java
  5. 12
      spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java
  6. 7
      spring-tx/src/main/java/org/springframework/jca/cci/connection/CciLocalTransactionManager.java

@ -178,6 +178,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
throw new InvalidIsolationLevelException("JMS does not support an isolation level concept");
}
JmsTransactionObject txObject = (JmsTransactionObject) transaction;
Connection con = null;
Session session = null;
@ -193,10 +194,17 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
txObject.getResourceHolder().setTimeoutInSeconds(timeout);
}
TransactionSynchronizationManager.bindResource(
getConnectionFactory(), txObject.getResourceHolder());
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getResourceHolder());
}
catch (Throwable ex) {
if (session != null) {
try {
session.close();
}
catch (Throwable ex2) {
// ignore
}
}
if (con != null) {
try {
con.close();

@ -513,6 +513,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
}
finally {
SessionFactoryUtils.closeSession(session);
txObject.setSessionHolder(null);
}
}
throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -596,6 +596,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
}
finally {
SessionFactoryUtils.closeSession(session);
txObject.setSessionHolder(null);
}
}
throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -341,15 +341,16 @@ public class JdoTransactionManager extends AbstractPlatformTransactionManager
conHolder.setTimeoutInSeconds(timeoutToUse);
}
if (logger.isDebugEnabled()) {
logger.debug("Exposing JDO transaction as JDBC transaction [" + conHolder.getConnectionHandle() + "]");
logger.debug("Exposing JDO transaction as JDBC transaction [" +
conHolder.getConnectionHandle() + "]");
}
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
txObject.setConnectionHolder(conHolder);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Not exposing JDO transaction [" + pm + "] as JDBC transaction because JdoDialect [" +
getJdoDialect() + "] does not support JDBC Connection retrieval");
logger.debug("Not exposing JDO transaction [" + pm + "] as JDBC transaction because " +
"JdoDialect [" + getJdoDialect() + "] does not support JDBC Connection retrieval");
}
}
}
@ -391,6 +392,7 @@ public class JdoTransactionManager extends AbstractPlatformTransactionManager
finally {
PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
}
txObject.setPersistenceManagerHolder(null, false);
}
}

@ -331,8 +331,8 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
TransactionSynchronizationManager.getResource(getEntityManagerFactory());
if (emHolder != null) {
if (logger.isDebugEnabled()) {
logger.debug("Found thread-bound EntityManager [" +
emHolder.getEntityManager() + "] for JPA transaction");
logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
"] for JPA transaction");
}
txObject.setEntityManagerHolder(emHolder, false);
}
@ -400,15 +400,16 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
conHolder.setTimeoutInSeconds(timeoutToUse);
}
if (logger.isDebugEnabled()) {
logger.debug("Exposing JPA transaction as JDBC transaction [" + conHolder.getConnectionHandle() + "]");
logger.debug("Exposing JPA transaction as JDBC transaction [" +
conHolder.getConnectionHandle() + "]");
}
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
txObject.setConnectionHolder(conHolder);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Not exposing JPA transaction [" + em + "] as JDBC transaction because JpaDialect [" +
getJpaDialect() + "] does not support JDBC Connection retrieval");
logger.debug("Not exposing JPA transaction [" + em + "] as JDBC transaction because " +
"JpaDialect [" + getJpaDialect() + "] does not support JDBC Connection retrieval");
}
}
}
@ -467,6 +468,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
finally {
EntityManagerFactoryUtils.closeEntityManager(em);
}
txObject.setEntityManagerHolder(null, false);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -126,7 +126,7 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
protected Object doGetTransaction() {
CciLocalTransactionObject txObject = new CciLocalTransactionObject();
ConnectionHolder conHolder =
(ConnectionHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
(ConnectionHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
txObject.setConnectionHolder(conHolder);
return txObject;
}
@ -159,7 +159,6 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
}
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
}
catch (NotSupportedException ex) {
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
@ -268,7 +267,7 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
}
public ConnectionHolder getConnectionHolder() {
return connectionHolder;
return this.connectionHolder;
}
}

Loading…
Cancel
Save