|
16 | 16 |
|
17 | 17 | package org.springframework.boot.data.jdbc.autoconfigure; |
18 | 18 |
|
| 19 | +import java.util.Collections; |
19 | 20 | import java.util.Optional; |
20 | | -import java.util.Set; |
21 | 21 |
|
| 22 | +import org.springframework.beans.factory.ObjectProvider; |
22 | 23 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
23 | 24 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
24 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
|
36 | 37 | import org.springframework.context.annotation.Lazy; |
37 | 38 | import org.springframework.data.jdbc.core.JdbcAggregateTemplate; |
38 | 39 | import org.springframework.data.jdbc.core.convert.DataAccessStrategy; |
| 40 | +import org.springframework.data.jdbc.core.convert.IdGeneratingEntityCallback; |
39 | 41 | import org.springframework.data.jdbc.core.convert.JdbcConverter; |
40 | 42 | import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; |
| 43 | +import org.springframework.data.jdbc.core.convert.QueryMappingConfiguration; |
41 | 44 | import org.springframework.data.jdbc.core.convert.RelationResolver; |
| 45 | +import org.springframework.data.jdbc.core.dialect.DialectResolver; |
42 | 46 | import org.springframework.data.jdbc.core.dialect.JdbcDialect; |
43 | 47 | import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; |
44 | 48 | import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration; |
45 | 49 | import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; |
| 50 | +import org.springframework.data.jdbc.repository.config.JdbcConfiguration; |
46 | 51 | import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension; |
47 | 52 | import org.springframework.data.relational.RelationalManagedTypes; |
48 | 53 | import org.springframework.data.relational.core.mapping.NamingStrategy; |
@@ -80,75 +85,65 @@ static class JdbcRepositoriesConfiguration { |
80 | 85 |
|
81 | 86 | @Configuration(proxyBeanMethods = false) |
82 | 87 | @ConditionalOnMissingBean(AbstractJdbcConfiguration.class) |
83 | | - static class SpringBootJdbcConfiguration extends AbstractJdbcConfiguration { |
| 88 | + static class SpringBootJdbcConfiguration { |
84 | 89 |
|
85 | | - private final ApplicationContext applicationContext; |
86 | | - |
87 | | - private final DataJdbcProperties properties; |
88 | | - |
89 | | - SpringBootJdbcConfiguration(ApplicationContext applicationContext, DataJdbcProperties properties) { |
90 | | - this.applicationContext = applicationContext; |
91 | | - this.properties = properties; |
92 | | - } |
93 | | - |
94 | | - @Override |
95 | | - protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { |
96 | | - return new EntityScanner(this.applicationContext).scan(Table.class); |
| 90 | + @Bean |
| 91 | + @ConditionalOnMissingBean |
| 92 | + RelationalManagedTypes jdbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException { |
| 93 | + return RelationalManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Table.class)); |
97 | 94 | } |
98 | 95 |
|
99 | | - @Override |
100 | 96 | @Bean |
101 | 97 | @ConditionalOnMissingBean |
102 | | - public RelationalManagedTypes jdbcManagedTypes() throws ClassNotFoundException { |
103 | | - return super.jdbcManagedTypes(); |
| 98 | + JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, |
| 99 | + JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) { |
| 100 | + return JdbcConfiguration.createMappingContext(jdbcManagedTypes, customConversions, |
| 101 | + namingStrategy.orElse(null)); |
104 | 102 | } |
105 | 103 |
|
106 | | - @Override |
107 | 104 | @Bean |
108 | 105 | @ConditionalOnMissingBean |
109 | | - public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, |
110 | | - JdbcCustomConversions customConversions, RelationalManagedTypes jdbcManagedTypes) { |
111 | | - return super.jdbcMappingContext(namingStrategy, customConversions, jdbcManagedTypes); |
| 106 | + IdGeneratingEntityCallback idGeneratingBeforeSaveCallback(JdbcMappingContext mappingContext, |
| 107 | + NamedParameterJdbcOperations operations, JdbcDialect dialect) { |
| 108 | + return new IdGeneratingEntityCallback(mappingContext, dialect, operations); |
112 | 109 | } |
113 | 110 |
|
114 | | - @Override |
115 | 111 | @Bean |
116 | 112 | @ConditionalOnMissingBean |
117 | | - public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, NamedParameterJdbcOperations operations, |
| 113 | + JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, NamedParameterJdbcOperations operations, |
118 | 114 | @Lazy RelationResolver relationResolver, JdbcCustomConversions conversions, JdbcDialect dialect) { |
119 | | - return super.jdbcConverter(mappingContext, operations, relationResolver, conversions, dialect); |
| 115 | + return JdbcConfiguration.createConverter(mappingContext, operations, relationResolver, conversions, |
| 116 | + dialect); |
120 | 117 | } |
121 | 118 |
|
122 | | - @Override |
123 | 119 | @Bean |
124 | 120 | @ConditionalOnMissingBean |
125 | | - public JdbcCustomConversions jdbcCustomConversions() { |
126 | | - return super.jdbcCustomConversions(); |
| 121 | + JdbcCustomConversions jdbcCustomConversions(JdbcDialect dialect) { |
| 122 | + return JdbcConfiguration.createCustomConversions(dialect, Collections.emptyList()); |
127 | 123 | } |
128 | 124 |
|
129 | | - @Override |
130 | 125 | @Bean |
131 | 126 | @ConditionalOnMissingBean |
132 | | - public JdbcAggregateTemplate jdbcAggregateTemplate(ApplicationContext applicationContext, |
| 127 | + JdbcAggregateTemplate jdbcAggregateTemplate(ApplicationContext applicationContext, |
133 | 128 | JdbcMappingContext mappingContext, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) { |
134 | | - return super.jdbcAggregateTemplate(applicationContext, mappingContext, converter, dataAccessStrategy); |
| 129 | + return new JdbcAggregateTemplate(applicationContext, mappingContext, converter, dataAccessStrategy); |
135 | 130 | } |
136 | 131 |
|
137 | | - @Override |
138 | 132 | @Bean |
139 | 133 | @ConditionalOnMissingBean |
140 | | - public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, |
141 | | - JdbcConverter jdbcConverter, JdbcMappingContext context, JdbcDialect dialect) { |
142 | | - return super.dataAccessStrategyBean(operations, jdbcConverter, context, dialect); |
| 134 | + DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter, |
| 135 | + JdbcMappingContext context, JdbcDialect dialect) { |
| 136 | + return JdbcConfiguration.createDataAccessStrategy(operations, jdbcConverter, |
| 137 | + QueryMappingConfiguration.EMPTY, dialect); |
143 | 138 | } |
144 | 139 |
|
145 | | - @Override |
146 | 140 | @Bean |
147 | 141 | @ConditionalOnMissingBean |
148 | | - public JdbcDialect jdbcDialect(NamedParameterJdbcOperations operations) { |
149 | | - DataJdbcDatabaseDialect dialect = this.properties.getDialect(); |
150 | | - return (dialect != null) ? dialect.getJdbcDialect(operations.getJdbcOperations()) |
151 | | - : super.jdbcDialect(operations); |
| 142 | + JdbcDialect jdbcDialect(DataJdbcProperties properties, |
| 143 | + ObjectProvider<NamedParameterJdbcOperations> operations) { |
| 144 | + DataJdbcDatabaseDialect dialect = properties.getDialect(); |
| 145 | + return (dialect != null) ? dialect.getJdbcDialect(() -> operations.getObject().getJdbcOperations()) |
| 146 | + : DialectResolver.getDialect(operations.getObject().getJdbcOperations()); |
152 | 147 | } |
153 | 148 |
|
154 | 149 | } |
|
0 commit comments