Reformat (NetBeans).
[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 Record[] records = null;
14     private boolean disposed = false;
15
16     ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) {
17         this.resultSet = resultSet;
18         this.connection = connection;
19         size = yaz4jlib.ZOOM_resultset_size(this.resultSet);
20         records = new Record[(int) size];
21     }
22
23     public void finalize() {
24         this.Dispose();
25     }
26
27     ResultSetOptionsCollection getResultSetOptions() {
28         return new ResultSetOptionsCollection(resultSet);
29     }
30
31     public Record getRecord(int index) {
32         if (records[index] == null) {
33             SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index);
34             records[index] = new Record(recordTemp, this);
35         }
36
37         return this.records[index];
38     }
39
40     public int getSize() {
41         return (int) size;
42     }
43
44     public void Dispose() {
45         if (!disposed) {
46             for (int i = 0; i < records.length; i++) {
47                 if (records[i] != null) {
48                     records[i].Dispose();
49                 }
50             }
51
52             yaz4jlib.ZOOM_resultset_destroy(resultSet);
53             connection = null;
54             resultSet = null;
55             disposed = true;
56         }
57     }
58 }