74903c92e82a701160fd746bd00a270d3f3c6d8b
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / ResultSet.java
1 package org.yaz4j;
2
3 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_connection_p;
4 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p;
5 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p;
6 import org.yaz4j.jni.yaz4jlib;
7
8 public class ResultSet {
9
10     private SWIGTYPE_p_ZOOM_resultset_p resultSet;
11     private SWIGTYPE_p_ZOOM_connection_p connection;
12     private long size = 0;
13     private boolean disposed = false;
14
15     ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) {
16         this.resultSet = resultSet;
17         this.connection = connection;
18         size = yaz4jlib.ZOOM_resultset_size(this.resultSet);
19     }
20
21     @Override
22     public void finalize() {
23         this._dispose();
24     }
25
26     ResultSetOptionsCollection getResultSetOptions() {
27         return new ResultSetOptionsCollection(resultSet);
28     }
29
30     public Record getRecord(int index) {
31       SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index);
32       return new Record(recordTemp, this);
33     }
34
35     public long getSize() {
36         return size;
37     }
38
39     void _dispose() {
40         if (!disposed) {
41             yaz4jlib.ZOOM_resultset_destroy(resultSet);
42             connection = null;
43             resultSet = null;
44             disposed = true;
45         }
46     }
47 }