Jooq dynamically changes db schema in generated query

I have two similar schemes in a simple database - “development” and “stage”. I created Java classes with Jooq for one of these schemes (for example, "develop"). When jooq generates a request to db, it implicitly adds the schema name to all request aliases

select "develop"."image"."id", "develop"."image"."image_data" 
from "develop"."image" 
where "develop"."image"."id" = ?

So my question is, is there a way to change the jooq schema name (for "stage" as an example) in the generated query without restoring the jooq classes for the "stage" schema?

+9
source share
1 answer

You have several options that can be combined:

"develop" , , :

<configuration>
  <generator>
    <database>
      <schemata>
        <schema>
          <inputSchema>develop</inputSchema>
          <outputSchema>stage</outputSchema>
        </schema>
      ...

, , . , :

<configuration>
  <generator>
    <database>
      <schemata>
        <schema>
          <inputSchema>develop</inputSchema>
          <outputSchemaToDefault>true</outputSchemaToDefault>
        </schema>
      ...

, ( search_path, !)

,

: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-catalog-and-schema-mapping/

, Settings ( jOOQ Configuration). , :

:

new Settings().withRenderMapping(new RenderMapping()
  .withSchemata(new MappedSchema()
    .withInput("develop")
    .withOutput("stage")
  )
);

:

new Settings().withRenderSchema(false);

:https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-render-mapping/

+12

Source: https://habr.com/ru/post/1678867/


All Articles