Refactor.
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / ResultSet.java
index 300cbad..74275a1 100644 (file)
@@ -10,49 +10,54 @@ public class ResultSet {
     private SWIGTYPE_p_ZOOM_resultset_p resultSet;
     private SWIGTYPE_p_ZOOM_connection_p connection;
     private long size = 0;
-    private Record[] records = null;
     private boolean disposed = false;
 
     ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, SWIGTYPE_p_ZOOM_connection_p connection) {
         this.resultSet = resultSet;
         this.connection = connection;
         size = yaz4jlib.ZOOM_resultset_size(this.resultSet);
-        records = new Record[(int) size];
     }
 
+    @Override
     public void finalize() {
-        this.Dispose();
+        this._dispose();
     }
 
-    ResultSetOptionsCollection getResultSetOptions() {
-        return new ResultSetOptionsCollection(resultSet);
+    /**
+     * Read option by name.
+     * @param name option name
+     * @return option value
+     */
+    public String option(String name) {
+      return yaz4jlib.ZOOM_resultset_option_get(resultSet, name);
     }
 
-    public Record getRecord(int index) {
-        if (records[index] == null) {
-            SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index);
-            records[index] = new Record(recordTemp, this);
-        }
+    /**
+     * Write option with a given name.
+     * @param name option name
+     * @param value option value
+     * @return result set (self) for chainability
+     */
+    public ResultSet option(String name, String value) {
+      yaz4jlib.ZOOM_resultset_option_set(resultSet, name, value);
+      return this;
+    }
 
-        return this.records[index];
+    public Record getRecord(int index) {
+      SWIGTYPE_p_ZOOM_record_p recordTemp = yaz4jlib.ZOOM_resultset_record(resultSet, index);
+      return new Record(recordTemp, this);
     }
 
-    public int getSize() {
-        return (int) size;
+    public long getSize() {
+        return size;
     }
 
-    public void Dispose() {
+    void _dispose() {
         if (!disposed) {
-            for (int i = 0; i < records.length; i++) {
-                if (records[i] != null) {
-                    records[i].Dispose();
-                }
-            }
-
             yaz4jlib.ZOOM_resultset_destroy(resultSet);
             connection = null;
             resultSet = null;
             disposed = true;
         }
     }
-}
+}
\ No newline at end of file