java.lang.Object | ||||
↳ | org.springframework.jdbc.datasource.AbstractDataSource | |||
↳ | org.springframework.jdbc.datasource.AbstractDriverBasedDataSource | |||
↳ | org.springframework.jdbc.datasource.DriverManagerDataSource | |||
↳ | org.springframework.jdbc.datasource.SingleConnectionDataSource |
Implementation of SmartDataSource
that wraps a single JDBC 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
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.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.datasource.AbstractDataSource
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for bean-style configuration.
| |||||||||||
This constructor is deprecated.
since Spring 2.5. Driver parameter usage is generally not recommended
for a SingleConnectionDataSource. If you insist on using driver parameters
directly, set up the Driver class manually before invoking this DataSource.
| |||||||||||
Create a new SingleConnectionDataSource with the given standard
DriverManager parameters.
| |||||||||||
Create a new SingleConnectionDataSource with the given standard
DriverManager parameters.
| |||||||||||
Create a new SingleConnectionDataSource with a given Connection.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Close the underlying Connection.
| |||||||||||
This implementation delegates to
getConnectionFromDriver ,
using the default username and password of this DataSource. | |||||||||||
Specifying a custom username and password doesn't make sense
with a single Connection.
| |||||||||||
Initialize the underlying Connection via the DriverManager.
| |||||||||||
Reset the underlying shared Connection, to be reinitialized on next access.
| |||||||||||
Set whether the returned Connection's "autoCommit" setting should be overridden.
| |||||||||||
Set whether the returned Connection should be a close-suppressing proxy
or the physical Connection.
| |||||||||||
This is a single Connection: Do not close it when returning to the "pool".
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return whether the returned Connection's "autoCommit" setting should be overridden.
| |||||||||||
Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls.
| |||||||||||
Return whether the returned Connection will be a close-suppressing proxy
or the physical Connection.
| |||||||||||
Prepare the given Connection before it is exposed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.datasource.DriverManagerDataSource
| |||||||||||
From class
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource
| |||||||||||
From class
org.springframework.jdbc.datasource.AbstractDataSource
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.sql.Wrapper
| |||||||||||
From interface
javax.sql.CommonDataSource
| |||||||||||
From interface
javax.sql.DataSource
| |||||||||||
From interface
org.springframework.beans.factory.DisposableBean
| |||||||||||
From interface
org.springframework.jdbc.datasource.SmartDataSource
|
Constructor for bean-style configuration.
This constructor is deprecated.
since Spring 2.5. Driver parameter usage is generally not recommended
for a SingleConnectionDataSource. If you insist on using driver parameters
directly, set up the Driver class manually before invoking this DataSource.
Create a new SingleConnectionDataSource with the given standard DriverManager parameters.
driverClassName | the JDBC driver class name |
---|---|
url | the JDBC URL to use for accessing the DriverManager |
username | the JDBC username to use for accessing the DriverManager |
password | the JDBC password to use for accessing the DriverManager |
suppressClose | if the returned Connection should be a close-suppressing proxy or the physical Connection |
Create a new SingleConnectionDataSource with the given standard DriverManager parameters.
url | the JDBC URL to use for accessing the DriverManager |
---|---|
username | the JDBC username to use for accessing the DriverManager |
password | the JDBC password to use for accessing the DriverManager |
suppressClose | if the returned Connection should be a close-suppressing proxy or the physical Connection |
Create a new SingleConnectionDataSource with the given standard DriverManager parameters.
url | the JDBC URL to use for accessing the DriverManager |
---|---|
suppressClose | if the returned Connection should be a close-suppressing proxy or the physical Connection |
Create a new SingleConnectionDataSource with a given Connection.
target | underlying target Connection |
---|---|
suppressClose | if the Connection should be wrapped with a Connection that
suppresses close() calls (to allow for normal close()
usage in applications that expect a pooled Connection but do not know our
SmartDataSource interface)
|
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.
This implementation delegates to getConnectionFromDriver
,
using the default username and password of this DataSource.
SQLException |
---|
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.
SQLException |
---|
Initialize the underlying Connection via the DriverManager.
SQLException |
---|
Reset the underlying shared Connection, to be reinitialized on next access.
Set whether the returned Connection's "autoCommit" setting should be overridden.
Set whether the returned Connection should be a close-suppressing proxy or the physical Connection.
This is a single Connection: Do not close it when returning to the "pool".
con | the Connection to check |
---|
Return whether the returned Connection's "autoCommit" setting should be overridden.
null
if none to be applied
Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls.
target | the original Connection to wrap |
---|
Return whether the returned Connection will be a close-suppressing proxy or the physical Connection.
Prepare the given Connection before it is exposed.
The default implementation applies the auto-commit flag, if necessary. Can be overridden in subclasses.
con | the Connection to prepare |
---|
SQLException |
---|