jOOQ table 模板,查询的动态 table 名称
jOOQ table template, dynamic table name for queries
我想使用预定义的 table 模板动态创建新数据库 table。那部分我看不出有什么问题。
但是我想生成一个 jOOQ table class(从模板)来编写 jOOQ 查询,并在执行前更改 table 名称。
有人对此有解决方案吗?
为此使用 jOOQ 的运行时模式/table 映射支持:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withInput("THE_SCHEMA")
.withOutput("THE_SCHEMA")
.withTables(
new MappedTable().withInput("PREDEFINED_TABLE")
.withOutput("CHANGED_TABLE")
)
));
// Add the settings to the DSLContext
DSLContext ctx = DSL.using(connection, dialect, settings);
// Run your queries with the above ctx
ctx.select(PREDEFINED_TABLE.COLUMM)
.from(PREDEFINED_TABLE)
.fetch();
以上会生成
SELECT "THE_SCHEMA"."CHANGED_TABLE"."COLUMN"
FROM "THE_SCHEMA"."CHANGED_TABLE"
更多信息在这里:
http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/runtime-schema-mapping
我想使用预定义的 table 模板动态创建新数据库 table。那部分我看不出有什么问题。
但是我想生成一个 jOOQ table class(从模板)来编写 jOOQ 查询,并在执行前更改 table 名称。
有人对此有解决方案吗?
为此使用 jOOQ 的运行时模式/table 映射支持:
Settings settings = new Settings()
.withRenderMapping(new RenderMapping()
.withSchemata(
new MappedSchema().withInput("THE_SCHEMA")
.withOutput("THE_SCHEMA")
.withTables(
new MappedTable().withInput("PREDEFINED_TABLE")
.withOutput("CHANGED_TABLE")
)
));
// Add the settings to the DSLContext
DSLContext ctx = DSL.using(connection, dialect, settings);
// Run your queries with the above ctx
ctx.select(PREDEFINED_TABLE.COLUMM)
.from(PREDEFINED_TABLE)
.fetch();
以上会生成
SELECT "THE_SCHEMA"."CHANGED_TABLE"."COLUMN"
FROM "THE_SCHEMA"."CHANGED_TABLE"
更多信息在这里: http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/runtime-schema-mapping