T
- type of the tuple inducing the SQL statement execution / resultsR
- type of tuple of a result stream consumer@FunctionalInterface
public interface ResultsHandler<T,R>
Sample use:
For a ResultSet created by executing the SQL statement:
"SELECT id, firstname, lastname FROM persons WHERE id = ?"
// create a Person tuple from db person info and add it to a stream
ResultsHandler<PersonId,Person> rh =
(tuple,rs,exc,consumer) -> {
if (exc != null)
return;
rs.next();
int id = rs.getInt("id");
String firstName = rs.getString("firstname");
String lastName = rs.getString("lastname");
consumer.accept(new Person(id, firstName, lastName));
}
};
}
Modifier and Type | Method and Description |
---|---|
void |
handleResults(T tuple,
java.sql.ResultSet resultSet,
java.lang.Exception exc,
Consumer<R> consumer)
Process the
ResultSet and add 0 or more tuples to consumer . |
void handleResults(T tuple, java.sql.ResultSet resultSet, java.lang.Exception exc, Consumer<R> consumer) throws java.sql.SQLException
ResultSet
and add 0 or more tuples to consumer
.tuple
- the tuple that induced the resultSetresultSet
- the SQL statement's result set. null if exc
is non-null or if the statement doesn't generate a ResultSet
.exc
- non-null if there was an exception executing the statement.
Typically a SQLException.consumer
- a Consumer to a result stream.java.sql.SQLException
- if there are problems handling the resultCopyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641