All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.hibernate.orm.runtime.RequestScopedStatelessSessionHolder Maven / Gradle / Ivy

package io.quarkus.hibernate.orm.runtime;

import java.util.HashMap;
import java.util.Map;

import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.RequestScoped;

import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;

/**
 * Bean that is used to manage request scoped stateless sessions
 */
@RequestScoped
public class RequestScopedStatelessSessionHolder {

    private final Map sessions = new HashMap<>();

    public StatelessSession getOrCreateSession(String name, SessionFactory factory) {
        return sessions.computeIfAbsent(name, (n) -> factory.openStatelessSession());
    }

    @PreDestroy
    public void destroy() {
        for (Map.Entry entry : sessions.entrySet()) {
            entry.getValue().close();
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy