Resource-based PlatformTransactionManager implementations defensively catch Throwable in doBegin in order to reliably close resource in case of OutOfMemoryError

Issue: SPR-10755
This commit is contained in:
Juergen Hoeller 2013-07-24 14:39:15 +02:00 committed by unknown
parent 504d5da71f
commit 2e4eb9fc10
7 changed files with 10 additions and 11 deletions

View File

@ -238,7 +238,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
} }
} }
catch (Exception ex) { catch (Throwable ex) {
DataSourceUtils.releaseConnection(con, this.dataSource); DataSourceUtils.releaseConnection(con, this.dataSource);
throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex); throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 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.
@ -196,7 +196,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
TransactionSynchronizationManager.bindResource( TransactionSynchronizationManager.bindResource(
getConnectionFactory(), txObject.getResourceHolder()); getConnectionFactory(), txObject.getResourceHolder());
} }
catch (JMSException ex) { catch (Throwable ex) {
if (con != null) { if (con != null) {
try { try {
con.close(); con.close();

View File

@ -500,7 +500,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
txObject.getSessionHolder().setSynchronizedWithTransaction(true); txObject.getSessionHolder().setSynchronizedWithTransaction(true);
} }
catch (Exception ex) { catch (Throwable ex) {
if (txObject.isNewSession()) { if (txObject.isNewSession()) {
try { try {
if (session.getTransaction().isActive()) { if (session.getTransaction().isActive()) {

View File

@ -583,7 +583,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
txObject.getSessionHolder().setSynchronizedWithTransaction(true); txObject.getSessionHolder().setSynchronizedWithTransaction(true);
} }
catch (Exception ex) { catch (Throwable ex) {
if (txObject.isNewSession()) { if (txObject.isNewSession()) {
try { try {
if (session.getTransaction().isActive()) { if (session.getTransaction().isActive()) {

View File

@ -366,7 +366,7 @@ public class JdoTransactionManager extends AbstractPlatformTransactionManager
closePersistenceManagerAfterFailedBegin(txObject); closePersistenceManagerAfterFailedBegin(txObject);
throw ex; throw ex;
} }
catch (Exception ex) { catch (Throwable ex) {
closePersistenceManagerAfterFailedBegin(txObject); closePersistenceManagerAfterFailedBegin(txObject);
throw new CannotCreateTransactionException("Could not open JDO PersistenceManager for transaction", ex); throw new CannotCreateTransactionException("Could not open JDO PersistenceManager for transaction", ex);
} }

View File

@ -425,7 +425,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
closeEntityManagerAfterFailedBegin(txObject); closeEntityManagerAfterFailedBegin(txObject);
throw ex; throw ex;
} }
catch (Exception ex) { catch (Throwable ex) {
closeEntityManagerAfterFailedBegin(txObject); closeEntityManagerAfterFailedBegin(txObject);
throw new CannotCreateTransactionException("Could not open JPA EntityManager for transaction", ex); throw new CannotCreateTransactionException("Could not open JPA EntityManager for transaction", ex);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 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.
@ -29,8 +29,8 @@ import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.TransactionSystemException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager; import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus; import org.springframework.transaction.support.DefaultTransactionStatus;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.ResourceTransactionManager; import org.springframework.transaction.support.ResourceTransactionManager;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/** /**
* {@link org.springframework.transaction.PlatformTransactionManager} implementation * {@link org.springframework.transaction.PlatformTransactionManager} implementation
@ -141,7 +141,6 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
@Override @Override
protected void doBegin(Object transaction, TransactionDefinition definition) { protected void doBegin(Object transaction, TransactionDefinition definition) {
CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction; CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
Connection con = null; Connection con = null;
try { try {
@ -169,7 +168,7 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory()); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex); throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex);
} }
catch (ResourceException ex) { catch (Throwable ex) {
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory()); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex); throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex);
} }