DATACMNS-1556 - Conditionally copy and unwrap query method arguments.

ParametersParameterAccessor now inspects invocation arguments whether we need to unwrap these at all. If not, we skip copying the list of values.
This commit is contained in:
Mark Paluch
2019-07-23 14:00:52 +02:00
committed by Oliver Drotbohm
parent f1bc778098
commit 94c4713e0f

View File

@@ -16,6 +16,7 @@
package org.springframework.data.repository.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
@@ -51,11 +52,26 @@ public class ParametersParameterAccessor implements ParameterAccessor {
Assert.isTrue(parameters.getNumberOfParameters() == values.length, "Invalid number of parameters given!");
this.parameters = parameters;
this.values = new ArrayList<>(values.length);
if (requiresUnwrapping(values)) {
this.values = new ArrayList<>(values.length);
for (Object value : values) {
this.values.add(QueryExecutionConverters.unwrap(value));
}
} else {
this.values = Arrays.asList(values);
}
}
private static boolean requiresUnwrapping(Object[] values) {
for (Object value : values) {
this.values.add(QueryExecutionConverters.unwrap(value));
if (value != null && QueryExecutionConverters.supports(value.getClass())) {
return true;
}
}
return false;
}
/**