Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -265,18 +266,19 @@ public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource p
* @param inParameters the parameter names and values
*/
public List<Object> matchInParameterValuesWithInsertColumns(Map<String, ?> inParameters) {
List<Object> values = new ArrayList<>(inParameters.size());
List<Object> values = new ArrayList<>(this.tableColumns.size());

Map<String, Object> caseInsensitiveLookup = new HashMap<>(inParameters.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring itself provides a LinkedCaseInsensitiveMap which provides this functionality already. Wouldn't it be easier to use that, it seems to be used in other places in the JDBC access already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the implementation to use LinkedCaseInsensitiveMap instead of manually creating a case-insensitive lookup map. The changes are available in commit cdb149b

for (Map.Entry<String, ?> entry : inParameters.entrySet()) {
caseInsensitiveLookup.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue());
}

for (String column : this.tableColumns) {
Object value = inParameters.get(column);
if (value == null) {
value = inParameters.get(column.toLowerCase(Locale.ROOT));
if (value == null) {
for (Map.Entry<String, ?> entry : inParameters.entrySet()) {
if (column.equalsIgnoreCase(entry.getKey())) {
value = entry.getValue();
break;
}
}
value = caseInsensitiveLookup.get(column.toLowerCase(Locale.ROOT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using the LinkedCaseInsensitiveMap you can just do a regular get without the need to convert to lowercase (the map will take care of this). Which would simplify this code.

}
}
values.add(value);
Expand Down