+
+ /**
+ * Retrieve a collection of records at once. If a record cannot be retrieved,
+ * it is omitted from the list (thus the list size may be smaller than 'count').
+ * @param start start index within the result set
+ * @param count number of records to retrieve
+ * @return
+ * @throws ZoomException raised in case of protocol errors
+ */
+ public List<Record> getRecords(long start, int count) throws ZoomException {
+ List<Record> out = new ArrayList<Record>(count);
+ SWIGTYPE_p_p_ZOOM_record_p recs = yaz4jlib.new_zoomRecordArray(count);
+ yaz4jlib.ZOOM_resultset_records(resultSet, recs, start, count);
+ ZoomException err = this.conn.getZoomException();
+ if (err != null) {
+ throw err;
+ }
+ 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 exception, code " + errorCode);
+ }
+ out.add(new Record(record, this));
+ }
+ return out;
+ }
+
+ @Override
+ public Iterator<Record> iterator() {
+ return new Iterator<Record>() {
+ private long cur;
+ @Override
+ public boolean hasNext() {
+ return cur < size;
+ }
+
+ @Override
+ public Record next() {
+ try {
+ return getRecord(cur++);
+ } catch (ZoomException ze) {
+ throw new NoSuchElementException(ze.getMessage());
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("remove operation not supported");
+ }
+ };
+ }
+
+ /**
+ *
+ * @param type
+ * @param spec
+ * @return
+ * @throws ZoomException
+ */
+ public ResultSet sort(String type, String spec) throws ZoomException {
+ if (type == null)
+ throw new NullPointerException("sort type cannot be null");
+ if (spec == null)
+ throw new NullPointerException("sort spec cannot be null");
+ int ret = yaz4jlib.ZOOM_resultset_sort1(resultSet, type, spec);
+ if (ret != 0) throw new ZoomException("Sorting resultset failed");
+ return this;
+ }