Class ResultSetIterator

  • All Implemented Interfaces:
    Iterator<Object[]>

    public class ResultSetIterator
    extends Object
    implements Iterator<Object[]>

    Wraps a ResultSet in an Iterator&lt;Object[]&gt;. This is useful when you want to present a non-database application layer with domain neutral data.

    This implementation requires the ResultSet.isLast() method to be implemented.

    • Constructor Detail

      • ResultSetIterator

        public ResultSetIterator​(ResultSet resultSet)
        Constructor for ResultSetIterator.
        Parameters:
        resultSet - Wrap this ResultSet in an Iterator.
      • ResultSetIterator

        public ResultSetIterator​(ResultSet resultSet,
                                 RowProcessor convert)
        Constructor for ResultSetIterator.
        Parameters:
        resultSet - Wrap this ResultSet in an Iterator.
        convert - The processor to use when converting a row into an Object[]. Defaults to a BasicRowProcessor.
    • Method Detail

      • iterable

        public static Iterable<Object[]> iterable​(ResultSet resultSet)
        Generates an Iterable, suitable for use in for-each loops.
        Parameters:
        resultSet - Wrap this ResultSet in an Iterator.
        Returns:
        an Iterable, suitable for use in for-each loops.
      • hasNext

        public boolean hasNext()
        Returns true if there are more rows in the ResultSet.
        Specified by:
        hasNext in interface Iterator<Object[]>
        Returns:
        boolean true if there are more rows
        Throws:
        RuntimeException - if an SQLException occurs.
      • rethrow

        protected void rethrow​(SQLException e)
        Rethrow the SQLException as a RuntimeException. This implementation creates a new RuntimeException with the SQLException's error message.
        Parameters:
        e - SQLException to rethrow
        Since:
        1.1