All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sql2o.PojoResultSetIterator Maven / Gradle / Ivy

There is a newer version: 0.2.6
Show newest version
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