2323import org .springframework .context .ApplicationEventPublisher ;
2424import org .springframework .data .jdbc .core .convert .JdbcConverter ;
2525import org .springframework .data .jdbc .core .convert .QueryMappingConfiguration ;
26+ import org .springframework .data .jdbc .core .dialect .JdbcDialect ;
2627import org .springframework .data .jdbc .repository .query .DefaultRowMapperFactory ;
2728import org .springframework .data .jdbc .repository .query .JdbcQueryMethod ;
2829import org .springframework .data .jdbc .repository .query .PartTreeJdbcQuery ;
@@ -69,7 +70,7 @@ abstract class JdbcQueryLookupStrategy extends RelationalQueryLookupStrategy {
6970 protected final ValueExpressionDelegate delegate ;
7071
7172 JdbcQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
72- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
73+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
7374 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
7475 ValueExpressionDelegate delegate ) {
7576
@@ -105,7 +106,7 @@ static class CreateQueryLookupStrategy extends JdbcQueryLookupStrategy {
105106 private final RowMapperFactory rowMapperFactory ;
106107
107108 CreateQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
108- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
109+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
109110 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
110111 ValueExpressionDelegate delegate ) {
111112
@@ -138,7 +139,7 @@ static class DeclaredQueryLookupStrategy extends JdbcQueryLookupStrategy {
138139 private final RowMapperFactory rowMapperFactory ;
139140
140141 DeclaredQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
141- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
142+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
142143 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
143144 @ Nullable BeanFactory beanfactory , ValueExpressionDelegate delegate ) {
144145 super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations , delegate );
@@ -191,7 +192,7 @@ static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy
191192 * @param lookupStrategy must not be {@literal null}.
192193 */
193194 CreateIfNotFoundQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
194- RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
195+ RelationalMappingContext context , JdbcConverter converter , JdbcDialect dialect ,
195196 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
196197 CreateQueryLookupStrategy createStrategy , DeclaredQueryLookupStrategy lookupStrategy ,
197198 ValueExpressionDelegate delegate ) {
@@ -225,6 +226,11 @@ JdbcQueryMethod getJdbcQueryMethod(Method method, RepositoryMetadata repositoryM
225226 return new JdbcQueryMethod (method , repositoryMetadata , projectionFactory , namedQueries , getMappingContext (), getDialect ().getSqlTypeResolver ());
226227 }
227228
229+ @ Override
230+ public JdbcDialect getDialect () {
231+ return (JdbcDialect ) super .getDialect ();
232+ }
233+
228234 /**
229235 * Creates a {@link QueryLookupStrategy} based on the provided
230236 * {@link org.springframework.data.repository.query.QueryLookupStrategy.Key}.
@@ -238,7 +244,9 @@ JdbcQueryMethod getJdbcQueryMethod(Method method, RepositoryMetadata repositoryM
238244 * @param queryMappingConfiguration must not be {@literal null}
239245 * @param operations must not be {@literal null}
240246 * @param beanFactory may be {@literal null}
247+ * @deprecated please, use {@link #create(Key, ApplicationEventPublisher, EntityCallbacks, RelationalMappingContext, JdbcConverter, JdbcDialect, QueryMappingConfiguration, NamedParameterJdbcOperations, BeanFactory, ValueExpressionDelegate)}
241248 */
249+ @ Deprecated (forRemoval = true , since = "4.0" )
242250 public static QueryLookupStrategy create (@ Nullable Key key , ApplicationEventPublisher publisher ,
243251 @ Nullable EntityCallbacks callbacks , RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
244252 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
@@ -250,6 +258,52 @@ public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPubl
250258 Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
251259 Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
252260 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" );
253307
254308 CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy (publisher , callbacks , context ,
255309 converter , dialect , queryMappingConfiguration , operations , delegate );
0 commit comments