public abstract class JdbcDaoSupport extends DaoSupport
Requires a DataSource
to be set, providing a
JdbcTemplate
based on it to
subclasses through the getJdbcTemplate()
method.
This base class is mainly intended for JdbcTemplate usage but can
also be used when working with a Connection directly or when using
org.springframework.jdbc.object
operation objects.
setDataSource(javax.sql.DataSource)
,
getJdbcTemplate()
,
JdbcTemplate
Modifier and Type | Field and Description |
---|---|
private JdbcTemplate |
jdbcTemplate |
logger
Constructor and Description |
---|
JdbcDaoSupport() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkDaoConfig()
Abstract subclasses must override this to check their configuration.
|
protected JdbcTemplate |
createJdbcTemplate(javax.sql.DataSource dataSource)
Create a JdbcTemplate for the given DataSource.
|
protected java.sql.Connection |
getConnection()
Get a JDBC Connection, either from the current transaction or a new one.
|
javax.sql.DataSource |
getDataSource()
Return the JDBC DataSource used by this DAO.
|
protected SQLExceptionTranslator |
getExceptionTranslator()
Return the SQLExceptionTranslator of this DAO's JdbcTemplate,
for translating SQLExceptions in custom JDBC access code.
|
JdbcTemplate |
getJdbcTemplate()
Return the JdbcTemplate for this DAO,
pre-initialized with the DataSource or set explicitly.
|
protected void |
initTemplateConfig()
Initialize the template-based configuration of this DAO.
|
protected void |
releaseConnection(java.sql.Connection con)
Close the given JDBC Connection, created via this DAO's DataSource,
if it isn't bound to the thread.
|
void |
setDataSource(javax.sql.DataSource dataSource)
Set the JDBC DataSource to be used by this DAO.
|
void |
setJdbcTemplate(JdbcTemplate jdbcTemplate)
Set the JdbcTemplate for this DAO explicitly,
as an alternative to specifying a DataSource.
|
afterPropertiesSet, initDao
private JdbcTemplate jdbcTemplate
public final void setDataSource(javax.sql.DataSource dataSource)
protected JdbcTemplate createJdbcTemplate(javax.sql.DataSource dataSource)
Can be overridden in subclasses to provide a JdbcTemplate instance with different configuration, or a custom JdbcTemplate subclass.
dataSource
- the JDBC DataSource to create a JdbcTemplate forsetDataSource(javax.sql.DataSource)
public final javax.sql.DataSource getDataSource()
public final void setJdbcTemplate(JdbcTemplate jdbcTemplate)
public final JdbcTemplate getJdbcTemplate()
protected void initTemplateConfig()
This implementation is empty. Subclasses may override this to configure further objects based on the JdbcTemplate.
getJdbcTemplate()
protected void checkDaoConfig()
DaoSupport
Implementors should be marked as final
if concrete subclasses
are not supposed to override this template method themselves.
checkDaoConfig
in class DaoSupport
protected final SQLExceptionTranslator getExceptionTranslator()
protected final java.sql.Connection getConnection() throws CannotGetJdbcConnectionException
CannotGetJdbcConnectionException
- if the attempt to get a Connection failedDataSourceUtils.getConnection(javax.sql.DataSource)
protected final void releaseConnection(java.sql.Connection con)
con
- Connection to closeDataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)