Polishing.
Remove unused parameter from DeclaredQuery. Reformat code. See: #3293 Original pull request: #3339
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.QueryRewriter;
|
||||
@@ -80,16 +81,17 @@ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery {
|
||||
|
||||
this.countQuery = Lazy.of(() -> {
|
||||
|
||||
if(StringUtils.hasText(countQueryString)) {
|
||||
if (StringUtils.hasText(countQueryString)) {
|
||||
|
||||
return new ExpressionBasedStringQuery(countQueryString, method.getEntityInformation(), parser,
|
||||
method.isNativeQuery());
|
||||
}
|
||||
return query.deriveCountQuery(null, method.getCountQueryProjection());
|
||||
|
||||
return query.deriveCountQuery(method.getCountQueryProjection());
|
||||
});
|
||||
|
||||
this.countParameterBinder = Lazy.of(() -> {
|
||||
return this.createCountBinder(this.countQuery.get());
|
||||
return this.createBinder(this.countQuery.get());
|
||||
});
|
||||
|
||||
this.parser = parser;
|
||||
@@ -118,13 +120,12 @@ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery {
|
||||
|
||||
@Override
|
||||
protected ParameterBinder createBinder() {
|
||||
|
||||
return ParameterBinderFactory.createQueryAwareBinder(getQueryMethod().getParameters(), query, parser,
|
||||
evaluationContextProvider);
|
||||
return createBinder(query);
|
||||
}
|
||||
|
||||
protected ParameterBinder createCountBinder(DeclaredQuery countQuery) {
|
||||
return ParameterBinderFactory.createQueryAwareBinder(getQueryMethod().getParameters(), countQuery, parser, evaluationContextProvider);
|
||||
protected ParameterBinder createBinder(DeclaredQuery query) {
|
||||
return ParameterBinderFactory.createQueryAwareBinder(getQueryMethod().getParameters(), query, parser,
|
||||
evaluationContextProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,11 +80,10 @@ interface DeclaredQuery {
|
||||
* expected from the original query, either derived from the query wrapped by this instance or from the information
|
||||
* passed as arguments.
|
||||
*
|
||||
* @param countQuery an optional query string to be used if present.
|
||||
* @param countQueryProjection an optional return type for the query.
|
||||
* @return a new {@literal DeclaredQuery} instance.
|
||||
*/
|
||||
DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection);
|
||||
DeclaredQuery deriveCountQuery(@Nullable String countQueryProjection);
|
||||
|
||||
/**
|
||||
* @return whether paging is implemented in the query itself, e.g. using SpEL expressions.
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* NULL-Object pattern implementation for {@link DeclaredQuery}.
|
||||
@@ -65,11 +64,8 @@ class EmptyDeclaredQuery implements DeclaredQuery {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection) {
|
||||
|
||||
Assert.hasText(countQuery, "CountQuery must not be empty");
|
||||
|
||||
return DeclaredQuery.of(countQuery, false);
|
||||
public DeclaredQuery deriveCountQuery(@Nullable String countQueryProjection) {
|
||||
return EMPTY_QUERY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,7 +98,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
/**
|
||||
* Returns whether the named query with the given name exists.
|
||||
*
|
||||
* @param em must not be {@literal null}.
|
||||
* @param em must not be {@literal null}.
|
||||
* @param queryName must not be {@literal null}.
|
||||
*/
|
||||
static boolean hasNamedQuery(EntityManager em, String queryName) {
|
||||
@@ -127,7 +127,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
* Looks up a named query for the given {@link org.springframework.data.repository.query.QueryMethod}.
|
||||
*
|
||||
* @param method must not be {@literal null}.
|
||||
* @param em must not be {@literal null}.
|
||||
* @param em must not be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) {
|
||||
@@ -190,7 +190,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
|
||||
} else {
|
||||
|
||||
String countQueryString = declaredQuery.deriveCountQuery(null, countProjection).getQueryString();
|
||||
String countQueryString = declaredQuery.deriveCountQuery(countProjection).getQueryString();
|
||||
cacheKey = countQueryString;
|
||||
countQuery = em.createQuery(countQueryString, Long.class);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ class StringQuery implements DeclaredQuery {
|
||||
*
|
||||
* @param query must not be {@literal null} or empty.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
StringQuery(String query, boolean isNative) {
|
||||
|
||||
Assert.hasText(query, "Query must not be null or empty");
|
||||
@@ -109,16 +108,12 @@ class StringQuery implements DeclaredQuery {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection) {
|
||||
|
||||
if(StringUtils.hasText(countQuery)) {
|
||||
return new StringQuery(countQuery, this.isNative);
|
||||
}
|
||||
public DeclaredQuery deriveCountQuery(@Nullable String countQueryProjection) {
|
||||
|
||||
StringQuery stringQuery = new StringQuery(this.queryEnhancer.createCountQueryFor(countQueryProjection), //
|
||||
this.isNative);
|
||||
|
||||
if(this.hasParameterBindings() && !this.getParameterBindings().equals(stringQuery.getParameterBindings())) {
|
||||
if (this.hasParameterBindings() && !this.getParameterBindings().equals(stringQuery.getParameterBindings())) {
|
||||
stringQuery.getParameterBindings().clear();
|
||||
stringQuery.getParameterBindings().addAll(this.bindings);
|
||||
}
|
||||
@@ -289,7 +284,6 @@ class StringQuery implements DeclaredQuery {
|
||||
parameterIndex = expressionParameterIndex;
|
||||
}
|
||||
|
||||
|
||||
BindingIdentifier queryParameter;
|
||||
if (parameterIndex != null) {
|
||||
queryParameter = BindingIdentifier.of(parameterIndex);
|
||||
|
||||
Reference in New Issue
Block a user