类 ExtendedConnectionDataSourceProxy
- java.lang.Object
- org.springframework.batch.item.database.ExtendedConnectionDataSourceProxy
- 所有已实现的接口:
java.sql.Wrapper
,javax.sql.CommonDataSource
,javax.sql.DataSource
,org.springframework.beans.factory.InitializingBean
,org.springframework.jdbc.datasource.SmartDataSource
public class ExtendedConnectionDataSourceProxy extends java.lang.Object implements org.springframework.jdbc.datasource.SmartDataSource, org.springframework.beans.factory.InitializingBean
Implementation ofSmartDataSource
that is capable of keeping a single JDBC Connection which is NOT closed after each use even ifConnection.close()
is called. The connection can be kept open over multiple transactions when used together with any of Spring'sPlatformTransactionManager
implementations.Loosely based on the SingleConnectionDataSource implementation in Spring Core. Intended to be used with the
JdbcCursorItemReader
to provide a connection that remains open across transaction boundaries, It remains open for the life of the cursor, and can be shared with the main transaction of the rest of the step processing.Once close suppression has been turned on for a connection, it will be returned for the first
getConnection()
call. Any subsequent calls togetConnection()
will retrieve a new connection from the wrappedDataSource
until theDataSourceUtils
queries whether the connection should be closed or not by callingshouldClose(Connection)
for the close-suppressedConnection
. At that point the cycle starts over again, and the nextgetConnection()
call will have theConnection
that is being close-suppressed returned. This allows the use of the close-suppressedConnection
to be the mainConnection
for an extended data access process. The close suppression is turned off by callingstopCloseSuppression(Connection)
.This class is not multi-threading capable.
The connection returned will be a close-suppressing proxy instead of the physical
Connection
. Be aware that you will not be able to cast this to a nativeOracleConnection
or the like anymore; you'd be required to useWrapper.unwrap(Class)
.- 从以下版本开始:
- 2.0
- 作者:
- Thomas Risberg
- 另请参阅:
getConnection()
,Connection.close()
,DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)
,Wrapper.unwrap(Class)
构造器概要
构造器 构造器 说明 ExtendedConnectionDataSourceProxy()
No arg constructor for use when configured using JavaBean style.ExtendedConnectionDataSourceProxy(javax.sql.DataSource dataSource)
Constructor that takes as a parameter with theDataSource
to be wrapped.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
protected java.sql.Connection
getCloseSuppressingConnectionProxy(java.sql.Connection target)
Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls.java.sql.Connection
getConnection()
java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
int
getLoginTimeout()
java.io.PrintWriter
getLogWriter()
java.util.logging.Logger
getParentLogger()
Added due to JDK 7 compatibility.boolean
isCloseSuppressionActive(java.sql.Connection connection)
Return the status of close suppression being activated for a givenConnection
boolean
isWrapperFor(java.lang.Class<?> iface)
Performs only a 'shallow' non-recursive check of self's and delegate's class to retain Java 5 compatibility.void
setDataSource(javax.sql.DataSource dataSource)
Setter for theDataSource
that is to be wrapped.void
setLoginTimeout(int seconds)
void
setLogWriter(java.io.PrintWriter out)
boolean
shouldClose(java.sql.Connection connection)
void
startCloseSuppression(java.sql.Connection connection)
void
stopCloseSuppression(java.sql.Connection connection)
<T> T
unwrap(java.lang.Class<T> iface)
Returns either self or delegate (in this order) if one of them can be cast to supplied parameter class.
构造器详细资料
ExtendedConnectionDataSourceProxy
public ExtendedConnectionDataSourceProxy()
No arg constructor for use when configured using JavaBean style.
ExtendedConnectionDataSourceProxy
public ExtendedConnectionDataSourceProxy(javax.sql.DataSource dataSource)
Constructor that takes as a parameter with theDataSource
to be wrapped.- 参数:
dataSource
- DataSource to be used
方法详细资料
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
Setter for theDataSource
that is to be wrapped.- 参数:
dataSource
- the DataSource
shouldClose
public boolean shouldClose(java.sql.Connection connection)
- 指定者:
shouldClose
在接口中org.springframework.jdbc.datasource.SmartDataSource
- 另请参阅:
SmartDataSource
isCloseSuppressionActive
public boolean isCloseSuppressionActive(java.sql.Connection connection)
Return the status of close suppression being activated for a givenConnection
- 参数:
connection
- theConnection
that the close suppression status is requested for- 返回:
- true or false
startCloseSuppression
public void startCloseSuppression(java.sql.Connection connection)
- 参数:
connection
- theConnection
that close suppression is requested for
stopCloseSuppression
public void stopCloseSuppression(java.sql.Connection connection)
- 参数:
connection
- theConnection
that close suppression should be turned off for
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
- 指定者:
getConnection
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
- 指定者:
getConnection
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
- 指定者:
getLogWriter
在接口中javax.sql.CommonDataSource
- 指定者:
getLogWriter
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException
- 指定者:
getLoginTimeout
在接口中javax.sql.CommonDataSource
- 指定者:
getLoginTimeout
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
- 指定者:
setLogWriter
在接口中javax.sql.CommonDataSource
- 指定者:
setLogWriter
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException
- 指定者:
setLoginTimeout
在接口中javax.sql.CommonDataSource
- 指定者:
setLoginTimeout
在接口中javax.sql.DataSource
- 抛出:
java.sql.SQLException
getCloseSuppressingConnectionProxy
protected java.sql.Connection getCloseSuppressingConnectionProxy(java.sql.Connection target)
Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls.- 参数:
target
- the original Connection to wrap- 返回:
- the wrapped Connection
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
Performs only a 'shallow' non-recursive check of self's and delegate's class to retain Java 5 compatibility.- 指定者:
isWrapperFor
在接口中java.sql.Wrapper
- 抛出:
java.sql.SQLException
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
Returns either self or delegate (in this order) if one of them can be cast to supplied parameter class. Does *not* support recursive unwrapping of the delegate to retain Java 5 compatibility.- 指定者:
unwrap
在接口中java.sql.Wrapper
- 抛出:
java.sql.SQLException
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
Added due to JDK 7 compatibility.- 指定者:
getParentLogger
在接口中javax.sql.CommonDataSource
- 抛出:
java.sql.SQLFeatureNotSupportedException