提交 1716c171 编写于 作者: J Juergen Hoeller

LazyConnectionDataSourceProxy catches setReadOnly exception analogous to DataSourceUtils

Also mentioning JDBC 4's unwrap method for obtaining the native connection now.

Issue: SPR-10312
上级 e0c7571a
/*
* 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.
*
* <p><b>NOTE:</b> 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.
* <p><b>NOTE:</b> 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())) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册