Skip to content

Commit 88b0b3c

Browse files
mp911deodrotbohm
authored andcommitted
DATACMNS-1556 - Store values as array in ParametersParameterAccessor.
Prevents changes in store modules that expose values as array.
1 parent b8c0a2f commit 88b0b3c

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java

+14-16
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package org.springframework.data.repository.query;
1717

18-
import java.util.ArrayList;
19-
import java.util.Arrays;
2018
import java.util.Iterator;
21-
import java.util.List;
2219
import java.util.Optional;
2320

2421
import org.springframework.data.domain.Pageable;
@@ -36,7 +33,7 @@
3633
public class ParametersParameterAccessor implements ParameterAccessor {
3734

3835
private final Parameters<?, ?> parameters;
39-
private final List<Object> values;
36+
private final Object[] values;
4037

4138
/**
4239
* Creates a new {@link ParametersParameterAccessor}.
@@ -54,12 +51,13 @@ public ParametersParameterAccessor(Parameters<?, ?> parameters, Object[] values)
5451
this.parameters = parameters;
5552

5653
if (requiresUnwrapping(values)) {
57-
this.values = new ArrayList<>(values.length);
58-
for (Object value : values) {
59-
this.values.add(QueryExecutionConverters.unwrap(value));
54+
this.values = new Object[values.length];
55+
56+
for (int i = 0; i < values.length; i++) {
57+
this.values[i] = QueryExecutionConverters.unwrap(values[i]);
6058
}
6159
} else {
62-
this.values = Arrays.asList(values);
60+
this.values = values;
6361
}
6462
}
6563

@@ -88,7 +86,7 @@ private static boolean requiresUnwrapping(Object[] values) {
8886
*
8987
* @return
9088
*/
91-
protected List<Object> getValues() {
89+
protected Object[] getValues() {
9290
return this.values;
9391
}
9492

@@ -102,7 +100,7 @@ public Pageable getPageable() {
102100
return Pageable.unpaged();
103101
}
104102

105-
Pageable pageable = (Pageable) values.get(parameters.getPageableIndex());
103+
Pageable pageable = (Pageable) values[parameters.getPageableIndex()];
106104

107105
return pageable == null ? Pageable.unpaged() : pageable;
108106
}
@@ -115,7 +113,7 @@ public Sort getSort() {
115113

116114
if (parameters.hasSortParameter()) {
117115

118-
Sort sort = (Sort) values.get(parameters.getSortIndex());
116+
Sort sort = (Sort) values[parameters.getSortIndex()];
119117
return sort == null ? Sort.unsorted() : sort;
120118
}
121119

@@ -134,7 +132,7 @@ public Sort getSort() {
134132
public Optional<Class<?>> getDynamicProjection() {
135133

136134
return Optional.ofNullable(parameters.hasDynamicProjection() //
137-
? (Class<?>) values.get(parameters.getDynamicProjectionIndex()) //
135+
? (Class<?>) values[parameters.getDynamicProjectionIndex()] //
138136
: null);
139137
}
140138

@@ -147,7 +145,7 @@ public Optional<Class<?>> getDynamicProjection() {
147145
public Class<?> findDynamicProjection() {
148146

149147
return parameters.hasDynamicProjection() //
150-
? (Class<?>) values.get(parameters.getDynamicProjectionIndex())
148+
? (Class<?>) values[parameters.getDynamicProjectionIndex()]
151149
: null;
152150
}
153151

@@ -159,15 +157,15 @@ public Class<?> findDynamicProjection() {
159157
*/
160158
@SuppressWarnings("unchecked")
161159
protected <T> T getValue(int index) {
162-
return (T) values.get(index);
160+
return (T) values[index];
163161
}
164162

165163
/*
166164
* (non-Javadoc)
167165
* @see org.springframework.data.repository.query.ParameterAccessor#getBindableValue(int)
168166
*/
169167
public Object getBindableValue(int index) {
170-
return values.get(parameters.getBindableParameter(index).getIndex());
168+
return values[parameters.getBindableParameter(index).getIndex()];
171169
}
172170

173171
/*
@@ -177,7 +175,7 @@ public Object getBindableValue(int index) {
177175
public boolean hasBindableNullValue() {
178176

179177
for (Parameter parameter : parameters.getBindableParameters()) {
180-
if (values.get(parameter.getIndex()) == null) {
178+
if (values[parameter.getIndex()] == null) {
181179
return true;
182180
}
183181
}

0 commit comments

Comments
 (0)