22
22
import java .util .Iterator ;
23
23
import java .util .Map ;
24
24
25
+ import org .slf4j .Logger ;
26
+ import org .slf4j .LoggerFactory ;
25
27
import org .springframework .dao .DataRetrievalFailureException ;
26
28
import org .springframework .data .jdbc .core .convert .RowDocumentExtractorSupport .AggregateContext ;
27
29
import org .springframework .data .jdbc .core .convert .RowDocumentExtractorSupport .RowDocumentSink ;
43
45
*/
44
46
class RowDocumentResultSetExtractor {
45
47
48
+ private static final Logger log = LoggerFactory .getLogger (RowDocumentResultSetExtractor .class );
49
+ public static final String DUPLICATE_COLUMN_WARNING = "ResultSet contains column \" {}\" multiple times. Later column index is {}" ;
50
+
46
51
private final RelationalMappingContext context ;
47
52
private final PathToColumnMapping propertyToColumn ;
48
53
@@ -66,9 +71,13 @@ static RowDocument toRowDocument(ResultSet resultSet) throws SQLException {
66
71
RowDocument document = new RowDocument (columnCount );
67
72
68
73
for (int i = 0 ; i < columnCount ; i ++) {
74
+
69
75
Object rsv = JdbcUtils .getResultSetValue (resultSet , i + 1 );
70
76
String columnName = md .getColumnLabel (i + 1 );
71
- document .put (columnName , rsv instanceof Array a ? a .getArray () : rsv );
77
+ Object old = document .put (columnName , rsv instanceof Array a ? a .getArray () : rsv );
78
+ if (old != null ) {
79
+ log .warn (DUPLICATE_COLUMN_WARNING , columnName , i );
80
+ }
72
81
}
73
82
74
83
return document ;
@@ -107,7 +116,12 @@ public Map<String, Integer> getColumnMap(ResultSet result) {
107
116
Map <String , Integer > columns = new LinkedCaseInsensitiveMap <>(metaData .getColumnCount ());
108
117
109
118
for (int i = 0 ; i < metaData .getColumnCount (); i ++) {
110
- columns .put (metaData .getColumnLabel (i + 1 ), i + 1 );
119
+
120
+ String columnLabel = metaData .getColumnLabel (i + 1 );
121
+ Object old = columns .put (columnLabel , i + 1 );
122
+ if (old != null ) {
123
+ log .warn (DUPLICATE_COLUMN_WARNING , columnLabel , i );
124
+ }
111
125
}
112
126
return columns ;
113
127
} catch (SQLException e ) {
0 commit comments