From 1716c171d8805049fc115942ebd96ecd793e926a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 1 Mar 2013 16:04:10 +0100 Subject: [PATCH] LazyConnectionDataSourceProxy catches setReadOnly exception analogous to DataSourceUtils Also mentioning JDBC 4's unwrap method for obtaining the native connection now. Issue: SPR-10312 --- .../LazyConnectionDataSourceProxy.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java index f6ddc15b34..5495aa68ce 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -66,18 +66,17 @@ import org.springframework.core.Constants; * You will get the same effect with non-transactional reads, but lazy fetching * of JDBC Connections allows you to still perform reads in transactions. * - *

NOTE: This DataSource proxy needs to return wrapped Connections to - * handle lazy fetching of an actual JDBC Connection. Therefore, the returned - * Connections cannot be cast to a native JDBC Connection type like OracleConnection, - * or to a connection pool implementation type. Use a corresponding - * NativeJdbcExtractor to retrieve the native JDBC Connection. + *

NOTE: This DataSource proxy needs to return wrapped Connections + * (which implement the {@link ConnectionProxy} interface) in order to handle + * lazy fetching of an actual JDBC Connection. Therefore, the returned Connections + * cannot be cast to a native JDBC Connection type such as OracleConnection or + * to a connection pool implementation type. Use a corresponding + * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor} + * or JDBC 4's {@link Connection#unwrap} to retrieve the native JDBC Connection. * * @author Juergen Hoeller * @since 1.1.4 - * @see ConnectionProxy * @see DataSourceTransactionManager - * @see org.springframework.orm.hibernate3.HibernateTransactionManager - * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor */ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { @@ -407,7 +406,13 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { // Apply kept transaction settings, if any. if (this.readOnly) { - this.target.setReadOnly(this.readOnly); + try { + this.target.setReadOnly(this.readOnly); + } + catch (Exception ex) { + // "read-only not supported" -> ignore, it's just a hint anyway + logger.debug("Could not set JDBC Connection read-only", ex); + } } if (this.transactionIsolation != null && !this.transactionIsolation.equals(defaultTransactionIsolation())) {