From c2b35d04750f2eace124d9c5fc86e68dc7079613 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Tue, 23 Feb 2010 13:24:57 +0100 Subject: [PATCH] Cleanup rercounts --- src/main/java/org/yaz4j/Connection.java | 2 +- src/main/java/org/yaz4j/Record.java | 6 +----- src/main/java/org/yaz4j/ResultSet.java | 13 ++++++------- src/main/java/org/yaz4j/ScanSet.java | 13 ++++++------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/yaz4j/Connection.java b/src/main/java/org/yaz4j/Connection.java index 1bd52fc..57b7a9f 100644 --- a/src/main/java/org/yaz4j/Connection.java +++ b/src/main/java/org/yaz4j/Connection.java @@ -74,7 +74,7 @@ public class Connection { } checkErrorCodeAndThrow(errorCode); - resultSet = new ResultSet(yazResultSet, zoomConnection); + resultSet = new ResultSet(yazResultSet, this); } finally { yaz4jlib.ZOOM_query_destroy(yazQuery); // deallocate yazQuery also when exceptions yazQuery = null; diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index 50fa381..362c279 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -5,13 +5,10 @@ import org.yaz4j.jni.SWIGTYPE_p_int; import org.yaz4j.jni.yaz4jlib; public class Record { - private SWIGTYPE_p_ZOOM_record_p record = null; - private ResultSet resultSet = null; private boolean disposed = false; - Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet resultSet) { - this.resultSet = resultSet; + Record(SWIGTYPE_p_ZOOM_record_p record) { this.record = record; } @@ -42,7 +39,6 @@ public class Record { void _dispose() { if (!disposed) { - resultSet = null; record = null; disposed = true; } diff --git a/src/main/java/org/yaz4j/ResultSet.java b/src/main/java/org/yaz4j/ResultSet.java index 74275a1..01e2478 100644 --- a/src/main/java/org/yaz4j/ResultSet.java +++ b/src/main/java/org/yaz4j/ResultSet.java @@ -1,21 +1,20 @@ package org.yaz4j; -import org.yaz4j.jni.SWIGTYPE_p_ZOOM_connection_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p; import org.yaz4j.jni.yaz4jlib; public class ResultSet { - + //for GC refcount + private Connection conn; private SWIGTYPE_p_ZOOM_resultset_p resultSet; - private SWIGTYPE_p_ZOOM_connection_p connection; private long size = 0; private boolean disposed = false; - ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) { + ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, Connection conn) { this.resultSet = resultSet; - this.connection = connection; size = yaz4jlib.ZOOM_resultset_size(this.resultSet); + this.conn = conn; } @Override @@ -45,7 +44,7 @@ public class ResultSet { public Record getRecord(int index) { SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index); - return new Record(recordTemp, this); + return new Record(recordTemp); } public long getSize() { @@ -55,8 +54,8 @@ public class ResultSet { void _dispose() { if (!disposed) { yaz4jlib.ZOOM_resultset_destroy(resultSet); - connection = null; resultSet = null; + conn = null; disposed = true; } } diff --git a/src/main/java/org/yaz4j/ScanSet.java b/src/main/java/org/yaz4j/ScanSet.java index e34cebf..3eaea94 100644 --- a/src/main/java/org/yaz4j/ScanSet.java +++ b/src/main/java/org/yaz4j/ScanSet.java @@ -1,19 +1,18 @@ package org.yaz4j; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_scanset_p; -import org.yaz4j.jni.SWIGTYPE_p_int; import org.yaz4j.jni.SWIGTYPE_p_size_t; import org.yaz4j.jni.yaz4jlib; public class ScanSet { - - private SWIGTYPE_p_ZOOM_scanset_p scanSet = null; - private Connection connection; + //for GC ref-count + private Connection conn; + private SWIGTYPE_p_ZOOM_scanset_p scanSet; private boolean disposed = false; - ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection connection) { - this.connection = connection; + ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) { this.scanSet = scanSet; + this.conn = conn; } public void finalize() { @@ -37,8 +36,8 @@ public class ScanSet { void _dispose() { if (!disposed) { yaz4jlib.ZOOM_scanset_destroy(scanSet); - connection = null; scanSet = null; + conn = null; disposed = true; } } -- 1.7.10.4