Top Description Fields Constructors Methods
org.springframework.jdbc.core.support

public abstract Class JdbcDaoSupport

extends DaoSupport
Class Inheritance
Known Direct Subclasses
org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport
Imports
java.sql.Connection, javax.sql.DataSource, org.springframework.dao.support.DaoSupport, org.springframework.jdbc.CannotGetJdbcConnectionException, org.springframework.jdbc.core.JdbcTemplate, org.springframework.jdbc.datasource.DataSourceUtils, org.springframework.jdbc.support.SQLExceptionTranslator, org.springframework.lang.Nullable, org.springframework.util.Assert

Convenient superclass for JDBC-based data access objects.

Requires a javax.sql.DataSource to be set, providing a org.springframework.jdbc.core.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.

Author
Juergen Hoeller
Since
28.07.2003
See Also
setDataSource, getJdbcTemplate, org.springframework.jdbc.core.JdbcTemplate

Field Summary

Modifier and TypeField and Description
private JdbcTemplate
Inherited from org.springframework.dao.support.DaoSupport:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
checkDaoConfig()

Implements abstract org.springframework.dao.support.DaoSupport.checkDaoConfig.

Abstract subclasses must override this to check their configuration.
protected JdbcTemplate

Returns:

the new JdbcTemplate instance
createJdbcTemplate
(DataSource
the JDBC DataSource to create a JdbcTemplate for
dataSource
)

Create a JdbcTemplate for the given DataSource.

protected final Connection

Returns:

the JDBC Connection
getConnection
()

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

public final DataSource
getDataSource()

Return the JDBC DataSource used by this DAO.

protected final SQLExceptionTranslator
getExceptionTranslator()

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

public final 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 final void
releaseConnection(Connection
the Connection to close
con
)

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

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.

Inherited from org.springframework.dao.support.DaoSupport:
afterPropertiesSetinitDao

Field Detail

jdbcTemplateback to summary
private JdbcTemplate jdbcTemplate
Annotations
@Nullable

Constructor Detail

JdbcDaoSupportback to summary
public JdbcDaoSupport()

Method Detail

checkDaoConfigback to summary
protected void checkDaoConfig()

Implements abstract org.springframework.dao.support.DaoSupport.checkDaoConfig.

Doc from org.springframework.dao.support.DaoSupport.checkDaoConfig.

Abstract subclasses must override this to check their configuration.

Implementors should be marked as final if concrete subclasses are not supposed to override this template method themselves.

Annotations
@Override
createJdbcTemplateback to summary
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:DataSource

the JDBC DataSource to create a JdbcTemplate for

Returns:JdbcTemplate

the new JdbcTemplate instance

See Also
setDataSource
getConnectionback to summary
protected final Connection getConnection() throws CannotGetJdbcConnectionException

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

Returns:Connection

the JDBC Connection

Exceptions
CannotGetJdbcConnectionException:
if the attempt to get a Connection failed
See Also
org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource)
getDataSourceback to summary
public final DataSource getDataSource()

Return the JDBC DataSource used by this DAO.

Annotations
@Nullable
getExceptionTranslatorback to summary
protected final SQLExceptionTranslator getExceptionTranslator()

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

See Also
org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator()
getJdbcTemplateback to summary
public final JdbcTemplate getJdbcTemplate()

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

Annotations
@Nullable
initTemplateConfigback to summary
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.

See Also
getJdbcTemplate()
releaseConnectionback to summary
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

the Connection to close

See Also
org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
setDataSourceback to summary
public final void setDataSource(DataSource dataSource)

Set the JDBC DataSource to be used by this DAO.

setJdbcTemplateback to summary
public final void setJdbcTemplate(JdbcTemplate jdbcTemplate)

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