22
22
import java .sql .DatabaseMetaData ;
23
23
import java .sql .PreparedStatement ;
24
24
import java .sql .ResultSet ;
25
+ import java .sql .ResultSetMetaData ;
25
26
import java .sql .SQLException ;
26
27
import java .sql .SQLWarning ;
27
28
import java .sql .Statement ;
28
29
import java .sql .Types ;
29
30
import java .util .ArrayList ;
30
31
import java .util .Arrays ;
32
+ import java .util .Collections ;
31
33
import java .util .LinkedList ;
32
34
import java .util .List ;
33
35
import java .util .Map ;
@@ -704,10 +706,10 @@ public int getBatchSize() {
704
706
@ Test
705
707
public void testBatchUpdateWithListOfObjectArrays () throws Exception {
706
708
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
707
- final List <Object []> ids = new ArrayList <>();
709
+ final List <Object []> ids = new ArrayList <>(2 );
708
710
ids .add (new Object [] {100 });
709
711
ids .add (new Object [] {200 });
710
- final int [] rowsAffected = new int [] { 1 , 2 };
712
+ final int [] rowsAffected = new int [] {1 , 2 };
711
713
712
714
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
713
715
mockDatabaseMetaData (true );
@@ -730,11 +732,11 @@ public void testBatchUpdateWithListOfObjectArrays() throws Exception {
730
732
@ Test
731
733
public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo () throws Exception {
732
734
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?" ;
733
- final List <Object []> ids = new ArrayList <>();
735
+ final List <Object []> ids = new ArrayList <>(2 );
734
736
ids .add (new Object [] {100 });
735
737
ids .add (new Object [] {200 });
736
738
final int [] sqlTypes = new int [] {Types .NUMERIC };
737
- final int [] rowsAffected = new int [] { 1 , 2 };
739
+ final int [] rowsAffected = new int [] {1 , 2 };
738
740
739
741
given (this .preparedStatement .executeBatch ()).willReturn (rowsAffected );
740
742
mockDatabaseMetaData (true );
@@ -1070,14 +1072,13 @@ public void testExecuteClosed() throws Exception {
1070
1072
given (this .callableStatement .execute ()).willReturn (true );
1071
1073
given (this .callableStatement .getUpdateCount ()).willReturn (-1 );
1072
1074
1073
- List <SqlParameter > params = new ArrayList <>();
1074
- params .add (new SqlReturnResultSet ("" , (RowCallbackHandler ) rs -> {
1075
+ SqlParameter param = new SqlReturnResultSet ("" , (RowCallbackHandler ) rs -> {
1075
1076
throw new InvalidDataAccessApiUsageException ("" );
1076
- })) ;
1077
+ });
1077
1078
1078
1079
this .thrown .expect (InvalidDataAccessApiUsageException .class );
1079
1080
try {
1080
- this .template .call (conn -> conn .prepareCall ("my query" ), params );
1081
+ this .template .call (conn -> conn .prepareCall ("my query" ), Collections . singletonList ( param ) );
1081
1082
}
1082
1083
finally {
1083
1084
verify (this .resultSet ).close ();
@@ -1099,10 +1100,8 @@ public void testCaseInsensitiveResultsMap() throws Exception {
1099
1100
assertTrue ("now it should have been set to case insensitive" ,
1100
1101
this .template .isResultsMapCaseInsensitive ());
1101
1102
1102
- List <SqlParameter > params = new ArrayList <>();
1103
- params .add (new SqlOutParameter ("a" , 12 ));
1104
-
1105
- Map <String , Object > out = this .template .call (conn -> conn .prepareCall ("my query" ), params );
1103
+ Map <String , Object > out = this .template .call (
1104
+ conn -> conn .prepareCall ("my query" ), Collections .singletonList (new SqlOutParameter ("a" , 12 )));
1106
1105
1107
1106
assertThat (out , instanceOf (LinkedCaseInsensitiveMap .class ));
1108
1107
assertNotNull ("we should have gotten the result with upper case" , out .get ("A" ));
@@ -1111,6 +1110,25 @@ public void testCaseInsensitiveResultsMap() throws Exception {
1111
1110
verify (this .connection ).close ();
1112
1111
}
1113
1112
1113
+ @ Test // SPR-16578
1114
+ public void testEquallyNamedColumn () throws SQLException {
1115
+ given (this .connection .createStatement ()).willReturn (this .statement );
1116
+
1117
+ ResultSetMetaData metaData = mock (ResultSetMetaData .class );
1118
+ given (metaData .getColumnCount ()).willReturn (2 );
1119
+ given (metaData .getColumnLabel (1 )).willReturn ("x" );
1120
+ given (metaData .getColumnLabel (2 )).willReturn ("X" );
1121
+ given (this .resultSet .getMetaData ()).willReturn (metaData );
1122
+
1123
+ given (this .resultSet .next ()).willReturn (true , false );
1124
+ given (this .resultSet .getObject (1 )).willReturn ("first value" );
1125
+ given (this .resultSet .getObject (2 )).willReturn ("second value" );
1126
+
1127
+ Map <String , Object > map = this .template .queryForMap ("my query" );
1128
+ assertEquals (1 , map .size ());
1129
+ assertEquals ("first value" , map .get ("x" ));
1130
+ }
1131
+
1114
1132
1115
1133
private void mockDatabaseMetaData (boolean supportsBatchUpdates ) throws SQLException {
1116
1134
DatabaseMetaData databaseMetaData = mock (DatabaseMetaData .class );
0 commit comments