@@ -56,25 +56,13 @@ void retrieveColumnNamesFromMetadata() throws Exception {
56
56
insertJaneSmith (insert );
57
57
}
58
58
59
- @ Test // gh-24013
60
- void retrieveColumnNamesFromMetadataAndUsingQuotedIdentifiers () throws Exception {
61
- SimpleJdbcInsert insert = new SimpleJdbcInsert (embeddedDatabase )
62
- .withTableName ("users" )
63
- .usingGeneratedKeyColumns ("id" )
64
- .usingQuotedIdentifiers ();
65
-
66
- insert .compile ();
67
- // NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
68
- assertThat (insert .getInsertString ()).isEqualTo ("INSERT INTO \" USERS\" (\" FIRST_NAME\" , \" LAST_NAME\" ) VALUES(?, ?)" );
69
-
70
- insertJaneSmith (insert );
71
- }
72
-
73
59
@ Test
74
60
void usingColumns () {
75
61
SimpleJdbcInsert insert = new SimpleJdbcInsert (embeddedDatabase )
62
+ .withoutTableColumnMetaDataAccess ()
76
63
.withTableName ("users" )
77
- .usingColumns ("first_name" , "last_name" );
64
+ .usingColumns ("first_name" , "last_name" )
65
+ .usingGeneratedKeyColumns ("id" );
78
66
79
67
insert .compile ();
80
68
assertThat (insert .getInsertString ()).isEqualTo ("INSERT INTO users (first_name, last_name) VALUES(?, ?)" );
@@ -84,13 +72,16 @@ void usingColumns() {
84
72
85
73
@ Test // gh-24013
86
74
void usingColumnsAndQuotedIdentifiers () throws Exception {
75
+ // NOTE: unquoted identifiers in H2/HSQL must be converted to UPPERCASE
76
+ // since that's how they are stored in the DB metadata.
87
77
SimpleJdbcInsert insert = new SimpleJdbcInsert (embeddedDatabase )
88
- .withTableName ("users" )
89
- .usingColumns ("first_name" , "last_name" )
78
+ .withoutTableColumnMetaDataAccess ()
79
+ .withTableName ("USERS" )
80
+ .usingColumns ("FIRST_NAME" , "LAST_NAME" )
81
+ .usingGeneratedKeyColumns ("id" )
90
82
.usingQuotedIdentifiers ();
91
83
92
84
insert .compile ();
93
- // NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
94
85
assertThat (insert .getInsertString ()).isEqualToIgnoringNewLines ("""
95
86
INSERT INTO "USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
96
87
""" );
@@ -116,9 +107,11 @@ class CustomSchemaTests extends AbstractSimpleJdbcInsertIntegrationTests {
116
107
@ Test
117
108
void usingColumnsWithSchemaName () {
118
109
SimpleJdbcInsert insert = new SimpleJdbcInsert (embeddedDatabase )
110
+ .withoutTableColumnMetaDataAccess ()
119
111
.withSchemaName ("my_schema" )
120
112
.withTableName ("users" )
121
- .usingColumns ("first_name" , "last_name" );
113
+ .usingColumns ("first_name" , "last_name" )
114
+ .usingGeneratedKeyColumns ("id" );
122
115
123
116
insert .compile ();
124
117
assertThat (insert .getInsertString ()).isEqualTo ("INSERT INTO my_schema.users (first_name, last_name) VALUES(?, ?)" );
@@ -128,14 +121,17 @@ void usingColumnsWithSchemaName() {
128
121
129
122
@ Test // gh-24013
130
123
void usingColumnsAndQuotedIdentifiersWithSchemaName () throws Exception {
124
+ // NOTE: unquoted identifiers in H2/HSQL must be converted to UPPERCASE
125
+ // since that's how they are stored in the DB metadata.
131
126
SimpleJdbcInsert insert = new SimpleJdbcInsert (embeddedDatabase )
132
- .withSchemaName ("my_schema" )
133
- .withTableName ("users" )
134
- .usingColumns ("first_name" , "last_name" )
127
+ .withoutTableColumnMetaDataAccess ()
128
+ .withSchemaName ("MY_SCHEMA" )
129
+ .withTableName ("USERS" )
130
+ .usingColumns ("FIRST_NAME" , "LAST_NAME" )
131
+ .usingGeneratedKeyColumns ("id" )
135
132
.usingQuotedIdentifiers ();
136
133
137
134
insert .compile ();
138
- // NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
139
135
assertThat (insert .getInsertString ()).isEqualToIgnoringNewLines ("""
140
136
INSERT INTO "MY_SCHEMA"."USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
141
137
""" );
@@ -182,7 +178,8 @@ protected void assertNumUsers(long count) {
182
178
}
183
179
184
180
protected void insertJaneSmith (SimpleJdbcInsert insert ) {
185
- insert .execute (Map .of ("first_name" , "Jane" , "last_name" , "Smith" ));
181
+ Number id = insert .executeAndReturnKey (Map .of ("first_name" , "Jane" , "last_name" , "Smith" ));
182
+ assertThat (id .intValue ()).isEqualTo (2 );
186
183
assertNumUsers (2 );
187
184
}
188
185
0 commit comments