From aff5dca66e32101af34f06844645c420272b92b1 Mon Sep 17 00:00:00 2001 From: Simon Jacob Date: Mon, 17 Dec 2012 09:20:28 +1100 Subject: [PATCH] Added support for getRecords method Signed-off-by: Jakub Skoczen --- src/main/java/org/yaz4j/ResultSet.java | 26 ++++++++++++++++++++++++++ src/main/swig/libyaz4j.i | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/org/yaz4j/ResultSet.java b/src/main/java/org/yaz4j/ResultSet.java index aef52f6..a60f9a5 100644 --- a/src/main/java/org/yaz4j/ResultSet.java +++ b/src/main/java/org/yaz4j/ResultSet.java @@ -1,9 +1,12 @@ package org.yaz4j; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; import org.yaz4j.exception.ZoomException; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; +import org.yaz4j.jni.SWIGTYPE_p_p_ZOOM_record_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p; import org.yaz4j.jni.yaz4jlib; @@ -78,6 +81,29 @@ public class ResultSet implements Iterable { } return new Record(record, this); } + + public List getRecords(long start, int count) throws ZoomException { + List out = new ArrayList(count); + + SWIGTYPE_p_p_ZOOM_record_p recs = yaz4jlib.new_zoomRecordArray(count); + yaz4jlib.ZOOM_resultset_records(resultSet, recs, start, count); + + for (int i = 0; i < count; i++) { + SWIGTYPE_p_ZOOM_record_p record = yaz4jlib.zoomRecordArray_getitem(recs, i); + if (record == null) { + continue; + } + + int errorCode = yaz4jlib.ZOOM_record_error(record, null, null, null); + if (errorCode != 0) { + throw new ZoomException("Record excpetion, code " + errorCode); + } + + out.add(new Record(record, this)); + } + + return out; + } @Override public Iterator iterator() { diff --git a/src/main/swig/libyaz4j.i b/src/main/swig/libyaz4j.i index 3e686e2..97a74cb 100644 --- a/src/main/swig/libyaz4j.i +++ b/src/main/swig/libyaz4j.i @@ -9,6 +9,8 @@ %include "cpointer.i" %pointer_functions(int, intp); %pointer_functions(size_t, size_tp); + %include "carrays.i" + %array_functions(ZOOM_record, zoomRecordArray); %typemap(jni) CharStarByteArray "jbyteArray" %typemap(jtype) CharStarByteArray "byte[]" %typemap(jstype) CharStarByteArray "byte[]" -- 1.7.10.4