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