Skip to content

Commit 0419f49

Browse files
committed
Minor refactoring.
1 parent 36d3a4a commit 0419f49

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ private Entry<String, KeyAssigner> getAssignerForParamMap(Configuration config,
159159
int firstDot = keyProperty.indexOf('.');
160160
if (firstDot == -1) {
161161
if (singleParam) {
162-
// Assume 'keyProperty' to be a property of the single param.
163-
String singleParamName = nameOfSingleParam(paramMap);
164-
String argParamName = omitParamName ? null : singleParamName;
165-
return entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty));
162+
return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName);
166163
}
167164
throw new ExecutorException("Could not determine which parameter to assign generated keys to. "
168165
+ "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). "
@@ -175,10 +172,7 @@ private Entry<String, KeyAssigner> getAssignerForParamMap(Configuration config,
175172
String argKeyProperty = keyProperty.substring(firstDot + 1);
176173
return entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty));
177174
} else if (singleParam) {
178-
// Assume 'keyProperty' to be a property of the single param.
179-
String singleParamName = nameOfSingleParam(paramMap);
180-
String argParamName = omitParamName ? null : singleParamName;
181-
return entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty));
175+
return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName);
182176
} else {
183177
throw new ExecutorException("Could not find parameter '" + paramName + "'. "
184178
+ "Note that when there are multiple parameters, 'keyProperty' must include the parameter name (e.g. 'param.id'). "
@@ -187,6 +181,14 @@ private Entry<String, KeyAssigner> getAssignerForParamMap(Configuration config,
187181
}
188182
}
189183

184+
private Entry<String, KeyAssigner> getAssignerForSingleParam(Configuration config, ResultSetMetaData rsmd,
185+
int columnPosition, Map<String, ?> paramMap, String keyProperty, boolean omitParamName) {
186+
// Assume 'keyProperty' to be a property of the single param.
187+
String singleParamName = nameOfSingleParam(paramMap);
188+
String argParamName = omitParamName ? null : singleParamName;
189+
return entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty));
190+
}
191+
190192
private static String nameOfSingleParam(Map<String, ?> paramMap) {
191193
// There is virtually one parameter, so any key works.
192194
return paramMap.keySet().iterator().next();
@@ -208,13 +210,13 @@ private static <K, V> Entry<K, V> entry(K key, V value) {
208210
}
209211

210212
private class KeyAssigner {
211-
protected final Configuration configuration;
212-
protected final ResultSetMetaData rsmd;
213-
protected final TypeHandlerRegistry typeHandlerRegistry;
214-
protected final int columnPosition;
215-
protected final String paramName;
216-
protected final String propertyName;
217-
protected TypeHandler<?> typeHandler;
213+
private final Configuration configuration;
214+
private final ResultSetMetaData rsmd;
215+
private final TypeHandlerRegistry typeHandlerRegistry;
216+
private final int columnPosition;
217+
private final String paramName;
218+
private final String propertyName;
219+
private TypeHandler<?> typeHandler;
218220

219221
protected KeyAssigner(Configuration configuration, ResultSetMetaData rsmd, int columnPosition, String paramName,
220222
String propertyName) {

0 commit comments

Comments
 (0)