JdbcDaoSupport.CLASS

http://www.apihome.cn/api/spring/JdbcDaoSupport.html


org.springframework.jdbc.core.support
Class JdbcDaoSupport

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.jdbc.core.support.JdbcDaoSupport
All Implemented Interfaces:
InitializingBean
Direct Known Subclasses:
NamedParameterJdbcDaoSupport, SimpleJdbcDaoSupport

public abstract class JdbcDaoSupport
    
    
     
     extends DaoSupport
    
    

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.

Since:
28.07.2003
Author:
Juergen Hoeller
See Also:
setDataSource(javax.sql.DataSource), getJdbcTemplate(), JdbcTemplate

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
JdbcDaoSupport()
           
 
Method Summary
protected  voidcheckDaoConfig()
          Abstract subclasses must override this to check their configuration.
protected  JdbcTemplatecreateJdbcTemplate(DataSource dataSource)
          Create a JdbcTemplate for the given DataSource.
protected  ConnectiongetConnection()
          Get a JDBC Connection, either from the current transaction or a new one.
 DataSourcegetDataSource()
          Return the JDBC DataSource used by this DAO.
protected  SQLExceptionTranslatorgetExceptionTranslator()
          Return the SQLExceptionTranslator of this DAO's JdbcTemplate, for translating SQLExceptions in custom JDBC access code.
 JdbcTemplategetJdbcTemplate()
          Return the JdbcTemplate for this DAO, pre-initialized with the DataSource or set explicitly.
protected  voidinitTemplateConfig()
          Initialize the template-based configuration of this DAO.
protected  voidreleaseConnection(Connection con)
          Close the given JDBC Connection, created via this DAO's DataSource, if it isn't bound to the thread.
 voidsetDataSource(DataSource dataSource)
          Set the JDBC DataSource to be used by this DAO.
 voidsetJdbcTemplate(JdbcTemplate jdbcTemplate)
          Set the JdbcTemplate for this DAO explicitly, as an alternative to specifying a DataSource.
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcDaoSupport

public JdbcDaoSupport()
Method Detail

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.

Parameters:
dataSource - the JDBC DataSource to create a JdbcTemplate for
Returns:
the new JdbcTemplate instance
See Also:
setDataSource(javax.sql.DataSource)

getDataSource

public final DataSource getDataSource()
Return the JDBC DataSource used by this DAO.


setJdbcTemplate

public final void setJdbcTemplate(JdbcTemplate jdbcTemplate)
Set the JdbcTemplate for this DAO explicitly, as an alternative to specifying a DataSource.


getJdbcTemplate

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.

See Also:
getJdbcTemplate()

checkDaoConfig

protected void checkDaoConfig()
Description copied from class: DaoSupport
Abstract subclasses must override this to check their configuration.

Implementors should be marked as final

Specified by:
checkDaoConfig in class DaoSupport

getExceptionTranslator

protected final SQLExceptionTranslator getExceptionTranslator()
Return the SQLExceptionTranslator of this DAO's JdbcTemplate, for translating SQLExceptions in custom JDBC access code.

See Also:
JdbcAccessor.getExceptionTranslator()

getConnection

protected final Connection getConnection()
                                  throws CannotGetJdbcConnectionException
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
See Also:
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.
Parameters:
con - Connection to close
See Also:
DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值