Refactor iterator of Map with Java8's Map.forEach

See gh-1459
This commit is contained in:
diguage
2017-06-13 17:53:13 +08:00
committed by Stephane Nicoll
parent 7018804e84
commit 1ef5f61ab2
18 changed files with 72 additions and 130 deletions

View File

@@ -131,13 +131,12 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
*/
public MapSqlParameterSource addValues(@Nullable Map<String, ?> values) {
if (values != null) {
for (Map.Entry<String, ?> entry : values.entrySet()) {
this.values.put(entry.getKey(), entry.getValue());
if (entry.getValue() instanceof SqlParameterValue) {
SqlParameterValue value = (SqlParameterValue) entry.getValue();
registerSqlType(entry.getKey(), value.getSqlType());
values.forEach((key, value) -> {
this.values.put(key, value);
if (value instanceof SqlParameterValue) {
registerSqlType(key, ((SqlParameterValue) value).getSqlType());
}
}
});
}
return this;
}

View File

@@ -114,11 +114,11 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
throw new IllegalArgumentException("Property 'targetDataSources' is required");
}
this.resolvedDataSources = new HashMap<>(this.targetDataSources.size());
for (Map.Entry<Object, Object> entry : this.targetDataSources.entrySet()) {
Object lookupKey = resolveSpecifiedLookupKey(entry.getKey());
DataSource dataSource = resolveSpecifiedDataSource(entry.getValue());
this.targetDataSources.forEach((key, value) -> {
Object lookupKey = resolveSpecifiedLookupKey(key);
DataSource dataSource = resolveSpecifiedDataSource(value);
this.resolvedDataSources.put(lookupKey, dataSource);
}
});
if (this.defaultTargetDataSource != null) {
this.resolvedDefaultDataSource = resolveSpecifiedDataSource(this.defaultTargetDataSource);
}