DataSourceUtils lets timeout exceptions through even for setReadOnly calls (revised; SPR-7226)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3364 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
db32d52375
commit
626d75ff61
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
|
|
@ -18,7 +18,6 @@ package org.springframework.jdbc.datasource;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
|
@ -236,7 +235,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
|
|||
}
|
||||
}
|
||||
|
||||
catch (SQLException ex) {
|
||||
catch (Exception ex) {
|
||||
DataSourceUtils.releaseConnection(con, this.dataSource);
|
||||
throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,14 +154,28 @@ public abstract class DataSourceUtils {
|
|||
}
|
||||
con.setReadOnly(true);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (ex instanceof SQLException && (ex.getClass().getSimpleName().contains("Timeout") ||
|
||||
(ex.getCause() != null && ex.getCause().getClass().getSimpleName().contains("Timeout")))) {
|
||||
// Assume it's a connection timeout that would otherwise get lost: e.g. from C3P0.
|
||||
throw (SQLException) ex;
|
||||
catch (SQLException ex) {
|
||||
Throwable exToCheck = ex;
|
||||
while (exToCheck != null) {
|
||||
if (exToCheck.getClass().getSimpleName().contains("Timeout")) {
|
||||
// Assume it's a connection timeout that would otherwise get lost: e.g. from JDBC 4.0
|
||||
throw ex;
|
||||
}
|
||||
exToCheck = exToCheck.getCause();
|
||||
}
|
||||
// "read-only not supported" SQLException or UnsupportedOperationException
|
||||
// -> ignore, it's just a hint anyway.
|
||||
// "read-only not supported" SQLException -> ignore, it's just a hint anyway
|
||||
logger.debug("Could not set JDBC Connection read-only", ex);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
Throwable exToCheck = ex;
|
||||
while (exToCheck != null) {
|
||||
if (exToCheck.getClass().getSimpleName().contains("Timeout")) {
|
||||
// Assume it's a connection timeout that would otherwise get lost: e.g. from Hibernate
|
||||
throw ex;
|
||||
}
|
||||
exToCheck = exToCheck.getCause();
|
||||
}
|
||||
// "read-only not supported" UnsupportedOperationException -> ignore, it's just a hint anyway
|
||||
logger.debug("Could not set JDBC Connection read-only", ex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue