21
21
* types of cursors.
22
22
* Supports only {@link ResultSet#HOLD_CURSORS_OVER_COMMIT} holdability type.
23
23
*/
24
- public class SQLStatement implements Statement {
24
+ public class SQLStatement implements TarantoolStatement {
25
25
26
26
protected final SQLConnection connection ;
27
27
@@ -31,6 +31,8 @@ public class SQLStatement implements Statement {
31
31
protected SQLResultSet resultSet ;
32
32
protected int updateCount ;
33
33
34
+ private boolean isCloseOnCompletion ;
35
+
34
36
private final int resultSetType ;
35
37
private final int resultSetConcurrency ;
36
38
private final int resultSetHoldability ;
@@ -310,23 +312,44 @@ public boolean isPoolable() throws SQLException {
310
312
throw new SQLFeatureNotSupportedException ();
311
313
}
312
314
315
+ /**
316
+ * {@inheritDoc}
317
+ * <p>
318
+ * <strong>Impl Note:</strong> this method doesn't affect
319
+ * execution methods which close the last result set implicitly.
320
+ * It is applied only when {@link ResultSet#close()} is invoked
321
+ * explicitly by the app.
322
+ *
323
+ * @throws SQLException if this method is called on a closed
324
+ * {@code Statement}
325
+ */
313
326
@ Override
314
327
public void closeOnCompletion () throws SQLException {
315
-
328
+ checkNotClosed ();
329
+ isCloseOnCompletion = true ;
316
330
}
317
331
318
332
@ Override
319
333
public boolean isCloseOnCompletion () throws SQLException {
320
334
checkNotClosed ();
321
- return false ;
335
+ return isCloseOnCompletion ;
336
+ }
337
+
338
+ @ Override
339
+ public void checkCompletion () throws SQLException {
340
+ if (isCloseOnCompletion &&
341
+ resultSet != null &&
342
+ resultSet .isClosed ()) {
343
+ close ();
344
+ }
322
345
}
323
346
324
347
@ Override
325
348
public <T > T unwrap (Class <T > type ) throws SQLException {
326
349
if (isWrapperFor (type )) {
327
350
return type .cast (this );
328
351
}
329
- throw new SQLNonTransientException ("Statement does not wrap " + type .getName ());
352
+ throw new SQLNonTransientException ("SQLStatement does not wrap " + type .getName ());
330
353
}
331
354
332
355
@ Override
@@ -338,15 +361,18 @@ public boolean isWrapperFor(Class<?> type) throws SQLException {
338
361
* Clears the results of the most recent execution.
339
362
*/
340
363
protected void discardLastResults () throws SQLException {
364
+ final SQLResultSet lastResultSet = resultSet ;
365
+
341
366
clearWarnings ();
342
367
updateCount = -1 ;
343
- if (resultSet != null ) {
368
+ resultSet = null ;
369
+
370
+ if (lastResultSet != null ) {
344
371
try {
345
- resultSet .close ();
372
+ lastResultSet .close ();
346
373
} catch (Exception ignored ) {
347
374
// No-op.
348
375
}
349
- resultSet = null ;
350
376
}
351
377
}
352
378
@@ -375,16 +401,7 @@ protected boolean executeInternal(String sql, Object... params) throws SQLExcept
375
401
return holder .isQueryResult ();
376
402
}
377
403
378
- /**
379
- * Returns {@link ResultSet} which will be initialized by <code>data</code>.
380
- *
381
- * @param data predefined result to be wrapped by {@link ResultSet}
382
- *
383
- * @return wrapped result
384
- *
385
- * @throws SQLException if a database access error occurs or
386
- * this method is called on a closed <code>Statement</code>
387
- */
404
+ @ Override
388
405
public ResultSet executeMetadata (SQLResultHolder data ) throws SQLException {
389
406
checkNotClosed ();
390
407
return createResultSet (data );
0 commit comments