/*
 * $Log: ResultSetIterator.java,v $
 * Revision 1.3  2008-02-26 08:36:05  europe\L190409
 * updated javadoc
 *
 * Revision 1.2  2007/07/26 16:14:08  Gerrit van Brakel <gerrit.van.brakel@ibissource.org>
 * use JdbcUtil.fullClose()
 *
 * Revision 1.1  2007/07/17 11:16:50  Gerrit van Brakel <gerrit.van.brakel@ibissource.org>
 * added iterating classes
 *
 */
package nl.nn.adapterframework.jdbc;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import nl.nn.adapterframework.core.IDataIterator;
import nl.nn.adapterframework.core.SenderException;
import nl.nn.adapterframework.util.DB2XMLWriter;
import nl.nn.adapterframework.util.JdbcUtil;
import nl.nn.adapterframework.util.LogUtil;
import nl.nn.adapterframework.util.Misc;

import org.apache.log4j.Logger;

/**
 * Iterator over ResultSet.
 * 
 * Each row is returned in the same way a row is usually returned from a query.
 * 
 * @author  Gerrit van Brakel
 * @since   4.7
 * @version Id
 */
class ResultSetIterator implements IDataIterator {
	protected Logger log = LogUtil.getLogger(this);

	private ResultSet rs;
		
	private ResultSetMetaData rsmeta;
	private boolean lineChecked=false;
	private boolean lineAvailable=false;

	int rowNumber=0;

	public ResultSetIterator(ResultSet rs) throws SQLException {
		super();
		this.rs=rs;
		rsmeta=rs.getMetaData();
	}

	public boolean hasNext() throws SenderException {
		try {
			if (!lineChecked) {
				lineAvailable=rs.next();
				lineChecked=true;
			}
			return lineAvailable;
		} catch (Exception e) {
			throw new SenderException(e);
		}
	}

	public Object next() throws SenderException {
		try {
			lineChecked=false;
			return DB2XMLWriter.getRowXml(rs, rowNumber++, rsmeta, Misc.DEFAULT_INPUT_STREAM_ENCODING, false, "", true).toXML();
		} catch (Exception e) {
			throw new SenderException(e);
		}
	}

	public void close() {
		JdbcUtil.fullClose(rs);
	}
}

@@ -50,17 +50,17 @@
 n 1.
-3
+4
   2008-0
 2-26
@@ -59,21 +59,21 @@
 08-0
-2-26 08
+5-15 14
 :36:
-05
+12
   eu
@@ -85,16 +85,170 @@
 L190409%0A
+ * change startup behaviour, first line is now returned too%0A *%0A * Revision 1.3  2008/02/26 08:36:05  Gerrit van Brakel %3Cgerrit.van.brakel@ibissource.org%3E%0A
  * updat
@@ -1330,22 +1330,83 @@
 Checked=
-false;
+true; // assumes at least one line is present, and cursor is on it!
 %0A%09privat
@@ -1429,20 +1429,19 @@
 ailable=
-fals
+tru
 e;%0A%0A%09int

change startup behaviour, first line is now returned too