Example usage for org.hibernate.service.spi ServiceBinding getService

List of usage examples for org.hibernate.service.spi ServiceBinding getService

Introduction

In this page you can find the example usage for org.hibernate.service.spi ServiceBinding getService.

Prototype

public R getService() 

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.GrailsSessionContext.java

License:Apache License

protected TransactionManager getJtaTransactionManager(Session session) {
    SessionFactoryImplementor sessionFactoryImpl = null;
    if (sessionFactory instanceof SessionFactoryImplementor) {
        sessionFactoryImpl = ((SessionFactoryImplementor) sessionFactory);
    } else if (session != null) {
        SessionFactory internalFactory = session.getSessionFactory();
        if (internalFactory instanceof SessionFactoryImplementor) {
            sessionFactoryImpl = (SessionFactoryImplementor) internalFactory;
        }//from   www  . j av  a  2 s  .  c  o m
    }

    if (sessionFactoryImpl == null) {
        return null;
    }

    ServiceBinding<JtaPlatform> sb = sessionFactory.getServiceRegistry()
            .locateServiceBinding(JtaPlatform.class);
    if (sb == null) {
        return null;
    }

    return sb.getService().retrieveTransactionManager();
}