Consistent reset of resource holders on doBegin failure
Issue: SPR-12280
(cherry picked from commit e58b33a)
This commit is contained in:
@@ -179,7 +179,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
|
||||
DataSourceTransactionObject txObject = new DataSourceTransactionObject();
|
||||
txObject.setSavepointAllowed(isNestedTransactionAllowed());
|
||||
ConnectionHolder conHolder =
|
||||
(ConnectionHolder) TransactionSynchronizationManager.getResource(this.dataSource);
|
||||
(ConnectionHolder) TransactionSynchronizationManager.getResource(this.dataSource);
|
||||
txObject.setConnectionHolder(conHolder, false);
|
||||
return txObject;
|
||||
}
|
||||
@@ -238,7 +238,10 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
|
||||
}
|
||||
|
||||
catch (Throwable ex) {
|
||||
DataSourceUtils.releaseConnection(con, this.dataSource);
|
||||
if (txObject.isNewConnectionHolder()) {
|
||||
DataSourceUtils.releaseConnection(con, this.dataSource);
|
||||
txObject.setConnectionHolder(null, false);
|
||||
}
|
||||
throw new CannotCreateTransactionException("Could not open JDBC Connection 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.
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user