简体   繁体   English

使用条件过滤 JOOQ 生成的表,同时保持类型

[英]Filter a JOOQ generated table with a condition while maintaining type

I have generated a number of JOOQ classes from my database.我从我的数据库中生成了许多 JOOQ 类。 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我得到了一个Table<JBooksRecord>而我看不到将我的新 Table 转换为JBooks

This is being worked on through:正在通过以下方式解决此问题:

  • #8012 "Override Table.where(Condition) methods in generated tables" #8012 “在生成的表中覆盖 Table.where(Condition) 方法”
  • #1969 "Add support for views expressed in jOOQ" #1969 “添加对 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.在生成的 SQL 中,这可以生成派生表或内联到调用 SQL 语句中。

As of jOOQ 3.11, these features are not yet available.从 jOOQ 3.11 开始,这些功能尚不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM