The Spring Framework

org.springframework.jdbc.support
Class JdbcAccessor

java.lang.Object
  extended by org.springframework.jdbc.support.JdbcAccessor
All Implemented Interfaces:
InitializingBean
Direct Known Subclasses:
JdbcTemplate, SqlMapClientTemplate

public abstract class JdbcAccessor
extends Object
implements InitializingBean

Base class for JdbcTemplate and other JDBC-accessing DAO helpers, defining common properties like DataSource and exception translator.

Not intended to be used directly. See JdbcTemplate.

Since:
28.11.2003
Author:
Juergen Hoeller
See Also:
JdbcTemplate

Field Summary
protected  Log logger
           
 
Constructor Summary
JdbcAccessor()
           
 
Method Summary
 void afterPropertiesSet()
          Eagerly initialize the exception translator, creating a default one for the specified DataSource if none set.
 DataSource getDataSource()
          Return the DataSource used by this template.
 SQLExceptionTranslator getExceptionTranslator()
          Return the exception translator for this instance.
 boolean isLazyInit()
          Return whether to lazily initialize the SQLExceptionTranslator for this accessor.
 void setDatabaseProductName(String dbName)
          Specify the database product name for the DataSource that this accessor uses.
 void setDataSource(DataSource dataSource)
          Set the JDBC DataSource to obtain connections from.
 void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)
          Set the exception translator for this instance.
 void setLazyInit(boolean lazyInit)
          Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of a SQLException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

JdbcAccessor

public JdbcAccessor()
Method Detail

setDataSource

public void setDataSource(DataSource dataSource)
Set the JDBC DataSource to obtain connections from.


getDataSource

public DataSource getDataSource()
Return the DataSource used by this template.


setDatabaseProductName

public void setDatabaseProductName(String dbName)
Specify the database product name for the DataSource that this accessor uses. This allows to initialize a SQLErrorCodeSQLExceptionTranslator without obtaining a Connection from the DataSource to get the metadata.

Parameters:
dbName - the database product name that identifies the error codes entry
See Also:
SQLErrorCodeSQLExceptionTranslator.setDatabaseProductName(java.lang.String), DatabaseMetaData.getDatabaseProductName()

setExceptionTranslator

public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)
Set the exception translator for this instance.

If no custom translator is provided, a default SQLErrorCodeSQLExceptionTranslator is used which examines the SQLException's vendor-specific error code.

Parameters:
exceptionTranslator - exception translator
See Also:
SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslator

getExceptionTranslator

public SQLExceptionTranslator getExceptionTranslator()
Return the exception translator for this instance.

Creates a default SQLErrorCodeSQLExceptionTranslator for the specified DataSource if none set.


setLazyInit

public void setLazyInit(boolean lazyInit)
Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of a SQLException. Default is "true"; can be switched to "false" for initialization on startup.

Early initialization only applies if afterPropertiesSet is called.

See Also:
getExceptionTranslator(), afterPropertiesSet()

isLazyInit

public boolean isLazyInit()
Return whether to lazily initialize the SQLExceptionTranslator for this accessor.


afterPropertiesSet

public void afterPropertiesSet()
Eagerly initialize the exception translator, creating a default one for the specified DataSource if none set.

Specified by:
afterPropertiesSet in interface InitializingBean

The Spring Framework

Copyright © 2002-2006 The Spring Framework.