Browse Source

Adds support for qualifying columns with table.

Adds support common in other ResultSet implemenatations for qualifying column names with table name to distinguish potentially duplicate column names in a join of two or more tables from one another. The expected format is {table_name}.{column_namne}, where column_name is the actuall designated column name and not the column label.
pull/32782/head
Chad Attermann 2 years ago committed by Juergen Hoeller
parent
commit
cb48077698
  1. 11
      spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java

11
spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java

@ -99,7 +99,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { @@ -99,7 +99,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
ResultSetMetaData rsmd = resultSet.getMetaData();
if (rsmd != null) {
int columnCount = rsmd.getColumnCount();
this.columnLabelMap = CollectionUtils.newHashMap(columnCount);
this.columnLabelMap = CollectionUtils.newHashMap(columnCount * 2);
for (int i = 1; i <= columnCount; i++) {
String key = rsmd.getColumnLabel(i);
// Make sure to preserve first matching column for any given name,
@ -107,6 +107,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { @@ -107,6 +107,15 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
if (!this.columnLabelMap.containsKey(key)) {
this.columnLabelMap.put(key, i);
}
// Also support column names prefixed with table name
// as in {table_name}.{column.name}.
String table = rsmd.getTableName(i);
if (table != null && !table.isEmpty()) {
key = table + "." + rsmd.getColumnName(i);
if (!this.columnLabelMap.containsKey(key)) {
this.columnLabelMap.put(key, i);
}
}
}
}
else {

Loading…
Cancel
Save