From 33d1aad77498f4da7efd5623a10ca4a423dd5885 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Tue, 23 Feb 2010 15:49:11 +0100 Subject: [PATCH] Properly dealocate records, implement Cloneable. --- src/main/java/org/yaz4j/Record.java | 22 ++++++++++++++++++---- src/main/java/org/yaz4j/ResultSet.java | 7 ++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index 977ee05..3770132 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -4,11 +4,17 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; import org.yaz4j.jni.SWIGTYPE_p_int; import org.yaz4j.jni.yaz4jlib; -public class Record { - private SWIGTYPE_p_ZOOM_record_p record = null; +public class Record implements Cloneable { + private SWIGTYPE_p_ZOOM_record_p record; + private ResultSet rset; private boolean disposed = false; - Record(SWIGTYPE_p_ZOOM_record_p record) { + Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet rset) { + this.record = record; + this.rset = rset; + } + + protected Record(SWIGTYPE_p_ZOOM_record_p record) { this.record = record; } @@ -37,9 +43,17 @@ public class Record { return new String(get("database")); } + public Object clone() { + SWIGTYPE_p_ZOOM_record_p clone = yaz4jlib.ZOOM_record_clone(record); + return new Record(clone); + } + void _dispose() { if (!disposed) { - yaz4jlib.ZOOM_record_destroy(record); + //was cloned, need to dealloc? + if (rset == null) + yaz4jlib.ZOOM_record_destroy(record); + rset = null; record = null; disposed = true; } diff --git a/src/main/java/org/yaz4j/ResultSet.java b/src/main/java/org/yaz4j/ResultSet.java index 01e2478..3d89bd7 100644 --- a/src/main/java/org/yaz4j/ResultSet.java +++ b/src/main/java/org/yaz4j/ResultSet.java @@ -43,8 +43,9 @@ public class ResultSet { } public Record getRecord(int index) { - SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index); - return new Record(recordTemp); + SWIGTYPE_p_ZOOM_record_p record = + yaz4jlib.ZOOM_resultset_record(resultSet, index); + return new Record(record, this); } public long getSize() { @@ -59,4 +60,4 @@ public class ResultSet { disposed = true; } } -} \ No newline at end of file +} -- 1.7.10.4