| java.lang.Object org.springframework.jdbc.datasource.AbstractDataSource org.springframework.jdbc.datasource.DriverManagerDataSource org.springframework.jdbc.datasource.SingleConnectionDataSource
SingleConnectionDataSource | public class SingleConnectionDataSource extends DriverManagerDataSource implements SmartDataSource,DisposableBean(Code) | | Implementation of SmartDataSource that wraps a single Connection which is not
closed after use. Obviously, this is not multi-threading capable.
Note that at shutdown, someone should close the underlying Connection via the
close() method. Client code will never call close on the Connection
handle if it is SmartDataSource-aware (e.g. uses
DataSourceUtils.releaseConnection ).
If client code will call close() in the assumption of a pooled
Connection, like when using persistence tools, set "suppressClose" to "true".
This will return 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 for this then).
This is primarily intended for testing. For example, it enables easy testing
outside an application server, for code that expects to work on a DataSource.
In contrast to DriverManagerDataSource, it reuses the same Connection all the
time, avoiding excessive creation of physical Connections.
author: Rod Johnson author: Juergen Hoeller See Also: SingleConnectionDataSource.getConnection() See Also: java.sql.Connection.close See Also: DataSourceUtils.releaseConnection See Also: org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor |
Method Summary | |
public void | destroy() Close the underlying Connection. | protected Boolean | getAutoCommitValue() Return whether the returned Connection's "autoCommit" setting should be overridden. | protected Connection | getCloseSuppressingConnectionProxy(Connection target) Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls. | public Connection | getConnection() | public Connection | getConnection(String username, String password) Specifying a custom username and password doesn't make sense
with a single Connection. | public void | initConnection() Initialize the underlying Connection via the DriverManager. | protected boolean | isSuppressClose() Return whether the returned Connection will be a close-suppressing proxy
or the physical Connection. | protected void | prepareConnection(Connection con) Prepare the given Connection before it is exposed. | public void | resetConnection() Reset the underlying shared Connection, to be reinitialized on next access. | public void | setAutoCommit(boolean autoCommit) Set whether the returned Connection's "autoCommit" setting should be overridden. | public void | setSuppressClose(boolean suppressClose) Set whether the returned Connection should be a close-suppressing proxy
or the physical Connection. | public boolean | shouldClose(Connection con) This is a single Connection: Do not close it when returning to the "pool". |
SingleConnectionDataSource | public SingleConnectionDataSource()(Code) | | Constructor for bean-style configuration.
|
SingleConnectionDataSource | public SingleConnectionDataSource(String driverClassName, String url, String username, String password, boolean suppressClose) throws CannotGetJdbcConnectionException(Code) | | Create a new SingleConnectionDataSource with the given standard
DriverManager parameters.
Parameters: driverClassName - the JDBC driver class name Parameters: url - the JDBC URL to use for accessing the DriverManager Parameters: username - the JDBC username to use for accessing the DriverManager Parameters: password - the JDBC password to use for accessing the DriverManager Parameters: suppressClose - if the returned Connection should be aclose-suppressing proxy or the physical Connection See Also: java.sql.DriverManager.getConnection(StringStringString) |
SingleConnectionDataSource | public SingleConnectionDataSource(String url, String username, String password, boolean suppressClose) throws CannotGetJdbcConnectionException(Code) | | Create a new SingleConnectionDataSource with the given standard
DriverManager parameters.
Parameters: url - the JDBC URL to use for accessing the DriverManager Parameters: username - the JDBC username to use for accessing the DriverManager Parameters: password - the JDBC password to use for accessing the DriverManager Parameters: suppressClose - if the returned Connection should be aclose-suppressing proxy or the physical Connection See Also: java.sql.DriverManager.getConnection(StringStringString) |
SingleConnectionDataSource | public SingleConnectionDataSource(Connection target, boolean suppressClose)(Code) | | Create a new SingleConnectionDataSource with a given Connection.
Parameters: target - underlying target Connection Parameters: suppressClose - if the Connection should be wrapped with a Connection thatsuppresses close() calls (to allow for normal close() usage in applications that expect a pooled Connection but do not know ourSmartDataSource interface) |
destroy | public void destroy()(Code) | | Close the underlying Connection.
The provider of this DataSource needs to care for proper shutdown.
As this bean implements DisposableBean, a bean factory will
automatically invoke this on destruction of its cached singletons.
|
getAutoCommitValue | protected Boolean getAutoCommitValue()(Code) | | Return whether the returned Connection's "autoCommit" setting should be overridden.
the "autoCommit" value, or null if none to be applied |
getCloseSuppressingConnectionProxy | protected Connection getCloseSuppressingConnectionProxy(Connection target)(Code) | | Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls.
Parameters: target - the original Connection to wrap the wrapped Connection |
getConnection | public Connection getConnection(String username, String password) throws SQLException(Code) | | Specifying a custom username and password doesn't make sense
with a single Connection. Returns the single Connection if given
the same username and password; throws a SQLException else.
|
initConnection | public void initConnection() throws SQLException(Code) | | Initialize the underlying Connection via the DriverManager.
|
isSuppressClose | protected boolean isSuppressClose()(Code) | | Return whether the returned Connection will be a close-suppressing proxy
or the physical Connection.
|
prepareConnection | protected void prepareConnection(Connection con) throws SQLException(Code) | | Prepare the given Connection before it is exposed.
The default implementation applies the auto-commit flag, if necessary.
Can be overridden in subclasses.
Parameters: con - the Connection to prepare See Also: SingleConnectionDataSource.setAutoCommit |
resetConnection | public void resetConnection()(Code) | | Reset the underlying shared Connection, to be reinitialized on next access.
|
setAutoCommit | public void setAutoCommit(boolean autoCommit)(Code) | | Set whether the returned Connection's "autoCommit" setting should be overridden.
|
setSuppressClose | public void setSuppressClose(boolean suppressClose)(Code) | | Set whether the returned Connection should be a close-suppressing proxy
or the physical Connection.
|
shouldClose | public boolean shouldClose(Connection con)(Code) | | This is a single Connection: Do not close it when returning to the "pool".
|
Fields inherited from org.springframework.jdbc.datasource.AbstractDataSource | final protected Log logger(Code)(Java Doc)
|
|
|