DATACMNS-1827 - Polishing.
Extract qualifier lookup into SpringDataAnnotationUtils. Original pull request: #474.
This commit is contained in:
@@ -231,7 +231,7 @@ public abstract class PageableHandlerMethodArgumentResolverSupport {
|
||||
|
||||
StringBuilder builder = new StringBuilder(prefix);
|
||||
|
||||
String value = getQualifier(parameter);
|
||||
String value = SpringDataAnnotationUtils.getQualifier(parameter);
|
||||
|
||||
if (StringUtils.hasLength(value)) {
|
||||
builder.append(value);
|
||||
@@ -292,16 +292,5 @@ public abstract class PageableHandlerMethodArgumentResolverSupport {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getQualifier(@Nullable MethodParameter parameter) {
|
||||
|
||||
if (parameter == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
|
||||
MergedAnnotation<Qualifier> qualifier = annotations.get(Qualifier.class);
|
||||
|
||||
return qualifier.isPresent() ? qualifier.getString("value") : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public abstract class SortHandlerMethodArgumentResolverSupport {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
String value = getQualifier(parameter);
|
||||
String value = SpringDataAnnotationUtils.getQualifier(parameter);
|
||||
|
||||
if (StringUtils.hasLength(value)) {
|
||||
builder.append(value);
|
||||
@@ -295,19 +295,6 @@ public abstract class SortHandlerMethodArgumentResolverSupport {
|
||||
return StringUtils.hasText(source.replace(".", ""));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getQualifier(@Nullable MethodParameter parameter) {
|
||||
|
||||
if (parameter == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
|
||||
MergedAnnotation<Qualifier> qualifier = annotations.get(Qualifier.class);
|
||||
|
||||
return qualifier.isPresent() ? qualifier.getString("value") : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to easily build request parameter expressions for {@link Sort} instances.
|
||||
*
|
||||
|
||||
@@ -23,15 +23,18 @@ import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Helper class to ease sharing code between legacy {@link PageableArgumentResolver} and
|
||||
* {@link PageableHandlerMethodArgumentResolver}.
|
||||
* Helper class to ease sharing code between legacy {@link PageableHandlerMethodArgumentResolverSupport} and
|
||||
* {@link SortHandlerMethodArgumentResolverSupport}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
abstract class SpringDataAnnotationUtils {
|
||||
|
||||
@@ -105,6 +108,26 @@ abstract class SpringDataAnnotationUtils {
|
||||
return (T) result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine a qualifier value for a {@link MethodParameter}.
|
||||
*
|
||||
* @param parameter must not be {@literal null}.
|
||||
* @return the qualifier value if {@code @Qualifier} is present.
|
||||
* @since 2.5
|
||||
*/
|
||||
@Nullable
|
||||
public static String getQualifier(@Nullable MethodParameter parameter) {
|
||||
|
||||
if (parameter == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
|
||||
MergedAnnotation<Qualifier> qualifier = annotations.get(Qualifier.class);
|
||||
|
||||
return qualifier.isPresent() ? qualifier.getString("value") : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that every {@link Pageable} parameter of the given parameters carries an {@link Qualifier} annotation to
|
||||
* distinguish them from each other.
|
||||
@@ -154,4 +177,5 @@ abstract class SpringDataAnnotationUtils {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user