Class AbstractJdbcConfiguration
java.lang.Object
org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
MyBatisJdbcConfiguration
@Configuration(proxyBeanMethods=false)
public class AbstractJdbcConfiguration
extends Object
implements org.springframework.context.ApplicationContextAware
Beans that must be registered for Spring Data JDBC to work.
- Since:
- 1.1
- Author:
- Greg Turnquist, Jens Schauder, Mark Paluch, Michael Simons, Christoph Strobl, Myeonghyeon Lee, Chirag Tailor
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondataAccessStrategyBean
(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, JdbcMappingContext context, Dialect dialect) Scans the mapping base package for classes annotated withTable
.protected Collection<String>
Returns the base packages to scan for JDBC mapped entities at startup.jdbcAggregateTemplate
(org.springframework.context.ApplicationContext applicationContext, JdbcMappingContext mappingContext, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Register aJdbcAggregateTemplate
as a bean for easy use in applications that need a lower level of abstraction than the normal repository abstraction.jdbcConverter
(JdbcMappingContext mappingContext, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, RelationResolver relationResolver, JdbcCustomConversions conversions, Dialect dialect) Creates aRelationalConverter
using the configuredjdbcMappingContext(Optional, JdbcCustomConversions, RelationalManagedTypes)
.Register customConverter
s in aJdbcCustomConversions
object if required.jdbcDialect
(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations) Resolves aJDBC dialect
by inspectingNamedParameterJdbcOperations
.Returns the aRelationalManagedTypes
object holding the initial entity set.jdbcMappingContext
(Optional<NamingStrategy> namingStrategy, JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) Register aJdbcMappingContext
and apply an optionalNamingStrategy
.scanForEntities
(String basePackage) Scans the given base package for entities, i.e.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) protected List<?>
-
Constructor Details
-
AbstractJdbcConfiguration
public AbstractJdbcConfiguration()
-
-
Method Details
-
getMappingBasePackages
Returns the base packages to scan for JDBC mapped entities at startup. Returns the package name of the configuration class' (the concrete class, not this one here) by default. So if you have acom.acme.AppConfig
extendingAbstractJdbcConfiguration
the base package will be consideredcom.acme
unless the method is overridden to implement alternate behavior.- Returns:
- the base packages to scan for mapped
Table
classes or an empty collection to not enable scanning for entities. - Since:
- 3.0
-
jdbcManagedTypes
Returns the aRelationalManagedTypes
object holding the initial entity set.- Returns:
- new instance of
RelationalManagedTypes
. - Throws:
ClassNotFoundException
- Since:
- 3.0
-
jdbcMappingContext
@Bean public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) Register aJdbcMappingContext
and apply an optionalNamingStrategy
.- Parameters:
namingStrategy
- optionalNamingStrategy
. UseDefaultNamingStrategy.INSTANCE
as fallback.customConversions
- seejdbcCustomConversions()
.jdbcManagedTypes
- JDBC managed types, typically discovered throughan entity scan
.- Returns:
- must not be null.
-
jdbcConverter
@Bean public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, @Lazy RelationResolver relationResolver, JdbcCustomConversions conversions, Dialect dialect) Creates aRelationalConverter
using the configuredjdbcMappingContext(Optional, JdbcCustomConversions, RelationalManagedTypes)
.- Returns:
- must not be null.
- See Also:
-
jdbcCustomConversions
Register customConverter
s in aJdbcCustomConversions
object if required. TheseJdbcCustomConversions
will be registered with thejdbcConverter(JdbcMappingContext, NamedParameterJdbcOperations, RelationResolver, JdbcCustomConversions, Dialect)
. Returns an emptyJdbcCustomConversions
instance by default.- Returns:
- will never be null.
-
userConverters
-
jdbcAggregateTemplate
@Bean public JdbcAggregateTemplate jdbcAggregateTemplate(org.springframework.context.ApplicationContext applicationContext, JdbcMappingContext mappingContext, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Register aJdbcAggregateTemplate
as a bean for easy use in applications that need a lower level of abstraction than the normal repository abstraction.- Parameters:
applicationContext
- for publishing events. Must not be null.mappingContext
- the mapping context to be used. Must not be null.converter
- the conversions used when reading and writing from/to the database. Must not be null.- Returns:
- a
JdbcAggregateTemplate
. Will never be null.
-
dataAccessStrategyBean
@Bean public DataAccessStrategy dataAccessStrategyBean(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, JdbcMappingContext context, Dialect dialect) Create aDataAccessStrategy
for reuse in theJdbcAggregateOperations
and theJdbcConverter
. Override this method to register a bean of typeDataAccessStrategy
if your use case requires a more specializedDataAccessStrategy
.- Returns:
- will never be null.
-
jdbcDialect
@Bean public Dialect jdbcDialect(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations operations) Resolves aJDBC dialect
by inspectingNamedParameterJdbcOperations
.- Parameters:
operations
- theNamedParameterJdbcOperations
allowing access to aConnection
.- Returns:
- the
Dialect
to be used. - Throws:
DialectResolver.NoDialectException
- if theDialect
cannot be determined.- Since:
- 2.0
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
getInitialEntitySet
Scans the mapping base package for classes annotated withTable
. By default, it scans for entities in all packages returned bygetMappingBasePackages()
.- Returns:
- Throws:
ClassNotFoundException
- Since:
- 3.0
- See Also:
-
scanForEntities
Scans the given base package for entities, i.e. JDBC-specific types annotated withTable
.- Parameters:
basePackage
- must not be null.- Returns:
- a set of classes identified as entities.
- Since:
- 3.0
-