X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fyaz4j%2FRecord.java;h=2793ba9a104722d814e9acd61f9dc5d3f1cfd78a;hb=9f0427337a2dbc0ca7db55ae7b6812b6d4680344;hp=50fa38181d808c760666a40fbd64ec09ac0e987d;hpb=51cc88d374e72f4c93a4721c2094e028a6ffae85;p=yaz4j-moved-to-github.git diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index 50fa381..2793ba9 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -1,50 +1,65 @@ package org.yaz4j; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; -import org.yaz4j.jni.SWIGTYPE_p_int; import org.yaz4j.jni.yaz4jlib; -public class Record { +public class Record implements Cloneable { - private SWIGTYPE_p_ZOOM_record_p record = null; - private ResultSet resultSet = null; - private boolean disposed = false; + private SWIGTYPE_p_ZOOM_record_p record; + private ResultSet rset; + private boolean disposed = false; - Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet resultSet) { - this.resultSet = resultSet; - this.record = record; - } + Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet rset) { + this.record = record; + this.rset = rset; + } - public void finalize() { - _dispose(); - } + protected Record(SWIGTYPE_p_ZOOM_record_p record) { + this.record = record; + } - public byte[] get(String type) { - SWIGTYPE_p_int length = null; - return yaz4jlib.ZOOM_record_get_bytes(record, type, length); - } + @Override + public void finalize() { + _dispose(); + } - public String render() { - return new String(get("render")); - } + public byte[] get(String type) { + if (type == null) + throw new NullPointerException("type cannot be null"); + return yaz4jlib.ZOOM_record_get_bytes(record, type); + } - public byte[] getContent() { - return get("raw"); - } + public String render() { + return new String(get("render")); + } - public String getSyntax() { - return new String(get("syntax")); - } + public byte[] getContent() { + return get("raw"); + } - public String getDatabase() { - return new String(get("database")); - } + public String getSyntax() { + return new String(get("syntax")); + } + + public String getDatabase() { + return new String(get("database")); + } + + @Override + public Object clone() { + SWIGTYPE_p_ZOOM_record_p clone = yaz4jlib.ZOOM_record_clone(record); + return new Record(clone); + } - void _dispose() { - if (!disposed) { - resultSet = null; - record = null; - disposed = true; - } + void _dispose() { + if (!disposed) { + //was cloned, need to dealloc? + if (rset == null) { + yaz4jlib.ZOOM_record_destroy(record); + } + rset = null; + record = null; + disposed = true; } + } }