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

play.db.helper.JdbcWindowIterator Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.db.helper;

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

public class JdbcWindowIterator extends JdbcIterator {

    private int pageSize;

    public JdbcWindowIterator(ResultSet result, int pageOffset, int pageSize, JdbcResultFactory factory) throws SQLException {
        super(result, factory);
        this.pageSize = pageSize;
        seek(pageOffset);
    }

    public JdbcWindowIterator(ResultSet result, int pageOffset, int pageSize, Class adapterClass) throws SQLException {
        super(result, adapterClass);
        this.pageSize = pageSize;
        seek(pageOffset);
    }

    private void seek(int pageOffset) throws SQLException {
        if (result != null) {
            if (pageOffset < 0) {
                pageSize += pageOffset;
                pageOffset = 0;
            }
            if (pageSize > 0) {
                if (pageOffset == 0) result.beforeFirst();
                else result.absolute(pageOffset);
            } else close();
        }
    }

    @Override
    protected void load() {
        if (pageSize-- > 0) super.load();
        else close();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy