Example usage for org.hibernate.engine.jdbc.connections.spi ConnectionProvider getConnection

List of usage examples for org.hibernate.engine.jdbc.connections.spi ConnectionProvider getConnection

Introduction

In this page you can find the example usage for org.hibernate.engine.jdbc.connections.spi ConnectionProvider getConnection.

Prototype

public Connection getConnection() throws SQLException;

Source Link

Document

Obtains a connection for Hibernate use according to the underlying strategy of this provider.

Usage

From source file:br.com.utfpr.pb.config.DatabaseConnection.java

private DatabaseConnection() {
    this.emf = Persistence.createEntityManagerFactory("default");

    Session session = getEntityManager().unwrap(Session.class);
    SessionFactoryImplementor sessionFactoryImplementation = (SessionFactoryImplementor) session
            .getSessionFactory();//from  w w  w. j  a  va 2  s  .  c  o  m
    ConnectionProvider connectionProvider = sessionFactoryImplementation.getConnectionProvider();
    try {
        this.conn = connectionProvider.getConnection();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

From source file:br.genericrepository.util.ManagerFactory.java

public Connection getConnection() {
    Connection connection = null;
    try {// ww w .  java  2  s  . co m
        Session session = (Session) em.getDelegate();
        SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
        ConnectionProvider cp = sfi.getConnectionProvider();
        connection = (Connection) cp.getConnection();
        return connection;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return connection;
}

From source file:org.squashtest.it.infrastructure.DeleteDataSetLoadStrategy.java

License:Open Source License

public Connection getConnection(Session session) {
    try {/*from w  ww.j a v a 2 s.c  o  m*/
        SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
        ConnectionProvider cp = sfi.getConnectionProvider();
        return cp.getConnection();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.teiid.spring.autoconfigure.SchemaBuilderUtility.java

License:Apache License

public static Metadata generateHbmModel(ConnectionProvider provider, Dialect dialect) throws SQLException {
    MetadataSources metadataSources = new MetadataSources();
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
                    .addService(ConnectionProvider.class, provider).addService(JdbcEnvironment.class,
                            new JdbcEnvironmentImpl(provider.getConnection().getMetaData(), dialect))
                    .build();/* w  w w . j a v a  2  s.co m*/

    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();
    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
    TypeResolver typeResolver = new TypeResolver(basicTypeRegistry, new TypeFactory());
    InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(options, typeResolver);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(options, null,
            metadataCollector);

    JDBCBinder binder = new JDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy, false);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));
    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        protected Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.start();
    return metadata;
}