Hello Lukas,

the generic Map<Object, Object> is indeed a good solution. 
I have changed my code accordingly, and the result looks better!
I can use the default nested-transactions the way they are described in the 
jooq documentation 
and with help of "dsl.data(x,y)" i still have my context-specific data 
available in my dao-layer.

---
i implemented the tenantId-check for all SELECT-Statements with a custom 
ExecuteListener,
that checks for the table if it contains a column "clientId" and will 
append the clientId from the request.
see: 
https://github.com/funkrusher/fk-framework-quarkus-jooq/blob/main/fk_core/src/main/java/org/fk/core/jooq/FkExecuteListener.java

I will keep the Policy Feature in my mind, for a reason in my company to 
get a commercial license someday! 
one thing would be helpful for the policy feature in my opinion:
- having all Tables generated by the Codegen present when the Policy is 
set, to automatically generate the list of all tables that contain a 
"tenantId", to not need to write them manually
- criterias depending on the existence of columns in a table (add criteria 
x, if table contains field "y")

but that only as an idea.


[email protected] schrieb am Montag, 25. März 2024 um 10:46:20 UTC:

> On Mon, Mar 25, 2024 at 11:35 AM 'Bernd Huber' via jOOQ User Group <
> [email protected]> wrote:
>
>> Hello Lukas,
>>
>> thanks for following up.
>>
>> exactly like you said, i wrote the own utility because i want to pass the 
>> following data from the Manager/Services-Layer into the DAO-Layer for each 
>> "daoFactory.createXyzDao()" call:
>> - tenantId
>> - langId of the user
>> - the dsl of jooq
>>
>
> Note that all jOOQ Scope types as well as the Configuration have a generic 
> Map<Object, Object>, which can be used to pass around such context objects. 
> Perhaps that would be useful here.
>  
>
>> when i use the DSLContext.transaction() API directly, the could be not as 
>> slim, i think. See:
>>
>> ```java
>>
>> DSLContext ctx = DslContextFactory.createDSLContext(request);
>>
>> ctx.transaction(trx -> {
>>     
>>     AuthorDao authorDao = daoFactory.createAuthorDao(requestContext, trx)
>>
>>     trx.dsl().transaction(trx1 -> {
>>         // ..
>>             BookDao bookDao = daoFactory.createBookDao(requestContext, 
>> trx1)
>>     });
>>
>> ```
>>
>> the instantiation of the DSLContext necessarily needs to be given the 
>> "request" object which contains the "tenantId" and the "langId", 
>> so it can construct the DSLContext by attaching a custom 
>> "DefaultExecuteListenerProvider" to the configuration of the DSLContext,
>> so all Queries executed by jooq will be appended a "WHERE tenantId = 
>> xyz", to automatically make sure that a user of tenant=xyz never
>> sees or accesses data from an other tenant.
>>
>
> How did you implement this from an ExecuteListener? With a regular 
> expression or VisitListener? Or with the policy feature?
> https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
>
> Though policies are registered separately from an ExecuteListener in the 
> Configuration...
>
>>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/3ad90acc-6c94-4946-8739-f0e3d0d1100bn%40googlegroups.com.

Reply via email to