Example usage for org.hibernate.boot.registry.internal StandardServiceRegistryImpl getService

List of usage examples for org.hibernate.boot.registry.internal StandardServiceRegistryImpl getService

Introduction

In this page you can find the example usage for org.hibernate.boot.registry.internal StandardServiceRegistryImpl getService.

Prototype

@Override
    public <R extends Service> R getService(Class<R> serviceRole) 

Source Link

Usage

From source file:com.zutubi.pulse.master.hibernate.SchemaRefactor.java

License:Apache License

protected Object executeWithConnection(Callback c) throws SQLException {
    StandardServiceRegistryImpl serviceRegistry = null;
    Connection connection = null;
    try {//from  w  w w.j a  v  a  2s.  c  o  m
        serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
                .applySettings(connectionProperties).build();
        connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();

        conditionalBuildMappings();

        return c.execute(connection);
    } finally {
        if (serviceRegistry != null) {
            serviceRegistry.getService(ConnectionProvider.class).closeConnection(connection);
            serviceRegistry.destroy();
        }
    }
}