Skip to content

Commit 0a7af47

Browse files
committed
add a cache for genericParamName
1 parent e836410 commit 0a7af47

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/main/java/org/apache/ibatis/reflection/ParamNameResolver.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public class ParamNameResolver {
3535

3636
public static final String GENERIC_NAME_PREFIX = "param";
3737

38+
public static final String[] GENERIC_NAME_CACHE = new String[10];
39+
40+
static {
41+
for (int i = 0; i < 10; i++) {
42+
GENERIC_NAME_CACHE[i] = GENERIC_NAME_PREFIX + (i + 1);
43+
}
44+
}
45+
3846
private final boolean useActualParamName;
3947

4048
/**
@@ -129,15 +137,19 @@ public Object getNamedParams(Object[] args) {
129137
} else {
130138
final Map<String, Object> param = new ParamMap<>();
131139
int i = 0;
132-
for (Map.Entry<Integer, String> entry : names.entrySet()) {
133-
param.put(entry.getValue(), args[entry.getKey()]);
134-
// add generic param names (param1, param2, ...)
135-
final String genericParamName = GENERIC_NAME_PREFIX + (i + 1);
136-
// ensure not to overwrite parameter named with @Param
137-
if (!names.containsValue(genericParamName)) {
138-
param.put(genericParamName, args[entry.getKey()]);
140+
try {
141+
for (Map.Entry<Integer, String> entry : names.entrySet()) {
142+
param.put(entry.getValue(), args[entry.getKey()]);
143+
// add generic param names (param1, param2, ...)
144+
final String genericParamName = GENERIC_NAME_CACHE[i];
145+
// ensure not to overwrite parameter named with @Param
146+
if (!names.containsValue(genericParamName)) {
147+
param.put(genericParamName, args[entry.getKey()]);
148+
}
149+
i++;
139150
}
140-
i++;
151+
} catch (ArrayIndexOutOfBoundsException e) {
152+
throw new ArrayIndexOutOfBoundsException("The parameter list is too long, the maximum supported length is 10");
141153
}
142154
return param;
143155
}

0 commit comments

Comments
 (0)