Java 类org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl 实例源码

项目:openeos    文件:ConnectionProviderBuilderImpl.java   
@Override
public ConnectionProvider buildConnectionProvider() {
    if (this.dataSourceProvider == null) {
        throw new IllegalStateException();
    }
    LOG.debug("Building new Connection Provider using datasourceProvider");
    DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl();
    connectionProvider.setDataSource(dataSourceProvider.getDataSource());
    connectionProvider.configure(Collections.emptyMap());
    return connectionProvider;
}
项目:openeos    文件:SessionFactoryManagerOsgiService.java   
@Override
public synchronized SessionFactory buildSessionFactory() {
    try {
        LOG.debug("Building new session factory");
        SessionFactory real = configurationProvider.getConfiguration().buildSessionFactory(
                this.serviceRegistryBuilder.buildServiceRegistry());

        LOG.debug("Session factory created, creating new Transaction Manager to handle transactions");
        HibernateTransactionManager txManager = new HibernateTransactionManager();

        txManager.setDataSource(((DatasourceConnectionProviderImpl) ((SessionFactoryImplementor) real).getServiceRegistry()
                .getService(ConnectionProvider.class)).getDataSource());
        txManager.setSessionFactory(proxySessionFactory);
        txManager.setValidateExistingTransaction(true);
        txManager.afterPropertiesSet();

        // The anotations at this point uses the new transaction manager
        AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf();
        txAspect.setTransactionManager(txManager);
        LOG.debug("New transaction manager established to AnnotationTransactionAspect, now the annotations used the new Transaction Manager");

        return real;
    } catch (RuntimeException ex) {
        LOG.error("Runtime exception when trying to create session factory.", ex);
        throw ex;
    }
}
项目:searchisko    文件:CdiHelper.java   
/**
     * Get Default DataSource. JNDI name of datasource is taken from Entity Manager
     *
     * @return
     * @throws NamingException
     */
    public static DataSource getDefaultDataSource(EntityManager em) throws NamingException {
//      Doesn't work because of https://hibernate.atlassian.net/browse/HHH-8121
//      EntityManagerFactory emFactory = em.getEntityManagerFactory();
//      Object ds = emFactory.getProperties().get("javax.persistence.jtaDataSource");
//      InitialContext initialContext = new InitialContext();
//      Object lookup = initialContext.lookup(ds.toString());
//      return (DataSource) lookup;

//      TODO: Find better way how to get DataSource from JPA without using hard coded JNDI name or casting to JPA implementation
        SessionFactoryImpl factory = (SessionFactoryImpl) em.unwrap(Session.class).getSessionFactory(); // or directly cast the sessionFactory
        DatasourceConnectionProviderImpl provider = (DatasourceConnectionProviderImpl) factory.getConnectionProvider();
        return provider.getDataSource();
    }
项目:ignite    文件:HibernateL2CacheTransactionalSelfTest.java   
/** {@inheritDoc} */
@Nullable @Override protected ServiceRegistryBuilder registryBuilder() {
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();

    BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.

    dataSrc.setTransactionManager(jotm.getTransactionManager());

    dataSrc.setDefaultAutoCommit(false);

    JdbcDataSource h2DataSrc = new JdbcDataSource();

    h2DataSrc.setURL(CONNECTION_URL);

    dataSrc.setXaDataSourceInstance(h2DataSrc);

    connProvider.setDataSource(dataSrc);

    connProvider.configure(Collections.emptyMap());

    builder.addService(ConnectionProvider.class, connProvider);

    builder.addService(JtaPlatform.class, new TestJtaPlatform());

    builder.addService(TransactionFactory.class, new JtaTransactionFactory());

    return builder;
}