@ -17,6 +17,7 @@ package org.springframework.data.jdbc.repository.config;
import java.util.Optional ;
import java.util.Optional ;
import org.springframework.beans.factory.ObjectProvider ;
import org.springframework.context.ApplicationEventPublisher ;
import org.springframework.context.ApplicationEventPublisher ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
@ -51,6 +52,8 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
@Configuration
@Configuration
public abstract class AbstractJdbcConfiguration {
public abstract class AbstractJdbcConfiguration {
private DefaultDataAccessStrategy defaultDataAccessStrategy = null ;
/ * *
/ * *
* Register a { @link RelationalMappingContext } and apply an optional { @link NamingStrategy } .
* Register a { @link RelationalMappingContext } and apply an optional { @link NamingStrategy } .
*
*
@ -76,17 +79,28 @@ public abstract class AbstractJdbcConfiguration {
* /
* /
@Bean
@Bean
public JdbcConverter jdbcConverter ( RelationalMappingContext mappingContext , NamedParameterJdbcOperations operations ,
public JdbcConverter jdbcConverter ( RelationalMappingContext mappingContext , NamedParameterJdbcOperations operations ,
@Lazy RelationResolver relationResolver ) {
ObjectProvider < RelationResolver > relationResolverProvider , Optional < NamingStrategy > namingStrategy ,
JdbcConverter jdbcConverter ) {
RelationResolver relationResolver = relationResolverProvider . getIfAvailable ( ( ) - > dataAccessStrategy ( //
operations , //
jdbcConverter , //
jdbcMappingContext ( namingStrategy ) ) //
) ;
return new BasicJdbcConverter ( mappingContext , relationResolver , jdbcCustomConversions ( ) ,
return new BasicJdbcConverter ( //
new DefaultJdbcTypeFactory ( operations . getJdbcOperations ( ) ) ) ;
mappingContext , //
relationResolver , //
jdbcCustomConversions ( ) , //
new DefaultJdbcTypeFactory ( operations . getJdbcOperations ( ) ) //
) ;
}
}
/ * *
/ * *
* Register custom { @link Converter } s in a { @link JdbcCustomConversions } object if required . These
* Register custom { @link Converter } s in a { @link JdbcCustomConversions } object if required . These
* { @link JdbcCustomConversions } will be registered with the
* { @link JdbcCustomConversions } will be registered with the
* { @link # jdbcConverter ( RelationalMappingContext , NamedParameterJdbcOperations , RelationResolver ) } . Returns an empty
* { @link # jdbcConverter ( RelationalMappingContext , NamedParameterJdbcOperations , ObjectProvider , Optional , JdbcConverter ) } .
* { @link JdbcCustomConversions } instance by default .
* Returns an empty { @link JdbcCustomConversions } instance by default .
*
*
* @return must not be { @literal null } .
* @return must not be { @literal null } .
* /
* /
@ -106,26 +120,45 @@ public abstract class AbstractJdbcConfiguration {
* /
* /
@Bean
@Bean
public JdbcAggregateTemplate jdbcAggregateTemplate ( ApplicationEventPublisher publisher ,
public JdbcAggregateTemplate jdbcAggregateTemplate ( ApplicationEventPublisher publisher ,
RelationalMappingContext context , JdbcConverter converter , DataAccessStrategy dataAccessStrategy ) {
RelationalMappingContext context , JdbcConverter converter ,
ObjectProvider < DataAccessStrategy > dataAccessStrategyProvider , NamedParameterJdbcOperations operations ,
Optional < NamingStrategy > namingStrategy , @Lazy JdbcConverter jdbcConverter ) {
DataAccessStrategy dataAccessStrategy = dataAccessStrategyProvider . getIfAvailable ( ( ) - > dataAccessStrategy ( //
operations , //
jdbcConverter , //
jdbcMappingContext ( namingStrategy ) ) //
) ;
return new JdbcAggregateTemplate ( publisher , context , converter , dataAccessStrategy ) ;
return new JdbcAggregateTemplate ( //
publisher , //
context , //
converter , //
dataAccessStrategy //
) ;
}
}
/ * *
/ * *
* Register a { @link DataAccessStrategy } as a bean for reuse in the { @link JdbcAggregateOperations } and the
* Create a { @link DataAccessStrategy } for reuse in the { @link JdbcAggregateOperations } and the
* { @link RelationalConverter } .
* { @link RelationalConverter } . It will return the same instance if called multiple times , regardless of the arguments
* provided . Register a bean of type { @link DataAccessStrategy } if your use case requires a more specialized
* DataAccessStrategy .
*
*
* @param operations
* @return Guaranteed to be not { @literal null } .
* @param namingStrategy
* @param jdbcConverter
* @return
* /
* /
@Bean
private DataAccessStrategy dataAccessStrategy ( NamedParameterJdbcOperations operations , JdbcConverter jdbcConverter ,
public DataAccessStrategy dataAccessStrategy ( NamedParameterJdbcOperations operations ,
JdbcMappingContext context ) {
Optional < NamingStrategy > namingStrategy , JdbcConverter jdbcConverter ) {
if ( defaultDataAccessStrategy = = null ) {
JdbcMappingContext context = jdbcMappingContext ( namingStrategy ) ;
defaultDataAccessStrategy = new DefaultDataAccessStrategy ( //
return new DefaultDataAccessStrategy ( new SqlGeneratorSource ( context ) , context , jdbcConverter , operations ) ;
new SqlGeneratorSource ( context ) , //
context , //
jdbcConverter , //
operations //
) ;
}
return defaultDataAccessStrategy ;
}
}
}
}