Filter a JOOQ generated table with a condition while maintaining type

hwaring :

I have generated a number of JOOQ classes from my database. I want to easily filter my tables by customer while maintaining the strong type of my tables.

This is what I want to be able to do:

// Generated class books
JBooks books = JBooks.BOOKS;

// get ownershipCheck (this could be more complicated, possibly joining multiple tables)
Condition ownershipCheck = books.customer().ID.eq(currentCustomer);

// desired output that I can do further operations on
JBooks filteredBooks = selectFrom(books).where(ownershipCheck).asTable();


// a bunch of random operations using the functionality from JBooks
db.select(filteredBooks.AUTHOR, filteredBooks.PUBLISH_DATE, ...etc)

Unfortunately, I can't do this. I get a Table<JBooksRecord> instead and I see no way to cast my new Table to JBooks

Lukas Eder :

This is being worked on through:

  • #8012 "Override Table.where(Condition) methods in generated tables"
  • #1969 "Add support for views expressed in jOOQ"

In short, a table can accept a predicate and the result is a modified table of the same table type, exposing the same type safe column expressions. In generated SQL, this can either produce a derived table or be inlined into the calling SQL statement.

As of jOOQ 3.11, these features are not yet available.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=159294&siteId=1