Search in sources :

Example 1 with QueryBuilder

use of net.robinfriedli.aiode.persist.qb.QueryBuilder in project aiode by robinfriedli.

the class AccessConfigurationPartitionInterceptor method intercept.

@Override
public void intercept(QueryBuilder<?, ?, ?, ?> queryBuilder) {
    Optional<ExecutionContext> executionContext = ExecutionContext.Current.optional();
    if (executionContext.isPresent() || (session != null && guildId != null)) {
        Session session = executionContext.map(ExecutionContext::getSession).orElse(this.session);
        String id = executionContext.map(ctx -> ctx.getGuild().getId()).orElse(guildId);
        queryBuilder.where((cb, root, subQueryFactory) -> cb.equal(root.get("guildSpecification"), subQueryFactory.createUncorrelatedSubQuery(GuildSpecification.class, "pk").where((cb1, root1, subQueryFactory1) -> cb1.equal(root1.get("guildId"), id)).build(session)));
    }
}
Also used : ExecutionContext(net.robinfriedli.aiode.concurrent.ExecutionContext) Component(org.springframework.stereotype.Component) GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) AccessConfiguration(net.robinfriedli.aiode.entities.AccessConfiguration) QueryInterceptor(net.robinfriedli.aiode.persist.qb.interceptor.QueryInterceptor) Optional(java.util.Optional) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) QueryBuilder(net.robinfriedli.aiode.persist.qb.QueryBuilder) ExecutionContext(net.robinfriedli.aiode.concurrent.ExecutionContext) Session(org.hibernate.Session)

Aggregations

Optional (java.util.Optional)1 ExecutionContext (net.robinfriedli.aiode.concurrent.ExecutionContext)1 AccessConfiguration (net.robinfriedli.aiode.entities.AccessConfiguration)1 GuildSpecification (net.robinfriedli.aiode.entities.GuildSpecification)1 QueryBuilder (net.robinfriedli.aiode.persist.qb.QueryBuilder)1 QueryInterceptor (net.robinfriedli.aiode.persist.qb.interceptor.QueryInterceptor)1 Session (org.hibernate.Session)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1