Consistent reset of resource holders on doBegin failure
Issue: SPR-12280
This commit is contained in:
@@ -178,6 +178,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
||||||
throw new InvalidIsolationLevelException("JMS does not support an isolation level concept");
|
throw new InvalidIsolationLevelException("JMS does not support an isolation level concept");
|
||||||
}
|
}
|
||||||
|
|
||||||
JmsTransactionObject txObject = (JmsTransactionObject) transaction;
|
JmsTransactionObject txObject = (JmsTransactionObject) transaction;
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
Session session = null;
|
Session session = null;
|
||||||
@@ -193,10 +194,17 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
|
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
|
||||||
txObject.getResourceHolder().setTimeoutInSeconds(timeout);
|
txObject.getResourceHolder().setTimeoutInSeconds(timeout);
|
||||||
}
|
}
|
||||||
TransactionSynchronizationManager.bindResource(
|
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getResourceHolder());
|
||||||
getConnectionFactory(), txObject.getResourceHolder());
|
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
|
if (session != null) {
|
||||||
|
try {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
catch (Throwable ex2) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
if (con != null) {
|
if (con != null) {
|
||||||
try {
|
try {
|
||||||
con.close();
|
con.close();
|
||||||
|
|||||||
@@ -513,6 +513,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
SessionFactoryUtils.closeSession(session);
|
SessionFactoryUtils.closeSession(session);
|
||||||
|
txObject.setSessionHolder(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -596,6 +596,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
SessionFactoryUtils.closeSession(session);
|
SessionFactoryUtils.closeSession(session);
|
||||||
|
txObject.setSessionHolder(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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);
|
conHolder.setTimeoutInSeconds(timeoutToUse);
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
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);
|
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
|
||||||
txObject.setConnectionHolder(conHolder);
|
txObject.setConnectionHolder(conHolder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Not exposing JDO transaction [" + pm + "] as JDBC transaction because JdoDialect [" +
|
logger.debug("Not exposing JDO transaction [" + pm + "] as JDBC transaction because " +
|
||||||
getJdoDialect() + "] does not support JDBC Connection retrieval");
|
"JdoDialect [" + getJdoDialect() + "] does not support JDBC Connection retrieval");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,6 +392,7 @@ public class JdoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
finally {
|
finally {
|
||||||
PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
|
PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
|
||||||
}
|
}
|
||||||
|
txObject.setPersistenceManagerHolder(null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -331,8 +331,8 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
TransactionSynchronizationManager.getResource(getEntityManagerFactory());
|
TransactionSynchronizationManager.getResource(getEntityManagerFactory());
|
||||||
if (emHolder != null) {
|
if (emHolder != null) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Found thread-bound EntityManager [" +
|
logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() +
|
||||||
emHolder.getEntityManager() + "] for JPA transaction");
|
"] for JPA transaction");
|
||||||
}
|
}
|
||||||
txObject.setEntityManagerHolder(emHolder, false);
|
txObject.setEntityManagerHolder(emHolder, false);
|
||||||
}
|
}
|
||||||
@@ -400,15 +400,16 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
conHolder.setTimeoutInSeconds(timeoutToUse);
|
conHolder.setTimeoutInSeconds(timeoutToUse);
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
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);
|
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
|
||||||
txObject.setConnectionHolder(conHolder);
|
txObject.setConnectionHolder(conHolder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Not exposing JPA transaction [" + em + "] as JDBC transaction because JpaDialect [" +
|
logger.debug("Not exposing JPA transaction [" + em + "] as JDBC transaction because " +
|
||||||
getJpaDialect() + "] does not support JDBC Connection retrieval");
|
"JpaDialect [" + getJpaDialect() + "] does not support JDBC Connection retrieval");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,6 +468,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
finally {
|
finally {
|
||||||
EntityManagerFactoryUtils.closeEntityManager(em);
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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() {
|
protected Object doGetTransaction() {
|
||||||
CciLocalTransactionObject txObject = new CciLocalTransactionObject();
|
CciLocalTransactionObject txObject = new CciLocalTransactionObject();
|
||||||
ConnectionHolder conHolder =
|
ConnectionHolder conHolder =
|
||||||
(ConnectionHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
|
(ConnectionHolder) TransactionSynchronizationManager.getResource(getConnectionFactory());
|
||||||
txObject.setConnectionHolder(conHolder);
|
txObject.setConnectionHolder(conHolder);
|
||||||
return txObject;
|
return txObject;
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,6 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
|
|||||||
}
|
}
|
||||||
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
|
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (NotSupportedException ex) {
|
catch (NotSupportedException ex) {
|
||||||
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
|
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
|
||||||
throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
|
throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
|
||||||
@@ -268,7 +267,7 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionHolder getConnectionHolder() {
|
public ConnectionHolder getConnectionHolder() {
|
||||||
return connectionHolder;
|
return this.connectionHolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user