23
23
import org .springframework .context .ApplicationEventPublisher ;
24
24
import org .springframework .data .jdbc .core .convert .JdbcConverter ;
25
25
import org .springframework .data .jdbc .core .convert .QueryMappingConfiguration ;
26
+ import org .springframework .data .jdbc .core .dialect .JdbcDialect ;
26
27
import org .springframework .data .jdbc .repository .query .DefaultRowMapperFactory ;
27
28
import org .springframework .data .jdbc .repository .query .JdbcQueryMethod ;
28
29
import org .springframework .data .jdbc .repository .query .PartTreeJdbcQuery ;
@@ -69,7 +70,7 @@ abstract class JdbcQueryLookupStrategy extends RelationalQueryLookupStrategy {
69
70
protected final ValueExpressionDelegate delegate ;
70
71
71
72
JdbcQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
72
- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
73
+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
73
74
QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
74
75
ValueExpressionDelegate delegate ) {
75
76
@@ -105,7 +106,7 @@ static class CreateQueryLookupStrategy extends JdbcQueryLookupStrategy {
105
106
private final RowMapperFactory rowMapperFactory ;
106
107
107
108
CreateQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
108
- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
109
+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
109
110
QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
110
111
ValueExpressionDelegate delegate ) {
111
112
@@ -138,7 +139,7 @@ static class DeclaredQueryLookupStrategy extends JdbcQueryLookupStrategy {
138
139
private final RowMapperFactory rowMapperFactory ;
139
140
140
141
DeclaredQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
141
- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
142
+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
142
143
QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
143
144
@ Nullable BeanFactory beanfactory , ValueExpressionDelegate delegate ) {
144
145
super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations , delegate );
@@ -191,7 +192,7 @@ static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy
191
192
* @param lookupStrategy must not be {@literal null}.
192
193
*/
193
194
CreateIfNotFoundQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
194
- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
195
+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
195
196
QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
196
197
CreateQueryLookupStrategy createStrategy , DeclaredQueryLookupStrategy lookupStrategy ,
197
198
ValueExpressionDelegate delegate ) {
@@ -222,7 +223,12 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
222
223
*/
223
224
JdbcQueryMethod getJdbcQueryMethod (Method method , RepositoryMetadata repositoryMetadata ,
224
225
ProjectionFactory projectionFactory , NamedQueries namedQueries ) {
225
- return new JdbcQueryMethod (method , repositoryMetadata , projectionFactory , namedQueries , getMappingContext ());
226
+ return new JdbcQueryMethod (method , repositoryMetadata , projectionFactory , namedQueries , getMappingContext (), getDialect ().getSqlTypeResolver ());
227
+ }
228
+
229
+ @ Override
230
+ public JdbcDialect getDialect () {
231
+ return (JdbcDialect ) super .getDialect ();
226
232
}
227
233
228
234
/**
@@ -238,7 +244,9 @@ JdbcQueryMethod getJdbcQueryMethod(Method method, RepositoryMetadata repositoryM
238
244
* @param queryMappingConfiguration must not be {@literal null}
239
245
* @param operations must not be {@literal null}
240
246
* @param beanFactory may be {@literal null}
247
+ * @deprecated please, use {@link #create(Key, ApplicationEventPublisher, EntityCallbacks, RelationalMappingContext, JdbcConverter, JdbcDialect, QueryMappingConfiguration, NamedParameterJdbcOperations, BeanFactory, ValueExpressionDelegate)}
241
248
*/
249
+ @ Deprecated (forRemoval = true , since = "4.0" )
242
250
public static QueryLookupStrategy create (@ Nullable Key key , ApplicationEventPublisher publisher ,
243
251
@ Nullable EntityCallbacks callbacks , RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
244
252
QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
@@ -250,6 +258,52 @@ public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPubl
250
258
Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
251
259
Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
252
260
Assert .notNull (delegate , "ValueExpressionDelegate must not be null" );
261
+ Assert .state (dialect instanceof JdbcDialect , "Dialect must be an instance of the JdbcDialect" );
262
+
263
+ CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy (publisher , callbacks , context ,
264
+ converter , (JdbcDialect ) dialect , queryMappingConfiguration , operations , delegate );
265
+
266
+ DeclaredQueryLookupStrategy declaredQueryLookupStrategy = new DeclaredQueryLookupStrategy (publisher , callbacks ,
267
+ context , converter , (JdbcDialect ) dialect , queryMappingConfiguration , operations , beanFactory , delegate );
268
+
269
+ Key keyToUse = key != null ? key : Key .CREATE_IF_NOT_FOUND ;
270
+
271
+ LOG .debug (String .format ("Using the queryLookupStrategy %s" , keyToUse ));
272
+
273
+ return switch (keyToUse ) {
274
+ case CREATE -> createQueryLookupStrategy ;
275
+ case USE_DECLARED_QUERY -> declaredQueryLookupStrategy ;
276
+ case CREATE_IF_NOT_FOUND ->
277
+ new CreateIfNotFoundQueryLookupStrategy (publisher , callbacks , context , converter , (JdbcDialect ) dialect ,
278
+ queryMappingConfiguration , operations , createQueryLookupStrategy , declaredQueryLookupStrategy , delegate );
279
+ };
280
+ }
281
+
282
+ /**
283
+ * Creates a {@link QueryLookupStrategy} based on the provided
284
+ * {@link org.springframework.data.repository.query.QueryLookupStrategy.Key}.
285
+ *
286
+ * @param key the key that decides what {@link QueryLookupStrategy} shozld be used.
287
+ * @param publisher must not be {@literal null}
288
+ * @param callbacks may be {@literal null}
289
+ * @param context must not be {@literal null}
290
+ * @param converter must not be {@literal null}
291
+ * @param dialect must not be {@literal null}
292
+ * @param queryMappingConfiguration must not be {@literal null}
293
+ * @param operations must not be {@literal null}
294
+ * @param beanFactory may be {@literal null}
295
+ */
296
+ public static QueryLookupStrategy create (@ Nullable Key key , ApplicationEventPublisher publisher ,
297
+ @ Nullable EntityCallbacks callbacks , RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
298
+ QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
299
+ @ Nullable BeanFactory beanFactory , ValueExpressionDelegate delegate ) {
300
+ Assert .notNull (publisher , "ApplicationEventPublisher must not be null" );
301
+ Assert .notNull (context , "RelationalMappingContextPublisher must not be null" );
302
+ Assert .notNull (converter , "JdbcConverter must not be null" );
303
+ Assert .notNull (dialect , "Dialect must not be null" );
304
+ Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
305
+ Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
306
+ Assert .notNull (delegate , "ValueExpressionDelegate must not be null" );
253
307
254
308
CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy (publisher , callbacks , context ,
255
309
converter , dialect , queryMappingConfiguration , operations , delegate );
0 commit comments