Class ExtendedConnectionDataSourceProxy

java.lang.Object
org.springframework.batch.item.database.ExtendedConnectionDataSourceProxy
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource, org.springframework.beans.factory.InitializingBean, org.springframework.jdbc.datasource.SmartDataSource

public class ExtendedConnectionDataSourceProxy extends Object implements org.springframework.jdbc.datasource.SmartDataSource, org.springframework.beans.factory.InitializingBean
Implementation of SmartDataSource that is capable of keeping a single JDBC Connection which is NOT closed after each use even if Connection.close() is called. The connection can be kept open over multiple transactions when used together with any of Spring's PlatformTransactionManager 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 to getConnection() will retrieve a new connection from the wrapped DataSource until the DataSourceUtils queries whether the connection should be closed or not by calling shouldClose(Connection) for the close-suppressed Connection. At that point the cycle starts over again, and the next getConnection() call will have the Connection that is being close-suppressed returned. This allows the use of the close-suppressed Connection to be the main Connection for an extended data access process. The close suppression is turned off by calling stopCloseSuppression(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 native OracleConnection or the like anymore; you'd be required to use Wrapper.unwrap(Class).

Since:
2.0
Author:
Thomas Risberg
See Also: