DATAJPA-1255 - Polishing.
Renamed newly introduced method. Added @since tags for newly introduced API. Original pull request: #247.
This commit is contained in:
@@ -86,8 +86,9 @@ interface DeclaredQuery {
|
||||
|
||||
/**
|
||||
* @return whether paging is implemented in the query itself, e.g. using SpEL expressions.
|
||||
* @since 2.0.6
|
||||
*/
|
||||
default boolean implementsPaging() {
|
||||
default boolean usesPaging() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2017 the original author or authors.
|
||||
* Copyright 2008-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,6 +39,18 @@ public class ParameterBinder {
|
||||
private final Iterable<QueryParameterSetter> parameterSetters;
|
||||
private final boolean useJpaForPaging;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterBinder} for the given {@link JpaParameters} and {@link QueryParameterSetter}s.
|
||||
* Defaults to use JPA API to apply pagination offsets.
|
||||
*
|
||||
* @param parameters must not be {@literal null}.
|
||||
* @param parameterSetters must not be {@literal null}.
|
||||
* @since 2.0.6
|
||||
*/
|
||||
ParameterBinder(JpaParameters parameters, Iterable<QueryParameterSetter> parameterSetters) {
|
||||
this(parameters, parameterSetters, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterBinder} for the given {@link JpaParameters} and {@link QueryParameterSetter}s.
|
||||
*
|
||||
@@ -58,18 +70,6 @@ public class ParameterBinder {
|
||||
this.useJpaForPaging = useJpaForPaging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only for backward compatibility.
|
||||
*
|
||||
* @param parameters must not be {@literal null}.
|
||||
* @param parameterSetters must not be {@literal null}.
|
||||
* @deprecated use three argument constructor instead}
|
||||
*/
|
||||
@Deprecated
|
||||
public ParameterBinder(JpaParameters parameters, Iterable<QueryParameterSetter> parameterSetters) {
|
||||
this(parameters, parameterSetters, true);
|
||||
}
|
||||
|
||||
public <T extends Query> T bind(T jpaQuery, Object[] values) {
|
||||
return bind(jpaQuery, values, ErrorHandling.STRICT);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class ParameterBinderFactory {
|
||||
QueryParameterSetterFactory setterFactory = QueryParameterSetterFactory.basic(parameters);
|
||||
List<ParameterBinding> bindings = getBindings(parameters);
|
||||
|
||||
return new ParameterBinder(parameters, createSetters(bindings, setterFactory), true);
|
||||
return new ParameterBinder(parameters, createSetters(bindings, setterFactory));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ class ParameterBinderFactory {
|
||||
QueryParameterSetterFactory setterFactory = QueryParameterSetterFactory.forCriteriaQuery(parameters, metadata);
|
||||
List<ParameterBinding> bindings = getBindings(parameters);
|
||||
|
||||
return new ParameterBinder(parameters, createSetters(bindings, setterFactory), true);
|
||||
return new ParameterBinder(parameters, createSetters(bindings, setterFactory));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,8 @@ class ParameterBinderFactory {
|
||||
evaluationContextProvider, parameters);
|
||||
QueryParameterSetterFactory basicSetterFactory = QueryParameterSetterFactory.basic(parameters);
|
||||
|
||||
return new ParameterBinder(parameters, createSetters(bindings, query, expressionSetterFactory, basicSetterFactory), !query.implementsPaging());
|
||||
return new ParameterBinder(parameters, createSetters(bindings, query, expressionSetterFactory, basicSetterFactory),
|
||||
!query.usesPaging());
|
||||
}
|
||||
|
||||
private static List<ParameterBinding> getBindings(JpaParameters parameters) {
|
||||
|
||||
@@ -60,6 +60,7 @@ class StringQuery implements DeclaredQuery {
|
||||
*
|
||||
* @param query must not be {@literal null} or empty.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
StringQuery(String query) {
|
||||
|
||||
Assert.hasText(query, "Query must not be null or empty!");
|
||||
@@ -98,17 +99,13 @@ class StringQuery implements DeclaredQuery {
|
||||
* @see org.springframework.data.jpa.repository.query.DeclaredQuery#deriveCountQuery(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection) {
|
||||
|
||||
return DeclaredQuery
|
||||
.of(countQuery != null ? countQuery : QueryUtils.createCountQueryFor(query, countQueryProjection));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implementsPaging() {
|
||||
return containsPageableInSpel;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.jpa.repository.query.DeclaredQuery#getQueryString()
|
||||
@@ -155,6 +152,15 @@ class StringQuery implements DeclaredQuery {
|
||||
return bindings.stream().anyMatch(b -> b.getName() != null);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.jpa.repository.query.DeclaredQuery#usesPaging()
|
||||
*/
|
||||
@Override
|
||||
public boolean usesPaging() {
|
||||
return containsPageableInSpel;
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser that extracts the parameter bindings from a given query string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user