Use Maven for building yaz4j.
[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         {
18                 this.resultSet = resultSet ;
19                 this.connection = connection ;
20                 size = yaz4jlib.ZOOM_resultset_size(this.resultSet);
21                 records = new Record[(int)size];
22         }
23         
24         public void finalize()
25         {
26                 this.Dispose();         
27         }       
28
29     ResultSetOptionsCollection getResultSetOptions()
30     {
31         return new ResultSetOptionsCollection(resultSet);
32     }
33         
34         public Record getRecord(int index)
35         {
36                 if ( records[index] == null)
37                 {
38                         SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index);
39                         records[index] = new Record(recordTemp, this);
40                 }
41         
42                 return this.records[index];
43         }
44         
45         public int getSize()
46         {
47                 return (int)size ;
48         }
49         
50         public void Dispose()
51         {
52                 if (! disposed )
53                 {
54                         for( int i=0 ; i<records.length ; i++)
55                         {
56                                 if (records[i] != null)
57                                         records[i].Dispose();
58                         }
59
60                         yaz4jlib.ZOOM_resultset_destroy(resultSet);
61                         connection = null;
62                         resultSet = null;
63                         disposed = true;
64                 }
65         }
66 }