-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DATAJDBC-395 - AbstractJdbcConfiguration no longer registers a bean of type DataAccessStrategy. #160
DATAJDBC-395 - AbstractJdbcConfiguration no longer registers a bean of type DataAccessStrategy. #160
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import java.util.Optional; | ||
|
||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
@@ -51,6 +52,8 @@ | |
@Configuration | ||
public abstract class AbstractJdbcConfiguration { | ||
|
||
private DefaultDataAccessStrategy defaultDataAccessStrategy = null; | ||
|
||
/** | ||
* Register a {@link RelationalMappingContext} and apply an optional {@link NamingStrategy}. | ||
* | ||
|
@@ -76,17 +79,28 @@ public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStra | |
*/ | ||
@Bean | ||
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(), | ||
new DefaultJdbcTypeFactory(operations.getJdbcOperations())); | ||
return new BasicJdbcConverter( // | ||
mappingContext, // | ||
relationResolver, // | ||
jdbcCustomConversions(), // | ||
new DefaultJdbcTypeFactory(operations.getJdbcOperations()) // | ||
); | ||
} | ||
|
||
/** | ||
* Register custom {@link Converter}s in a {@link JdbcCustomConversions} object if required. These | ||
* {@link JdbcCustomConversions} will be registered with the | ||
* {@link #jdbcConverter(RelationalMappingContext, NamedParameterJdbcOperations, RelationResolver)}. Returns an empty | ||
* {@link JdbcCustomConversions} instance by default. | ||
* {@link #jdbcConverter(RelationalMappingContext, NamedParameterJdbcOperations, ObjectProvider, Optional, JdbcConverter)}. | ||
* Returns an empty {@link JdbcCustomConversions} instance by default. | ||
* | ||
* @return must not be {@literal null}. | ||
*/ | ||
|
@@ -106,26 +120,45 @@ public JdbcCustomConversions jdbcCustomConversions() { | |
*/ | ||
@Bean | ||
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( // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I think the single line reads way better than the ones broken out onto multiple ones. |
||
publisher, // | ||
context, // | ||
converter, // | ||
dataAccessStrategy // | ||
); | ||
} | ||
|
||
/** | ||
* Register a {@link DataAccessStrategy} as a bean for reuse in the {@link JdbcAggregateOperations} and the | ||
* {@link RelationalConverter}. | ||
* Create a {@link DataAccessStrategy} for reuse in the {@link JdbcAggregateOperations} and the | ||
* {@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 | ||
* @param namingStrategy | ||
* @param jdbcConverter | ||
* @return | ||
* @return Guaranteed to be not {@literal null}. | ||
*/ | ||
@Bean | ||
public DataAccessStrategy dataAccessStrategy(NamedParameterJdbcOperations operations, | ||
Optional<NamingStrategy> namingStrategy, JdbcConverter jdbcConverter) { | ||
private DataAccessStrategy dataAccessStrategy(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, | ||
JdbcMappingContext context) { | ||
|
||
if (defaultDataAccessStrategy == null) { | ||
|
||
JdbcMappingContext context = jdbcMappingContext(namingStrategy); | ||
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context), context, jdbcConverter, operations); | ||
defaultDataAccessStrategy = new DefaultDataAccessStrategy( // | ||
new SqlGeneratorSource(context), // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe extract into a local variable to keep the line shorter and avoid the additional manual breaks. |
||
context, // | ||
jdbcConverter, // | ||
operations // | ||
); | ||
} | ||
return defaultDataAccessStrategy; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try to avoid these manual breaks in parameters lists? If a list exceeds the line length, we could rather prefer breaking right before the invocation instead: