public abstract class

JdbcDaoSupport

extends DaoSupport
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.jdbc.core.support.JdbcDaoSupport
Known Direct Subclasses

Class Overview

Convenient super class for JDBC-based data access objects.

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.

Summary

[Expand]
Inherited Fields
From class org.springframework.dao.support.DaoSupport
Public Constructors
JdbcDaoSupport()
Public Methods
final DataSource getDataSource()
Return the JDBC DataSource used by this DAO.
final JdbcTemplate getJdbcTemplate()
Return the JdbcTemplate for this DAO, pre-initialized with the DataSource or set explicitly.
final void setDataSource(DataSource dataSource)
Set the JDBC DataSource to be used by this DAO.
final void setJdbcTemplate(JdbcTemplate jdbcTemplate)
Set the JdbcTemplate for this DAO explicitly, as an alternative to specifying a DataSource.
Protected Methods
void checkDaoConfig()
Abstract subclasses must override this to check their configuration.
JdbcTemplate createJdbcTemplate(DataSource dataSource)
Create a JdbcTemplate for the given DataSource.
final Connection getConnection()
Get a JDBC Connection, either from the current transaction or a new one.
final SQLExceptionTranslator getExceptionTranslator()
Return the SQLExceptionTranslator of this DAO's JdbcTemplate, for translating SQLExceptions in custom JDBC access code.
void initTemplateConfig()
Initialize the template-based configuration of this DAO.
final void releaseConnection(Connection con)
Close the given JDBC Connection, created via this DAO's DataSource, if it isn't bound to the thread.
[Expand]
Inherited Methods
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public JdbcDaoSupport ()

Public Methods

public final DataSource getDataSource ()

Return the JDBC DataSource used by this DAO.

public final JdbcTemplate getJdbcTemplate ()

Return the JdbcTemplate for this DAO, pre-initialized with the DataSource or set explicitly.

public final void setDataSource (DataSource dataSource)

Set the JDBC DataSource to be used by this DAO.

public final void setJdbcTemplate (JdbcTemplate jdbcTemplate)

Set the JdbcTemplate for this DAO explicitly, as an alternative to specifying a DataSource.

Protected Methods

protected void checkDaoConfig ()

Abstract subclasses must override this to check their configuration.

Implementors should be marked as final

protected JdbcTemplate createJdbcTemplate (DataSource dataSource)

Create a JdbcTemplate for the given DataSource. Only invoked if populating the DAO with a DataSource reference!

Can be overridden in subclasses to provide a JdbcTemplate instance with different configuration, or a custom JdbcTemplate subclass.

Parameters
dataSource the JDBC DataSource to create a JdbcTemplate for
Returns
  • the new JdbcTemplate instance

protected final Connection getConnection ()

Get a JDBC Connection, either from the current transaction or a new one.

Returns
  • the JDBC Connection
Throws
CannotGetJdbcConnectionException if the attempt to get a Connection failed

protected final SQLExceptionTranslator getExceptionTranslator ()

Return the SQLExceptionTranslator of this DAO's JdbcTemplate, for translating SQLExceptions in custom JDBC access code.

protected void initTemplateConfig ()

Initialize the template-based configuration of this DAO. Called after a new JdbcTemplate has been set, either directly or through a DataSource.

This implementation is empty. Subclasses may override this to configure further objects based on the JdbcTemplate.

protected final void releaseConnection (Connection con)

Close the given JDBC Connection, created via this DAO's DataSource, if it isn't bound to the thread.

Parameters
con Connection to close