Skip to content

Commit 1716c17

Browse files
committed
LazyConnectionDataSourceProxy catches setReadOnly exception analogous to DataSourceUtils
Also mentioning JDBC 4's unwrap method for obtaining the native connection now. Issue: SPR-10312
1 parent e0c7571 commit 1716c17

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,18 +66,17 @@
6666
* You will get the same effect with non-transactional reads, but lazy fetching
6767
* of JDBC Connections allows you to still perform reads in transactions.
6868
*
69-
* <p><b>NOTE:</b> This DataSource proxy needs to return wrapped Connections to
70-
* handle lazy fetching of an actual JDBC Connection. Therefore, the returned
71-
* Connections cannot be cast to a native JDBC Connection type like OracleConnection,
72-
* or to a connection pool implementation type. Use a corresponding
73-
* NativeJdbcExtractor to retrieve the native JDBC Connection.
69+
* <p><b>NOTE:</b> This DataSource proxy needs to return wrapped Connections
70+
* (which implement the {@link ConnectionProxy} interface) in order to handle
71+
* lazy fetching of an actual JDBC Connection. Therefore, the returned Connections
72+
* cannot be cast to a native JDBC Connection type such as OracleConnection or
73+
* to a connection pool implementation type. Use a corresponding
74+
* {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
75+
* or JDBC 4's {@link Connection#unwrap} to retrieve the native JDBC Connection.
7476
*
7577
* @author Juergen Hoeller
7678
* @since 1.1.4
77-
* @see ConnectionProxy
7879
* @see DataSourceTransactionManager
79-
* @see org.springframework.orm.hibernate3.HibernateTransactionManager
80-
* @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
8180
*/
8281
public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
8382

@@ -407,7 +406,13 @@ private Connection getTargetConnection(Method operation) throws SQLException {
407406

408407
// Apply kept transaction settings, if any.
409408
if (this.readOnly) {
410-
this.target.setReadOnly(this.readOnly);
409+
try {
410+
this.target.setReadOnly(this.readOnly);
411+
}
412+
catch (Exception ex) {
413+
// "read-only not supported" -> ignore, it's just a hint anyway
414+
logger.debug("Could not set JDBC Connection read-only", ex);
415+
}
411416
}
412417
if (this.transactionIsolation != null &&
413418
!this.transactionIsolation.equals(defaultTransactionIsolation())) {

0 commit comments

Comments
 (0)