org.springframework.jdbc.core.support

Class JdbcDaoSupport

    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor and Description
      JdbcDaoSupport() 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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.
      • 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(javax.sql.DataSource dataSource)
        Set the JDBC DataSource to be used by this DAO.
      • createJdbcTemplate

        protected JdbcTemplate createJdbcTemplate(javax.sql.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

        @Nullable
        public final javax.sql.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.

        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 if concrete subclasses are not supposed to override this template method themselves.

        Specified by:
        checkDaoConfig in class DaoSupport