| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.batch.item.database.ExtendedConnectionDataSourceProxy
public class ExtendedConnectionDataSourceProxy
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 need to
 use a NativeJdbcExtractor.
getConnection(), 
Connection.close(), 
DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource), 
NativeJdbcExtractor| Constructor Summary | |
|---|---|
| ExtendedConnectionDataSourceProxy()No arg constructor for use when configured using JavaBean style. | |
| ExtendedConnectionDataSourceProxy(DataSource dataSource)Constructor that takes as a parameter with the {&link DataSource} to be wrapped. | |
| Method Summary | ||
|---|---|---|
|  void | afterPropertiesSet() | |
| protected  Connection | getCloseSuppressingConnectionProxy(Connection target)Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls. | |
|  Connection | getConnection() | |
|  Connection | getConnection(String username,
              String password) | |
|  int | getLoginTimeout() | |
|  PrintWriter | getLogWriter() | |
|  Logger | getParentLogger()Added due to JDK 7 compatibility, sadly a proper implementation that would throw SqlFeatureNotSupportedException is not possible in Java 5 (the class was added in Java 6). | |
|  boolean | isCloseSuppressionActive(Connection connection)Return the status of close suppression being activated for a given Connection | |
|  boolean | isWrapperFor(Class<?> iface)Performs only a 'shallow' non-recursive check of self's and delegate's class to retain Java 5 compatibility. | |
|  void | setDataSource(DataSource dataSource)Setter for the {&link DataSource} that is to be wrapped. | |
|  void | setLoginTimeout(int seconds) | |
|  void | setLogWriter(PrintWriter out) | |
|  boolean | shouldClose(Connection connection) | |
|  void | startCloseSuppression(Connection connection) | |
|  void | stopCloseSuppression(Connection connection) | |
| 
 | unwrap(Class<T> iface)Returns either self or delegate (in this order) if one of them can be cast to supplied parameter class. | |
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public ExtendedConnectionDataSourceProxy()
public ExtendedConnectionDataSourceProxy(DataSource dataSource)
| Method Detail | 
|---|
public void setDataSource(DataSource dataSource)
dataSource - the DataSourcepublic boolean shouldClose(Connection connection)
shouldClose in interface SmartDataSourceSmartDataSourcepublic boolean isCloseSuppressionActive(Connection connection)
Connection
connection - the Connection that the close suppression
 status is requested for
public void startCloseSuppression(Connection connection)
connection - the Connection that close suppression is
 requested forpublic void stopCloseSuppression(Connection connection)
connection - the Connection that close suppression should be
 turned off for
public Connection getConnection()
                         throws SQLException
getConnection in interface DataSourceSQLException
public Connection getConnection(String username,
                                String password)
                         throws SQLException
getConnection in interface DataSourceSQLException
public PrintWriter getLogWriter()
                         throws SQLException
getLogWriter in interface CommonDataSourceSQLException
public int getLoginTimeout()
                    throws SQLException
getLoginTimeout in interface CommonDataSourceSQLException
public void setLogWriter(PrintWriter out)
                  throws SQLException
setLogWriter in interface CommonDataSourceSQLException
public void setLoginTimeout(int seconds)
                     throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionprotected Connection getCloseSuppressingConnectionProxy(Connection target)
target - the original Connection to wrap
public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
isWrapperFor in interface WrapperSQLException
public <T> T unwrap(Class<T> iface)
         throws SQLException
unwrap in interface WrapperSQLException
public void afterPropertiesSet()
                        throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic Logger getParentLogger()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||