Package rife.database

Interface RowProcessor

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface RowProcessor
This interface can be implemented to process one row in a database query result set. The fetch method of a DbQueryManager requires an instance of a RowProcessor and calls its processRow method each time it is called.

The RowProcessor instance can then work with the result set and extract all needed data. It is free to implement any logic to be able to return the retrieved data in an acceptable form to the user.

A class that implements DbRowProcessor can for example take a Template instance as the argument of its constructor and progressively fill in each resulting row in an HTML table. This, without having to maintain the query results in memory to be able to provide it to a separate method which is responsible for the handling of the output. Using a RowProcessor thus allows for perfect separation and abstraction of result processing without having to be burdened with possible large memory usage or large object allocation.

More extensive processing is possible by extending the DbRowProcessor class instead.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    processRow(ResultSet resultSet)
    This method has to contain all the logic that should be executed for each row of a result set.
  • Method Details

    • processRow

      void processRow(ResultSet resultSet) throws SQLException
      This method has to contain all the logic that should be executed for each row of a result set.
      Parameters:
      resultSet - the ResultSet instance that was provided to the DbQueryManager's fetch method.
      Throws:
      SQLException - when a database error occurs, it's thus not necessary to catch all the possible SQLExceptions inside this method. They'll be caught higher up and be transformed in DatabaseExceptions.
      Since:
      1.0
      See Also: