From 3dfcf557b5429ddd06ae707d69bc1e450f6c981b Mon Sep 17 00:00:00 2001 From: Chad Attermann Date: Tue, 16 Apr 2024 18:43:00 -0600 Subject: [PATCH] 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. --- .../support/rowset/ResultSetWrappingSqlRowSet.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java index d9b68de09bc1..116898d11c0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java @@ -99,7 +99,7 @@ public ResultSetWrappingSqlRowSet(ResultSet resultSet) throws InvalidResultSetAc 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 ResultSetWrappingSqlRowSet(ResultSet resultSet) throws InvalidResultSetAc 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 {