From fe149dad412bec8dc0c39334192a3283dd195c68 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 26 Oct 2012 11:36:49 +0200 Subject: [PATCH] [#1756] Add RecordMapper, similar to RecordHandler, mapping records to custom types - Updated manual --- .../src/main/resources/manual-2.6.xml | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/jOOQ-website/src/main/resources/manual-2.6.xml b/jOOQ-website/src/main/resources/manual-2.6.xml index 38884de142..a2f6d2a6d3 100644 --- a/jOOQ-website/src/main/resources/manual-2.6.xml +++ b/jOOQ-website/src/main/resources/manual-2.6.xml @@ -5288,7 +5288,8 @@ Result resultQuery.fetch();]]>
  • : Sometimes you care about the returned type of your records, sometimes (with arbitrary projections) you don't.
  • : Instead of letting you transform your result sets into any more suitable data type, a library should do that work for you.
  • -
  • : This is an entirely different fetching paradigm. With Java 8's lambda expressions, this will become even more powerful.
  • +
  • : This is an entirely different fetching paradigm. With Java 8's lambda expressions, this will become even more powerful.
  • +
  • : This is an entirely different fetching paradigm. With Java 8's lambda expressions, this will become even more powerful.
  • : This is what made Hibernate and JPA so strong. Automatic mapping of tables to custom POJOs.
  • : It should be easy to distinguish these two fetch modes.
  • : Some databases allow for returning many result sets from a single query. JDBC can handle this but it's very verbose. A list of results should be returned instead.
  • @@ -5328,6 +5329,9 @@ List> fetchMany(); // Fetch records into a custom callback > H fetchInto(H handler); +// Map records using a custom callback + List fetch(RecordMapper mapper); + // Execute a ResultQuery with jOOQ, but return a JDBC ResultSet, not a jOOQ object ResultSet fetchResultSet();]]> @@ -5500,6 +5504,46 @@ create.selectFrom(BOOK) .orderBy(BOOK.ID) .fetchInto(book -> { Util.doThingsWithBook(book); }; ); ]]> + +

    + See also the manual's section about the , which provides similar features +

    + + + +
    + RecordMapper + +

    + In a more functional operating mode, you might want to write callbacks that map records from your select statement results in order to do some processing. This is a common data access pattern in Spring's JdbcTemplate, and it is also available in jOOQ. With jOOQ, you can implement your own classes and plug them into jOOQ's : +

    + + ids = +create.selectFrom(BOOK) + .orderBy(BOOK.ID) + .fetch() + .map(new RecordMapper() { + @Override + public Integer map(BookRecord book) { + return book.getId(); + } + }); + +// Or more concisely +create.selectFrom(BOOK) + .orderBy(BOOK.ID) + .fetch(new RecordMapper() {...}); + +// Or even more concisely with Java 8's lambda expressions: +create.selectFrom(BOOK) + .orderBy(BOOK.ID) + .fetch(book -> book.getId()); +]]> + +

    + See also the manual's section about the , which provides similar features +

    @@ -5723,6 +5767,7 @@ finally {
    • : Cursors are also typed with the <R> type, allowing to fetch custom, generated or plain types.
    • : You can use your own callbacks to receive lazily fetched records.
    • +
    • : You can use your own callbacks to map lazily fetched records.
    • : You can fetch data into your own custom POJO types.
    @@ -8944,7 +8989,7 @@ SERVER = new RemoteDebuggerServer(DEBUGGER_PORT);
  • JPA: The de-facto standard in the javax.persistence packages, supplied by Oracle. Its annotations are useful to jOOQ as well.
  • OneWebSQL: A commercial SQL abstraction API with support for DAO source code generation, which was integrated also in jOOQ
  • QueryDSL: A "LINQ-port" to Java. It has a similar fluent API, a similar code-generation facility, yet quite a different purpose. While jOOQ is all about SQL, QueryDSL (like LINQ) is mostly about querying.
  • -
  • Spring Data: Spring's JdbcTemplate knows RowMappers, which are reflected by jOOQ's
  • +
  • Spring Data: Spring's JdbcTemplate knows RowMappers, which are reflected by jOOQ's or