扩展JOOQ Table类 [英] Extending a JOOQ Table class

查看:88
本文介绍了扩展JOOQ Table类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文档"表(非常原始),我需要在运行时动态子集化,以便在应用程序/数据库之间存在一些时间限制的情况下,我的API使用者无法查看不合法的数据. JOOQ为我创建了一个很好的自动生成Document类,它表示该表.

I have a 'document' table (very original) that I need to dynamically subset at runtime so that my API consumers can't see data that isn't legal to view given some temporal constraints between the application/database. JOOQ created me a nice auto-gen Document class that represents this table.

理想情况下,我想创建一个Document的匿名子类,该子类实际上可以转换为

Ideally, I'd like to create an anonymous subclass of Document that actually translates to

SELECT document.* FROM document, other_table 
WHERE document.id = other_table.doc_id AND other_table.foo = 'bar'

请注意,bar在运行时是动态的,因此需要匿名扩展它.我可以匿名扩展Document类,这一切对我的API使用者来说都很不错,但我不知道如何实际限制数据. accept()是最终的,并且toSQL似乎没有任何作用.

Note that bar is dynamic at runtime hence the desire to extend it anonymously. I can extend the Document class anonymously and everything looks great to my API consumers, but I can't figure out how to actually restrict the data. accept() is final and toSQL doesn't seem to have any effect.

如果这不可能,并且我需要扩展CustomTable,那么我应该重写哪种方法来提供我的自定义SQL? JOOQ文档说要覆盖accept(),但是该方法在TableImpl中被标记为final,CustomITable是该方法的扩展.这是在JOOQ 3.5.3.上.

If this isn't possible and I need to extend CustomTable, what method do I override to provide my custom SQL? The JOOQ docs say to override accept(), but that method is marked final in TableImpl, which CustomTable extends from. This is on JOOQ 3.5.3.

谢谢, 凯尔

在删除TableImpl.accept()上的"final"修饰符后,我从源代码构建了3.5.4,并且能够完全执行我想要的操作.鉴于文档暗示我应该能够覆盖接受,也许这只是错误的最终声明的简单问题.

I built 3.5.4 from source after removing the "final" modifier on TableImpl.accept() and was able to do exactly what I wanted. Given that the docs imply I should be able to override accept perhaps it's just a simple matter of an erroneous final declaration.

推荐答案

也许您可以实现接口之一

Maybe you can implement one of the interfaces

  • TableLike(并将所有方法委托给JOOQ实现实例),例如TableImpl(使用HashMap来存储字段的动态字段?)

  • TableLike (and delegate all methods to a JOOQ implementation instance) such as TableImpl (dynamic field using a HashMap to store the Fields?)

实现Field界面(并使之动态)

Implement the Field interface (and make it dynamic)

无论如何,您都需要提醒JOOQ构建查询,绑定值,执行查询时有不同的阶段.您可能应该避免在开始构建查询时更改"foo"字段.

Anyway you will need to remind that there are different phases while JOOQ builds the query, binds values, executes it etc. You should probably avoid changing the "foo" Field when starting to build a query.

自从我与JOOQ合作以来已经有一段时间了.我的团队最终建立了一个定制的JOOQ.连接到JOOQ库的另一个(肮脏的)技巧是使用相同的程序包,因为受保护的标识符使所有内容在同一程序包以及子类中都可见...

It's been a while since I worked with JOOQ. My team ended up building a customized JOOQ. Another (dirty) trick to hook into the JOOQ library was to use the same packages, as the protected identifier makes everything visible within the same package as well as to sub classes...

这篇关于扩展JOOQ Table类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆