DATACMNS-804 - ParametersParameterAccessor now correctly iterates over only the bindable values.
Corrected the way the BindableParametersIterator works by limiting the upper bound of the iteration to the number of actually bindable parameters.
This commit is contained in:
@@ -145,7 +145,7 @@ public class ParametersParameterAccessor implements ParameterAccessor {
|
||||
* @see org.springframework.data.repository.query.ParameterAccessor#iterator()
|
||||
*/
|
||||
public BindableParameterIterator iterator() {
|
||||
return new BindableParameterIterator();
|
||||
return new BindableParameterIterator(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,17 +153,33 @@ public class ParametersParameterAccessor implements ParameterAccessor {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private class BindableParameterIterator implements Iterator<Object> {
|
||||
private static class BindableParameterIterator implements Iterator<Object> {
|
||||
|
||||
private final int bindableParameterCount;
|
||||
private final ParameterAccessor accessor;
|
||||
|
||||
private int currentIndex = 0;
|
||||
|
||||
/**
|
||||
* Creates a new {@link BindableParameterIterator}.
|
||||
*
|
||||
* @param accessor must not be {@literal null}.
|
||||
*/
|
||||
public BindableParameterIterator(ParametersParameterAccessor accessor) {
|
||||
|
||||
Assert.notNull(accessor, "ParametersParameterAccessor must not be null!");
|
||||
|
||||
this.accessor = accessor;
|
||||
this.bindableParameterCount = accessor.getParameters().getBindableParameters().getNumberOfParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next bindable parameter.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object next() {
|
||||
return getBindableValue(currentIndex++);
|
||||
return accessor.getBindableValue(currentIndex++);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,7 +187,7 @@ public class ParametersParameterAccessor implements ParameterAccessor {
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return values.size() > currentIndex;
|
||||
return bindableParameterCount > currentIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user