DATACMNS-791 - Improved messages in QueryMethodeParameterConversionException and ReflectionRepositoryInvoker.
This commit is contained in:
@@ -34,13 +34,16 @@ public class QueryMethodParameterConversionException extends RuntimeException {
|
||||
private final MethodParameter parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@link QueryMethodParameterConversionException} for the given source object, {@link MethodParameter}
|
||||
* and root cause {@link ConversionException}.
|
||||
*
|
||||
* @param source can be {@literal null}.
|
||||
* @param parameter the {@link MethodParameter} the value should've been converted for, must not be {@literal null}..
|
||||
* @param cause the original {@link ConversionException}, must not be {@literal null}.
|
||||
*/
|
||||
public QueryMethodParameterConversionException(Object source, MethodParameter parameter, ConversionException cause) {
|
||||
|
||||
super("message", cause);
|
||||
super(String.format("Failed to convert %s into %s!", source, parameter.getParameterType().getName()), cause);
|
||||
|
||||
Assert.notNull(parameter, "Method parameter must not be null!");
|
||||
Assert.notNull(cause, "ConversionException must not be null!");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.data.repository.core.CrudMethods;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -46,6 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
|
||||
private static final AnnotationAttribute PARAM_ANNOTATION = new AnnotationAttribute(Param.class);
|
||||
private static final String NAME_NOT_FOUND = "Unable to detect parameter names for query method %s! Use @Param or compile with -parameters on JDK 8.";
|
||||
|
||||
private final Object repository;
|
||||
private final CrudMethods methods;
|
||||
@@ -60,7 +62,8 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
* @param metadata must not be {@literal null}.
|
||||
* @param conversionService must not be {@literal null}.
|
||||
*/
|
||||
public ReflectionRepositoryInvoker(Object repository, RepositoryMetadata metadata, ConversionService conversionService) {
|
||||
public ReflectionRepositoryInvoker(Object repository, RepositoryMetadata metadata,
|
||||
ConversionService conversionService) {
|
||||
|
||||
Assert.notNull(repository, "Repository must not be null!");
|
||||
Assert.notNull(metadata, "RepositoryMetadata must not be null!");
|
||||
@@ -229,8 +232,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
String parameterName = param.getParameterName();
|
||||
|
||||
if (!StringUtils.hasText(parameterName)) {
|
||||
throw new IllegalArgumentException("No @Param annotation found on query method " + method.getName()
|
||||
+ " for parameter " + parameterName);
|
||||
throw new IllegalArgumentException(String.format(NAME_NOT_FOUND, ClassUtils.getQualifiedMethodName(method)));
|
||||
}
|
||||
|
||||
Object value = unwrapSingleElement(rawParameters.get(parameterName));
|
||||
|
||||
Reference in New Issue
Block a user