Skip to content

Commit cb48077

Browse files
attermannjhoeller
authored andcommitted
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.
1 parent 2d942a6 commit cb48077

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,23 @@ public ResultSetWrappingSqlRowSet(ResultSet resultSet) throws InvalidResultSetAc
9999
ResultSetMetaData rsmd = resultSet.getMetaData();
100100
if (rsmd != null) {
101101
int columnCount = rsmd.getColumnCount();
102-
this.columnLabelMap = CollectionUtils.newHashMap(columnCount);
102+
this.columnLabelMap = CollectionUtils.newHashMap(columnCount * 2);
103103
for (int i = 1; i <= columnCount; i++) {
104104
String key = rsmd.getColumnLabel(i);
105105
// Make sure to preserve first matching column for any given name,
106106
// as defined in ResultSet's type-level javadoc (lines 81 to 83).
107107
if (!this.columnLabelMap.containsKey(key)) {
108108
this.columnLabelMap.put(key, i);
109109
}
110+
// Also support column names prefixed with table name
111+
// as in {table_name}.{column.name}.
112+
String table = rsmd.getTableName(i);
113+
if (table != null && !table.isEmpty()) {
114+
key = table + "." + rsmd.getColumnName(i);
115+
if (!this.columnLabelMap.containsKey(key)) {
116+
this.columnLabelMap.put(key, i);
117+
}
118+
}
110119
}
111120
}
112121
else {

0 commit comments

Comments
 (0)