Search in sources :

Example 1 with EnversService

use of org.hibernate.envers.boot.internal.EnversService in project hibernate-orm by hibernate.

the class AuditReaderFactory method get.

/**
	 * Create an audit reader associated with an open session.
	 *
	 * @param session An open session.
	 *
	 * @return An audit reader associated with the given sesison. It shouldn't be used
	 *         afterQuery the session is closed.
	 *
	 * @throws AuditException When the given required listeners aren't installed.
	 */
public static AuditReader get(Session session) throws AuditException {
    SessionImplementor sessionImpl;
    if (!(session instanceof SessionImplementor)) {
        sessionImpl = (SessionImplementor) session.getSessionFactory().getCurrentSession();
    } else {
        sessionImpl = (SessionImplementor) session;
    }
    final ServiceRegistry serviceRegistry = sessionImpl.getFactory().getServiceRegistry();
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    return new AuditReaderImpl(enversService, session, sessionImpl);
}
Also used : AuditReaderImpl(org.hibernate.envers.internal.reader.AuditReaderImpl) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) EnversService(org.hibernate.envers.boot.internal.EnversService) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Aggregations

SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1 EnversService (org.hibernate.envers.boot.internal.EnversService)1 AuditReaderImpl (org.hibernate.envers.internal.reader.AuditReaderImpl)1 ServiceRegistry (org.hibernate.service.ServiceRegistry)1