类 JdbcDaoSupport
- java.lang.Object
- org.springframework.dao.support.DaoSupport
- org.springframework.jdbc.core.support.JdbcDaoSupport
- 所有已实现的接口:
InitializingBean
- 直接已知子类:
NamedParameterJdbcDaoSupport
public abstract class JdbcDaoSupport extends DaoSupport
Convenient super class for JDBC-based data access objects.Requires a
DataSource
to be set, providing aJdbcTemplate
based on it to subclasses through thegetJdbcTemplate()
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.- 从以下版本开始:
- 28.07.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
setDataSource(javax.sql.DataSource)
,getJdbcTemplate()
,JdbcTemplate
字段概要
从类继承的字段 org.springframework.dao.support.DaoSupport
logger
构造器概要
构造器 构造器 说明 JdbcDaoSupport()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
checkDaoConfig()
Abstract subclasses must override this to check their configuration.protected JdbcTemplate
createJdbcTemplate(DataSource dataSource)
Create a JdbcTemplate for the given DataSource.protected Connection
getConnection()
Get a JDBC Connection, either from the current transaction or a new one.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(Connection con)
Close the given JDBC Connection, created via this DAO's DataSource, if it isn't bound to the thread.void
setDataSource(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.从类继承的方法 org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
构造器详细资料
JdbcDaoSupport
public JdbcDaoSupport()
方法详细资料
setDataSource
public final void setDataSource(DataSource dataSource)
Set the JDBC DataSource to be used by this DAO.
createJdbcTemplate
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.
- 参数:
dataSource
- the JDBC DataSource to create a JdbcTemplate for- 返回:
- the new JdbcTemplate instance
- 另请参阅:
setDataSource(javax.sql.DataSource)
getDataSource
@Nullable public final DataSource getDataSource()
Return the JDBC DataSource used by this DAO.
setJdbcTemplate
public final void setJdbcTemplate(@Nullable JdbcTemplate jdbcTemplate)
Set the JdbcTemplate for this DAO explicitly, as an alternative to specifying a DataSource.
getJdbcTemplate
@Nullable public final JdbcTemplate getJdbcTemplate()
Return the JdbcTemplate for this DAO, pre-initialized with the DataSource or set explicitly.
initTemplateConfig
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.
- 另请参阅:
getJdbcTemplate()
checkDaoConfig
protected void checkDaoConfig()
从类复制的说明:DaoSupport
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.- 指定者:
checkDaoConfig
在类中DaoSupport
getExceptionTranslator
protected final SQLExceptionTranslator getExceptionTranslator()
Return the SQLExceptionTranslator of this DAO's JdbcTemplate, for translating SQLExceptions in custom JDBC access code.
getConnection
protected final Connection getConnection() throws CannotGetJdbcConnectionException
Get a JDBC Connection, either from the current transaction or a new one.- 返回:
- the JDBC Connection
- 抛出:
CannotGetJdbcConnectionException
- if the attempt to get a Connection failed- 另请参阅:
DataSourceUtils.getConnection(javax.sql.DataSource)
releaseConnection
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.- 参数:
con
- the Connection to close- 另请参阅:
DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)