简体   繁体   English

JOOQ Metamodel:为什么没有Table.rename(String)?

[英]JOOQ Metamodel: why is there no Table.rename(String)?

I am dynamically creating and using physical DB tables for which I only have one metamodel object. 我正在动态创建和使用物理数据库表,我只有一个元模型对象。 An example: I have one JOOQ class Customer in my metamodel, but I have CUSTOMER1 , CUSTOMER2 , etc. at runtime. 一个例子:我的元模型中有一个JOOQ类Customer ,但我在运行时有CUSTOMER1CUSTOMER2等。 I'd like to write strongly typed JOOQ queries for these dynamic tables. 我想为这些动态表编写强类型的JOOQ查询。 The following seems to do the trick: 以下似乎可以解决问题:

Customer CUSTOMER1 = Customer.rename("CUSTOMER1")

Of course, there's a whole bunch of tables for which I need to do this. 当然,我需要做一大堆表格。 Unfortunately, I cannot leverage the rename method generically, because it is not part of the Table<R> interface. 不幸的是,我无法一般地利用rename方法,因为它不是Table<R>接口的一部分。 Is this an oversight or a deliberate measure against something I am missing? 这是对我失踪的事情的疏忽或蓄意措施吗?

Is there a robust and elegant way to achieve what I want, ie without resorting to reflection? 是否有一种强大而优雅的方式来实现我想要的,即不采用反思?

EDIT : the two tables are never used jointly in the same query. 编辑 :这两个表永远不会在同一个查询中联合使用。 Concrete usage pattern is the following: At any given moment, a DB synonym CUSTOMER will point to one (the active), while the other is being modified (the shadow copy). 具体使用模式如下:在任何给定时刻,DB同义词CUSTOMER将指向一个(活动),而另一个正在被修改(阴影副本)。 Once the modification is complete, roles are swapped by pointing the synonym at the other one, and we start over. 修改完成后,通过将同义词指向另一个角色来交换角色,然后我们重新开始。 We do this to minimize "downtime" of heavy reporting result tables. 我们这样做是为了尽量减少沉重的报告结果表的“停机时间”。

The answer to your question 你的问题的答案

The question being in the title: 题目中的问题是:

why is there no Table.rename(String)? 为什么没有Table.rename(String)?

The feature was implemented in jOOQ 3.3 ( #2921 ). 该功能在jOOQ 3.3( #2921 )中实现。 The issue reads: 问题如下:

As table renaming is not really a SQL DSL feature, the rename() method should be generated onto generated tables only, instead of being declared in org.jooq.Table 由于表重命名实际上不是SQL DSL功能,因此只应在生成的表上生成rename()方法,而不是在org.jooq.Table中声明

In fact, this argument doesn't really make much sense. 事实上,这个论点并没有多大意义。 There are other "non-DSL" utilities on the DSL types. DSL类型上还有其他“非DSL”实用程序。 I don't see why rename() is special. 我不明白为什么rename()很特别。 The method should be declared on Table as you suggested. 应该按照您的建议在Table上声明该方法。 This will be done in jOOQ 3.9 ( #5242 ). 这将在jOOQ 3.9( #5242 )中完成。

The answer to your problem 你的问题的答案

From the update of your question, I understand that you don't really need that fine-grained renaming control. 从您的问题更新,我知道您并不真正需要细粒度的重命名控件。 jOOQ's out of the box multi-tenancy feature will do. jOOQ开箱即用的多租户功能可以做到。 This is called "table mapping" in the manual: 这在手册中称为“表映射”:

http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/runtime-schema-mapping http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/runtime-schema-mapping

For the scope of a Configuration (most fine-grained scope: per-query level), you can rewrite any matching table name as such: 对于Configuration的范围(最细粒度的范围:每个查询级别),您可以重写任何匹配的表名:

Settings settings = new Settings()
    .withRenderMapping(new RenderMapping()
    .withSchemata(
        new MappedSchema().withInput("MY_SCHEMA")
                          .withOutput("MY_SCHEMA")
                          .withTables(
         new MappedTable().withInput("CUSTOMER")
                          .withOutput("CUSTOMER1"))));

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

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