From d7f72fbbd45798353ee5fea6686154426fd7bf65 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 20 May 2010 20:58:02 +0000 Subject: [PATCH] DataSourceUtils lets timeout exceptions through even for setReadOnly calls (SPR-7226) --- .../jdbc/datasource/DataSourceUtils.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java index 166803dbd0..bb79f43d87 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java @@ -51,8 +51,7 @@ import org.springframework.util.Assert; public abstract class DataSourceUtils { /** - * Order value for TransactionSynchronization objects that clean up - * JDBC Connections. + * Order value for TransactionSynchronization objects that clean up JDBC Connections. */ public static final int CONNECTION_SYNCHRONIZATION_ORDER = 1000; @@ -156,7 +155,12 @@ public abstract class DataSourceUtils { con.setReadOnly(true); } catch (Throwable ex) { - // SQLException or UnsupportedOperationException + 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; + } + // "read-only not supported" SQLException or UnsupportedOperationException // -> ignore, it's just a hint anyway. logger.debug("Could not set JDBC Connection read-only", ex); }