【发布时间】:2021-11-11 14:05:49
【问题描述】:
我正在扩展我的last question I asked about jOOQ。在 Hibernate 模型中,使用了 @Filter 注释,我想将这个相同的“默认过滤器”应用于 jOOQ 查询。当我将 jOOQ 查询传递给 nativeQuery(org.jooq.Query query, Class<E> type) 时,我想知道是否可以从 jOOQ 查询 (org.jooq.Query) 中的 FROM 子句中提取使用的表 (TableImpl<?,?>)。
这是我尝试过的:
private static <E> SelectConditionStep<Record> applyDefaultFilters(Class<E> type, SelectConditionStep<Record> query)
{
if (BaseOrganizationModel.class.isAssignableFrom(type)) {
query
.getQuery()
.addConditions(
query
.getQuery()
.asTable()
.field("organization_id", Long.class)
.eq(currentOrganization().id));
if (SoftDeletableModel.class.isAssignableFrom(type)) {
query
.getQuery()
.addConditions(query.getQuery().asTable().field("deleted", Boolean.class).eq(false));
}
}
return query;
}
结果就是这个 SQL,这不是我想要的。我想让它过滤对应的表。
select distinct `EventGroup`.*
from `EventGroup`
where (
...
and `alias_100341773`.`organization_id` = ?
and `alias_17045196`.`deleted` = ?
)
我想要这个
select distinct `EventGroup`.*
from `EventGroup`
where (
...
and `EventGroup`.`organization_id` = ?
and `EventGroup`.`deleted` = ?
)
这可能吗?如果没有,还有哪些可能的其他路线? (除了明显的将表格传递给函数)
【问题讨论】: