org.sql2o.PojoResultSetIterator Maven / Gradle / Ivy
package org.sql2o;
import org.sql2o.quirks.Quirks;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Iterator for a {@link ResultSet}. Tricky part here is getting {@link #hasNext()}
* to work properly, meaning it can be called multiple times without calling {@link #next()}.
*
* @author [email protected]
*/
public class PojoResultSetIterator extends ResultSetIteratorBase {
private ResultSetHandler handler;
public PojoResultSetIterator(ResultSet rs, boolean isCaseSensitive, Quirks quirks, ResultSetHandlerFactory factory) {
super(rs, isCaseSensitive, quirks);
try {
this.handler = factory.newResultSetHandler(rs.getMetaData());
} catch (SQLException e) {
throw new Sql2oException("Database error: " + e.getMessage(), e);
}
}
public PojoResultSetIterator(ResultSet rs, boolean isCaseSensitive, Quirks quirks, ResultSetHandler handler) {
super(rs, isCaseSensitive, quirks);
this.handler = handler;
}
@Override
protected T readNext() throws SQLException {
return handler.handle(rs);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy