This version of the manual is outdated. For the latest version, follow this link: http://www.jooq.org/doc/3.0/manual.
| The jOOQ User Manual. Multiple Pages : jOOQ classes and their usage : ResultQuery and fetch() methods | previous : next |
# The ResultQuery and its convenience methods
Data fetching is one of the great hassles in JDBC and JPA. With jOOQ, you will be able to specify exactly, what kind of data you want to fetch from any given query, as well as how you want to fetch that data. This doesn't just mean distinguishing between fetching one record at a time, or the whole resultset, between fetching one column at a time, or the whole resultset. This also means transforming your result (a list) into a map, into arrays, into custom types, into JPA-annotated types, into a call-back, or simply fetching it asynchronously
These methods allow for fetching a jOOQ Result or parts of it.
// Fetch the whole result
Result<R> fetch();
// Fetch a single field from the result
<T> List<T> fetch(Field<T> field);
List<?> fetch(int fieldIndex);
<T> List<T> fetch(int fieldIndex, Class<? extends T> type);
List<?> fetch(String fieldName);
<T> List<T> fetch(String fieldName, Class<? extends T> type);
// Fetch the first Record
R fetchAny();
// Fetch exactly one Record
R fetchOne();
// Fetch a single field of exactly one Record
<T> T fetchOne(Field<T> field);
Object fetchOne(int fieldIndex);
<T> T fetchOne(int fieldIndex, Class<? extends T> type);
Object fetchOne(String fieldName);
<T> T fetchOne(String fieldName, Class<? extends T> type);
These methods transform the result into another form, if org.jooq.Result is not optimal
// Fetch the resulting records as Maps
List<Map<String, Object>> fetchMaps();
Map<String, Object> fetchOneMap();
// Fetch the result as a Map
<K> Map<K, R> fetchMap(Field<K> key);
<K, V> Map<K, V> fetchMap(Field<K> key, Field<V> value);
// Fetch the resulting records as arrays
Object[][] fetchArrays();
Object[] fetchOneArray();
// Fetch a single field as an array
<T> T[] fetchArray(Field<T> field);
Object[] fetchArray(int fieldIndex);
<T> T[] fetchArray(int fieldIndex, Class<? extends T> type);
Object[] fetchArray(String fieldName);
<T> T[] fetchArray(String fieldName, Class<? extends T> type);
These methods transform the result into a user-defined form, if org.jooq.Result is not optimal
// Fetch the resulting records into a custom POJO // type, which may or may not be JPA-annotated // Use the generator's <pojos>true</pojos> and <jpaAnnotation>true</jpaAnnotation> // configurations to generate such POJOs with jOOQ <E> List<E> fetchInto(Class<? extends E> type); // Fetch the resulting records into a custom // record handler, similar to how Spring JdbcTemplate's // RowMapper or the Ollin Framework works. <H extends RecordHandler<R>> H fetchInto(H handler); // These change the behaviour of fetching itself, // especially, when not all data should be // fetched at once // ---------------------------------------------- // Fetch a Cursor for lazy iteration Cursor<R> fetchLazy(); // Or a JDBC ResultSet, if you prefer that ResultSet fetchResultSet(); // Fetch data asynchronously and let client code // decide, when the data must be available. // This makes use of the java.util.concurrent API, // Similar to how Avajé Ebean works. FutureResult<R> fetchLater(); FutureResult<R> fetchLater(ExecutorService executor);
| The jOOQ User Manual. Multiple Pages : jOOQ classes and their usage : ResultQuery and fetch() methods | previous : next |
