Skip to content

Commit 2cda891

Browse files
committed
#953 Refine and reduce finalization
1 parent 2165b27 commit 2cda891

7 files changed

Lines changed: 33 additions & 49 deletions

File tree

src/jna-client/org/firebirdsql/gds/ng/jna/JnaDatabase.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,11 @@ public void processStatusVector(ISC_STATUS[] statusVector, WarningMessageCallbac
500500

501501
@Override
502502
protected void finalize() throws Throwable {
503-
try {
504-
if (isAttached()) {
505-
safelyDetach();
506-
}
503+
try (LockCloseable ignored = withLock()) {
504+
if (handle.getValue() == 0 || !isAttached()) return;
505+
clientLibrary.fb_cancel_operation(
506+
new ISC_STATUS[JnaDatabase.STATUS_VECTOR_SIZE], handle, (short) fb_cancel_abort);
507+
// Intentionally not processing status vector
507508
} finally {
508509
super.finalize();
509510
}

src/jna-client/org/firebirdsql/gds/ng/jna/JnaStatement.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,18 @@ public final RowDescriptor emptyRowDescriptor() {
482482
private void processStatusVector() throws SQLException {
483483
getDatabase().processStatusVector(statusVector, getStatementWarningCallback());
484484
}
485+
486+
@Override
487+
protected void finalize() throws Throwable {
488+
if (getState() == StatementState.CLOSED) return;
489+
try (LockCloseable ignored = withLock()) {
490+
if (handle.getValue() == 0 || !database.isAttached()) return;
491+
clientLibrary.isc_dsql_free_statement(
492+
new ISC_STATUS[JnaDatabase.STATUS_VECTOR_SIZE], handle, (short) ISCConstants.DSQL_drop);
493+
// We're intentionally not processing the status vector
494+
} finally {
495+
super.finalize();
496+
}
497+
}
498+
485499
}

src/main/org/firebirdsql/gds/ng/AbstractFbStatement.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,15 +690,6 @@ protected final void checkStatementValid(StatementState ignoreState) throws SQLE
690690
checkStatementValid();
691691
}
692692

693-
@Override
694-
protected void finalize() throws Throwable {
695-
try {
696-
if (getState() != StatementState.CLOSED) close();
697-
} finally {
698-
super.finalize();
699-
}
700-
}
701-
702693
@Override
703694
public FbTransaction getTransaction() {
704695
return transaction;

src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireDatabase.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,4 @@ public byte[] getInfo(int operation, int handle, byte[] requestItems, int maxBuf
361361
*/
362362
public abstract FbWireAsynchronousChannel initAsynchronousChannel() throws SQLException;
363363

364-
@Override
365-
protected void finalize() throws Throwable {
366-
try {
367-
if (!connection.isConnected()) return;
368-
if (isAttached()) {
369-
safelyDetach();
370-
} else {
371-
closeConnection();
372-
}
373-
} finally {
374-
super.finalize();
375-
}
376-
}
377364
}

src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireService.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,4 @@ protected final void closeConnection() throws IOException {
190190
}
191191
}
192192

193-
@Override
194-
protected void finalize() throws Throwable {
195-
try {
196-
if (!connection.isConnected()) return;
197-
if (isAttached()) {
198-
safelyDetach();
199-
} else {
200-
closeConnection();
201-
}
202-
} finally {
203-
super.finalize();
204-
}
205-
}
206-
207193
}

src/main/org/firebirdsql/gds/ng/wire/AbstractFbWireStatement.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.firebirdsql.gds.ng.wire;
2020

21+
import org.firebirdsql.gds.ISCConstants;
2122
import org.firebirdsql.gds.impl.wire.WireProtocolConstants;
2223
import org.firebirdsql.gds.impl.wire.XdrInputStream;
2324
import org.firebirdsql.gds.impl.wire.XdrOutputStream;
@@ -242,4 +243,17 @@ private void deferredExceptionHandler(Exception exception) {
242243
forceState(StatementState.ERROR);
243244
}
244245
}
246+
247+
@Override
248+
protected void finalize() throws Throwable {
249+
if (getState() == StatementState.CLOSED) return;
250+
try (LockCloseable ignored = withLock()) {
251+
StatementState state = getState();
252+
if (state == StatementState.NEW || state == StatementState.CLOSED || !database.isAttached()) return;
253+
free(ISCConstants.DSQL_drop);
254+
} finally {
255+
super.finalize();
256+
}
257+
}
258+
245259
}

src/main/org/firebirdsql/gds/ng/wire/version10/V10AsynchronousChannel.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,6 @@ private boolean processSingleEvent() {
305305
}
306306
}
307307

308-
@Override
309-
protected void finalize() throws Throwable {
310-
try {
311-
close();
312-
} finally {
313-
super.finalize();
314-
}
315-
}
316-
317308
private class ChannelDatabaseListener implements DatabaseListener {
318309

319310
@Override

0 commit comments

Comments
 (0)