-
Could you please assist me in identifying the optimal approach to implement Multi-Tenancy in my database using Spring and jOOQ? My objective is to dynamically extract the Additionally, I aim to ensure that new tenants can be seamlessly and dynamically added. What best practices and concepts should be considered when implementing these requirements, and how can they be effectively implemented in jOOQ? I tried it with @Bean
fun configuration(): DefaultConfigurationCustomizer {
return DefaultConfigurationCustomizer { defaultConfiguration: DefaultConfiguration ->
defaultConfiguration.set(
DefaultPolicyProvider()
.append(
AREA,
AREA.TENANT_ID.eq(1)
)
)
}
} This raises the question of whether the ID can be set dynamically here. In addition, the approach unfortunately did not work with the following insert: fun insert(area: AreaRequest): Area {
return dsl.insertInto(AREA)
.set(AREA.NAME, area.name)
.returning()
.fetchSingleInto(Area::class.java)
} Log:
No database entry is created. Many thanks for the great tool and the support. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
jOOQ isn't really opinionated about "best practices" (assuming these are either about Spring or kotlin or both). jOOQ's SPIs are designed to support any such "best practice"
Of course. Every jOOQ query is dynamic, including such predicates provided by yourself. You can provide
Of course not! You have to provide the You can see how this works in the generated query: insert into "public"."area" ("name", "tenant_id")
select "t"."name", "t"."tenant_id" from (
select 'A1', cast(null as int) -- You didn't provide the TENANT_ID here!
) as "t" ("name", "tenant_id")
where "t"."tenant_id" = 1 -- Hence, this predicate is NULL (effectively FALSE)
returning "area"."area_id", "area"."name", "area"."tenant_id" |
Beta Was this translation helpful? Give feedback.
jOOQ isn't really opinionated about "best practices" (assuming these are either about Spring or kotlin or both). jOOQ's SPIs are designed to support any such "best practice"
Of course. Every jOOQ query is dynamic, including such predicates provided by yourself. You can provide
AREA.TENANT_ID.eq(myId)
. You can configure jOOQ in any way you want. While theDefaultPolicyProvider
helps implement very simplePolicyProvider
implementations, you can always also implement the int…