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

public abstract Class JdbcAccessor

extends Object
implements InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean
Known Direct Subclasses
org.springframework.jdbc.core.JdbcTemplate
Imports
javax.sql.DataSource, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.InitializingBean, org.springframework.lang.Nullable, org.springframework.util.Assert

Base class for org.springframework.jdbc.core.JdbcTemplate and other JDBC-accessing DAO helpers, defining common properties such as DataSource and exception translator.

Not intended to be used directly. See org.springframework.jdbc.core.JdbcTemplate.

Authors
Juergen Hoeller, Sebastien Deleuze
Since
28.11.2003
See Also
org.springframework.jdbc.core.JdbcTemplate

Field Summary

Modifier and TypeField and Description
private DataSource
private volatile SQLExceptionTranslator
private boolean
protected final Log
logger

Logger available to subclasses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

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

Return the DataSource used by this template.

public SQLExceptionTranslator
getExceptionTranslator()

Return the exception translator to use for this instance, creating a default if necessary.

public boolean
isLazyInit()

Return whether to lazily initialize the SQLExceptionTranslator for this accessor.

protected DataSource

Returns:

the DataSource (never null)
obtainDataSource
()

Obtain the DataSource for actual use.

public void
setDatabaseProductName(String
the database product name that identifies the error codes entry
dbName
)

Specify the database product name for the DataSource that this accessor uses.

public void
setDataSource(DataSource dataSource)

Set the JDBC DataSource to obtain connections from.

public void
setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)

Set the exception translator for this instance.

public void
setLazyInit(boolean lazyInit)

Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of an SQLException.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataSourceback to summary
private DataSource dataSource
Annotations
@Nullable
exceptionTranslatorback to summary
private volatile SQLExceptionTranslator exceptionTranslator
Annotations
@Nullable
lazyInitback to summary
private boolean lazyInit
loggerback to summary
protected final Log logger

Logger available to subclasses.

Constructor Detail

JdbcAccessorback to summary
public JdbcAccessor()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.

Annotations
@Override
getDataSourceback to summary
public DataSource getDataSource()

Return the DataSource used by this template.

Annotations
@Nullable
getExceptionTranslatorback to summary
public SQLExceptionTranslator getExceptionTranslator()

Return the exception translator to use for this instance, creating a default if necessary.

See Also
setExceptionTranslator
isLazyInitback to summary
public boolean isLazyInit()

Return whether to lazily initialize the SQLExceptionTranslator for this accessor.

See Also
getExceptionTranslator()
obtainDataSourceback to summary
protected DataSource obtainDataSource()

Obtain the DataSource for actual use.

Returns:DataSource

the DataSource (never null)

Exceptions
IllegalStateException:
in case of no DataSource set
Since
5.0
setDatabaseProductNameback to summary
public void setDatabaseProductName(String dbName)

Specify the database product name for the DataSource that this accessor uses. This allows for initializing a SQLErrorCodeSQLExceptionTranslator without obtaining a Connection from the DataSource to get the meta-data.

Parameters
dbName:String

the database product name that identifies the error codes entry

See Also
setExceptionTranslator, SQLErrorCodeSQLExceptionTranslator#setDatabaseProductName, java.sql.DatabaseMetaData#getDatabaseProductName()
setDataSourceback to summary
public void setDataSource(DataSource dataSource)

Set the JDBC DataSource to obtain connections from.

setExceptionTranslatorback to summary
public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)

Set the exception translator for this instance.

A SQLErrorCodeSQLExceptionTranslator used by default if a user-provided `sql-error-codes.xml` file has been found in the root of the classpath. Otherwise, SQLExceptionSubclassTranslator serves as the default translator as of 6.0.

See Also
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator, org.springframework.jdbc.support.SQLExceptionSubclassTranslator
setLazyInitback to summary
public void setLazyInit(boolean lazyInit)

Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of an SQLException. Default is "true"; can be switched to "false" for initialization on startup.

Early initialization just applies if afterPropertiesSet() is called.

See Also
getExceptionTranslator(), afterPropertiesSet()