Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to create an inherited policy that is evaluated at runtime

22 views
Skip to first unread message

Joaquin

unread,
Mar 20, 2025, 4:40:43 AMMar 20
to jOOQ User Group
Hello everyone,
I created an inherited policy with jooq, but it seems to get evaluted during initialization with Spring Boot.

this is my setup:

@Bean
DefaultConfigurationCustomizer defaultConfigurationCustomizer(CustomPolicyProvider customPolicyProvider) {
return configuration -> {
configuration.setRecordListener(new JooqRecordListener());
configuration.settings().setEmulateNestedRecordProjectionsUsingMultisetEmulation(true);
configuration.setPolicyProvider(customPolicyProvider);
};
}

the constructor of my policyProvider is done this way:

public CustomPolicyProvider(AuthenticationFacade authenticationFacade) {
this.append(new CustomPolicy<>(TABLE, () -> 
TABLE.child().ID.eq(authenticationFacade.getAuthenticatedUser().userId())), ANOTHER_TABLE.child()));
}

what happens is that this fails because the authenticationFacade is actually null during startup which makes sense, this works properly when I'm not using an inherited policy.

any ideas on how to get it working?

Thanks


Lukas Eder

unread,
Mar 24, 2025, 4:15:36 AMMar 24
to jooq...@googlegroups.com
Just create your policies at runtime rather than at configuration time. 

--
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 jooq-user+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jooq-user/293ed01d-6a53-4e73-8239-d5378f4305efn%40googlegroups.com.

Joaquin

unread,
Mar 25, 2025, 7:42:48 AMMar 25
to jOOQ User Group
what's the overhead to it? is it fine to pass the policy provider deriving the configuration everytime?

Lukas Eder

unread,
Mar 25, 2025, 8:40:17 AMMar 25
to jooq...@googlegroups.com
You don't have to create new configurations all the time. Just implement your own PolicyProvider that creates the policies on the fly. Try it, measure it.

If you're afraid (due to measurements) that overheads will be too high, you can also work with thread locals or whatever context provider to access your authenticated user from the policy predicate.

Joaquin

unread,
Mar 25, 2025, 8:48:28 AMMar 25
to jOOQ User Group
Got you, I'll create my custom policyprovider.
Thanks for the idea.

Lukas Eder

unread,
Mar 26, 2025, 6:35:21 AMMar 26
to jOOQ User Group
For the record, jOOQ 3.21 will offer a ContextPolicyProvider subtype, which is capable of receiving a new PolicyContext object that gives access to the rendering context:

It should be possible to communicate with other SPIs via this type in case Spring's injection capabilities do not suffice (though, they should IMO).

Joaquin

unread,
Mar 26, 2025, 7:45:29 AMMar 26
to jOOQ User Group
Looks awesome, may give a look to it tomorrow when snapshot is updated.
Reply all
Reply to author
Forward
0 new messages