@@ -157,12 +157,14 @@ public void execute() throws Throwable {
157
157
158
158
@ Test
159
159
public void testUnwrap () throws SQLException {
160
+ assertEquals (stmt , stmt .unwrap (TarantoolStatement .class ));
160
161
assertEquals (stmt , stmt .unwrap (SQLStatement .class ));
161
162
assertThrows (SQLException .class , () -> stmt .unwrap (Integer .class ));
162
163
}
163
164
164
165
@ Test
165
166
public void testIsWrapperFor () throws SQLException {
167
+ assertTrue (stmt .isWrapperFor (TarantoolStatement .class ));
166
168
assertTrue (stmt .isWrapperFor (SQLStatement .class ));
167
169
assertFalse (stmt .isWrapperFor (Integer .class ));
168
170
}
@@ -246,4 +248,103 @@ void testStatementConnection() throws SQLException {
246
248
Statement statement = conn .createStatement ();
247
249
assertEquals (conn , statement .getConnection ());
248
250
}
251
+
252
+ @ Test
253
+ void testCloseOnCompletion () throws SQLException {
254
+ assertFalse (stmt .isCloseOnCompletion ());
255
+ stmt .closeOnCompletion ();
256
+ assertTrue (stmt .isCloseOnCompletion ());
257
+ }
258
+
259
+ @ Test
260
+ void testCloseOnCompletionDisabled () throws SQLException {
261
+ ResultSet resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=1" );
262
+ assertFalse (stmt .isClosed ());
263
+ assertFalse (resultSet .isClosed ());
264
+
265
+ resultSet .close ();
266
+ assertTrue (resultSet .isClosed ());
267
+ assertFalse (stmt .isClosed ());
268
+ }
269
+
270
+ @ Test
271
+ void testCloseOnCompletionEnabled () throws SQLException {
272
+ stmt .closeOnCompletion ();
273
+ ResultSet resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=1" );
274
+
275
+ assertFalse (stmt .isClosed ());
276
+ assertFalse (resultSet .isClosed ());
277
+
278
+ resultSet .close ();
279
+ assertTrue (resultSet .isClosed ());
280
+ assertTrue (stmt .isClosed ());
281
+ }
282
+
283
+ @ Test
284
+ void testCloseOnCompletionAfterResultSet () throws SQLException {
285
+ ResultSet resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=1" );
286
+ stmt .closeOnCompletion ();
287
+
288
+ assertFalse (stmt .isClosed ());
289
+ assertFalse (resultSet .isClosed ());
290
+
291
+ resultSet .close ();
292
+ assertTrue (resultSet .isClosed ());
293
+ assertTrue (stmt .isClosed ());
294
+ }
295
+
296
+ @ Test
297
+ void testCloseOnCompletionMultipleResultSets () throws SQLException {
298
+ stmt .closeOnCompletion ();
299
+ ResultSet resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=1" );
300
+ ResultSet anotherResultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=2" );
301
+
302
+ assertTrue (resultSet .isClosed ());
303
+ assertFalse (anotherResultSet .isClosed ());
304
+ assertFalse (stmt .isClosed ());
305
+
306
+ anotherResultSet .close ();
307
+ assertTrue (anotherResultSet .isClosed ());
308
+ assertTrue (stmt .isClosed ());
309
+ }
310
+
311
+ @ Test
312
+ void testCloseOnCompletionUpdateQueries () throws SQLException {
313
+ stmt .closeOnCompletion ();
314
+
315
+ int updateCount = stmt .executeUpdate ("INSERT INTO test(id, val) VALUES (5, 'five')" );
316
+ assertEquals (1 , updateCount );
317
+ assertFalse (stmt .isClosed ());
318
+
319
+ updateCount = stmt .executeUpdate ("INSERT INTO test(id, val) VALUES (6, 'six')" );
320
+ assertEquals (1 , updateCount );
321
+ assertFalse (stmt .isClosed ());
322
+ }
323
+
324
+ @ Test
325
+ void testCloseOnCompletionMixedQueries () throws SQLException {
326
+ stmt .closeOnCompletion ();
327
+
328
+ int updateCount = stmt .executeUpdate ("INSERT INTO test(id, val) VALUES (7, 'seven')" );
329
+ assertEquals (1 , updateCount );
330
+ assertFalse (stmt .isClosed ());
331
+
332
+ ResultSet resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=7" );
333
+ assertFalse (resultSet .isClosed ());
334
+ assertFalse (stmt .isClosed ());
335
+
336
+ updateCount = stmt .executeUpdate ("INSERT INTO test(id, val) VALUES (8, 'eight')" );
337
+ assertEquals (1 , updateCount );
338
+ assertTrue (resultSet .isClosed ());
339
+ assertFalse (stmt .isClosed ());
340
+
341
+ resultSet = stmt .executeQuery ("SELECT val FROM test WHERE id=8" );
342
+ assertFalse (resultSet .isClosed ());
343
+ assertFalse (stmt .isClosed ());
344
+
345
+ resultSet .close ();
346
+ assertTrue (resultSet .isClosed ());
347
+ assertTrue (stmt .isClosed ());
348
+ }
349
+
249
350
}
0 commit comments