JOOQ FLUENT API中间结果是不可变的吗?
如果我从流利的API查询构建器中保存中间结果,以后会调用它吗? (换句话说,中间结果是不可变的吗?)例如,
final var a = create.select().from(AUTHOR);
final var before1920 = a.where(AUTHOR.YEAR_OF_BIRTH.gt(1920).fetch();
final var authorSql = a.where(AUTHOR.FIRST_NAME.eq("Paulo")).getSql();
我可以确信 a
未通过以后的语句修改吗?
如果不是这种情况,我的主要愿望是有时将查询中的SQL记录到审核日志或调试日志。我可以在调用 fetch*()
方法之前或之后安全地调用 getsql()
吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JOOQ DSL的可变性
为JOOQ 3.16,是的,这些特定的方法可暴露出可变的行为,因此您可以像这样动态构建查询。另请参见,暗示了这种可能在(远)未来的变化,而有利于更可预测的不可预测的DSL API。
但是,即使可以利用这一点,您也不应构建这样。使用推荐方法:
这对您的实际问题无济于事,但是它回答了您问的问题的一部分,即,您不应该依靠这种可变的行为。
具体问题
不,你不能。
A
已修改,请参见有关Mustability 的部分。您可以使用内置的执行日志记录,将所有查询记录到
debug
级别。是的,这些电话是安全的。这也是上述执行记录也是如此,以应用格式化,将绑定值插入登录目的,等等。
Mutability of the jOOQ DSL
As of jOOQ 3.16, yes, those particular methods expose mutable behaviour, so you can dynamically construct the query as you did. See also the jOOQ manual's section about mutability, which hints at this possibly changing in the (far) future, in favour of more predictable immutable DSL APIs.
But even if this can be exploited, you should not construct dynamic SQL queries like this. Use the recommended approach:
This doesn't help you with your actual question, but it answers parts of the question you have asked, namely, you shouldn't rely on this mutable behaviour.
Specific questions
No, you cannot.
a
was modified, see the section about mutability.You can either use the built in execute logging, which logs all queries to the
DEBUG
level.Yes, those calls are safe. That's what the above execute logging does, too, in order to apply formatting, inlining of bind values for logging purposes, etc.