Example usage for org.hibernate.event.spi AbstractEvent getSession

List of usage examples for org.hibernate.event.spi AbstractEvent getSession

Introduction

In this page you can find the example usage for org.hibernate.event.spi AbstractEvent getSession.

Prototype

public final EventSource getSession() 

Source Link

Document

Returns the session event source for this event.

Usage

From source file:de.dktk.dd.rpb.portal.audit.AuditLogListener.java

License:Open Source License

private void audit(AbstractEvent hibernateEvent, final AuditLog auditLog) {
    hibernateEvent.getSession().getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {
        @Override/* ww  w.j  ava 2s .c o m*/
        public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
            if (success) {
                auditLogService.log(auditLog);
            }
        }
    });
}

From source file:org.grails.orm.hibernate.support.ClosureEventListener.java

License:Apache License

private <T> T doWithManualSession(AbstractEvent event, Closure<T> callable) {
    Session session = event.getSession();
    FlushMode current = session.getFlushMode();
    try {//from  ww w.  jav  a 2  s. co m
        session.setFlushMode(FlushMode.MANUAL);
        return callable.call();
    } finally {
        session.setFlushMode(current);
    }
}

From source file:org.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor.java

License:Apache License

private Datastore findDatastore(AbstractEvent hibernateEvent) {
    SessionFactory sessionFactory = hibernateEvent.getSession().getSessionFactory();
    if (!(sessionFactory instanceof SessionFactoryProxy)) {
        // should always be the case
        for (Map.Entry<SessionFactory, HibernateDatastore> entry : datastores.entrySet()) {
            SessionFactory sf = entry.getKey();
            if (sf instanceof SessionFactoryProxy) {
                if (((SessionFactoryProxy) sf).getCurrentSessionFactory() == sessionFactory) {
                    return entry.getValue();
                }/*  www. j a v a 2s .  com*/
            }
        }
    }

    Datastore datastore = datastores.get(sessionFactory);
    if (datastore == null && datastores.size() == 1) {
        datastore = datastores.values().iterator().next();
    }
    return datastore;
}

From source file:org.libreplan.business.hibernate.notification.HibernateDatabaseModificationsListener.java

License:Open Source License

private Transaction inferTransaction(AbstractEvent event) {
    return event.getSession().getTransaction();
}