类 IsolationLevelDataSourceAdapter
- java.lang.Object
- org.springframework.jdbc.datasource.DelegatingDataSource
- org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter
- org.springframework.jdbc.datasource.IsolationLevelDataSourceAdapter
- 所有已实现的接口:
Wrapper
,CommonDataSource
,DataSource
,InitializingBean
- 直接已知子类:
WebSphereDataSourceAdapter
public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAdapter
An adapter for a targetDataSource
, applying the current Spring transaction's isolation level (and potentially specified user credentials) to everygetConnection
call. Also applies the read-only flag, if specified.Can be used to proxy a target JNDI DataSource that does not have the desired isolation level (and user credentials) configured. Client code can work with this DataSource as usual, not worrying about such settings.
Inherits the capability to apply specific user credentials from its superclass
UserCredentialsDataSourceAdapter
; see the latter's javadoc for details on that functionality (e.g.UserCredentialsDataSourceAdapter.setCredentialsForCurrentThread(java.lang.String, java.lang.String)
).WARNING: This adapter simply calls
Connection.setTransactionIsolation(int)
and/orConnection.setReadOnly(boolean)
for every Connection obtained from it. It does, however, not reset those settings; it rather expects the target DataSource to perform such resetting as part of its connection pool handling. Make sure that the target DataSource properly cleans up such transaction state.
构造器概要
构造器 构造器 说明 IsolationLevelDataSourceAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Connection
doGetConnection(String username, String password)
Applies the current isolation level value and read-only flag to the returned Connection.protected Integer
getCurrentIsolationLevel()
Determine the current isolation level: either the transaction's isolation level or a statically defined isolation level.protected Boolean
getCurrentReadOnlyFlag()
Determine the current read-only flag: by default, the transaction's read-only hint.protected Integer
getIsolationLevel()
Return the statically specified isolation level, ornull
if none.void
setIsolationLevel(int isolationLevel)
Specify the default isolation level to use for Connection retrieval, according to the JDBCConnection
constants (equivalent to the corresponding SpringTransactionDefinition
constants).void
setIsolationLevelName(String constantName)
Set the default isolation level by the name of the corresponding constant inTransactionDefinition
, e.g.从类继承的方法 org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter
getConnection, getConnection, removeCredentialsFromCurrentThread, setCatalog, setCredentialsForCurrentThread, setPassword, setSchema, setUsername
从类继承的方法 org.springframework.jdbc.datasource.DelegatingDataSource
afterPropertiesSet, getLoginTimeout, getLogWriter, getParentLogger, getTargetDataSource, isWrapperFor, setLoginTimeout, setLogWriter, setTargetDataSource, unwrap
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 javax.sql.CommonDataSource
createShardingKeyBuilder
从接口继承的方法 javax.sql.DataSource
createConnectionBuilder
构造器详细资料
IsolationLevelDataSourceAdapter
public IsolationLevelDataSourceAdapter()
方法详细资料
setIsolationLevelName
public final void setIsolationLevelName(String constantName) throws IllegalArgumentException
Set the default isolation level by the name of the corresponding constant inTransactionDefinition
, e.g. "ISOLATION_SERIALIZABLE".If not specified, the target DataSource's default will be used. Note that a transaction-specific isolation value will always override any isolation setting specified at the DataSource level.
setIsolationLevel
public void setIsolationLevel(int isolationLevel)
Specify the default isolation level to use for Connection retrieval, according to the JDBCConnection
constants (equivalent to the corresponding SpringTransactionDefinition
constants).If not specified, the target DataSource's default will be used. Note that a transaction-specific isolation value will always override any isolation setting specified at the DataSource level.
- 另请参阅:
Connection.TRANSACTION_READ_UNCOMMITTED
,Connection.TRANSACTION_READ_COMMITTED
,Connection.TRANSACTION_REPEATABLE_READ
,Connection.TRANSACTION_SERIALIZABLE
,TransactionDefinition.ISOLATION_READ_UNCOMMITTED
,TransactionDefinition.ISOLATION_READ_COMMITTED
,TransactionDefinition.ISOLATION_REPEATABLE_READ
,TransactionDefinition.ISOLATION_SERIALIZABLE
,TransactionDefinition.getIsolationLevel()
,TransactionSynchronizationManager.getCurrentTransactionIsolationLevel()
getIsolationLevel
protected Integer getIsolationLevel()
Return the statically specified isolation level, ornull
if none.
doGetConnection
protected Connection doGetConnection(String username, String password) throws SQLException
Applies the current isolation level value and read-only flag to the returned Connection.- 覆盖:
doGetConnection
在类中UserCredentialsDataSourceAdapter
- 参数:
username
- the username to usepassword
- the password to use- 返回:
- the Connection
- 抛出:
SQLException
- 另请参阅:
getCurrentIsolationLevel()
,getCurrentReadOnlyFlag()
getCurrentIsolationLevel
protected Integer getCurrentIsolationLevel()
Determine the current isolation level: either the transaction's isolation level or a statically defined isolation level.- 返回:
- the current isolation level, or
null
if none - 另请参阅:
TransactionSynchronizationManager.getCurrentTransactionIsolationLevel()
,setIsolationLevel(int)
getCurrentReadOnlyFlag
protected Boolean getCurrentReadOnlyFlag()
Determine the current read-only flag: by default, the transaction's read-only hint.- 返回:
- whether there is a read-only hint for the current scope
- 另请参阅:
TransactionSynchronizationManager.isCurrentTransactionReadOnly()