Java 类org.hibernate.service.jdbc.connections.spi.ConnectionProvider 实例源码

项目:vibur-dbcp-hibernate4.012    文件:ViburDBCPConnectionProviderTest.java   
@Test
public void testSelectStatementWithStatementsCache() throws SQLException {
    Session session = HibernateTestUtils.getSessionFactoryWithStmtCache().openSession();

    ConnectionProvider cp = ((SessionFactoryImplementor) session.getSessionFactory())
            .getServiceRegistry().getService(ConnectionProvider.class);
    ViburDBCPDataSource ds = ((ViburDBCPConnectionProvider) cp).getDataSource();

    ConcurrentMap<StatementMethod, StatementHolder> mockedStatementCache = mockStatementCache(ds);

    executeAndVerifySelectInSession(session);
    // resources/hibernate-with-stmt-cache.cfg.xml defines pool with 1 connection only, that's why
    // the second session will get and use the same underlying connection.
    session = HibernateTestUtils.getSessionFactoryWithStmtCache().openSession();
    executeAndVerifySelectInSession(session);

    InOrder inOrder = inOrder(mockedStatementCache);
    inOrder.verify(mockedStatementCache).get(key1.capture());
    inOrder.verify(mockedStatementCache).putIfAbsent(same(key1.getValue()), val1.capture());
    inOrder.verify(mockedStatementCache).get(key2.capture());

    assertEquals(1, mockedStatementCache.size());
    assertTrue(mockedStatementCache.containsKey(key1.getValue()));
    assertEquals(key1.getValue(), key2.getValue());
    assertEquals(AVAILABLE, val1.getValue().state().get());
}
项目:openeos    文件:ServiceRegistryBuilderImpl.java   
@Override
public ServiceRegistry buildServiceRegistry() {
    if (connectionProviderBuilder == null || configurationPovider == null) {
        throw new IllegalArgumentException();
    }
    LOG.debug("Creating service registry");
    BootstrapServiceRegistry bootstrapServiceRegistry = buildBootstrapServiceRegistry();
    org.hibernate.service.ServiceRegistryBuilder builder = new org.hibernate.service.ServiceRegistryBuilder(
            bootstrapServiceRegistry).addService(ConnectionProvider.class, connectionProviderBuilder.buildConnectionProvider());
    if (sessionObserver != null) {
        builder.addService(SessionObserver.class, sessionObserver);
    }
    builder.applySettings(configurationPovider.getConfiguration().getProperties());
    return builder.buildServiceRegistry();

}
项目:appengine-hibernate    文件:CloudSqlConnectionProvider.java   
@Override
@SuppressWarnings( {"unchecked"})
public <T> T unwrap(Class<T> unwrapType) {
    if ( ConnectionProvider.class.equals( unwrapType ) ||
            CloudSqlConnectionProvider.class.isAssignableFrom( unwrapType ) ) {
        return (T) this;
    }
    else {
        throw new UnknownUnwrapTypeException( unwrapType );
    }
}
项目: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;
    }
}
项目:snakerflow    文件:Hibernate4Access.java   
/**
 * 取得hibernate的connection对象
 */
protected Connection getConnection() throws SQLException {
    if (sessionFactory instanceof SessionFactoryImpl) {
        SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory;
        ConnectionProvider provider = sessionFactoryImpl.getServiceRegistry().getService(ConnectionProvider.class);
        if(provider != null) return provider.getConnection();
    }
    return null;
}
项目:class-guard    文件:SessionFactoryUtils.java   
/**
 * Determine the DataSource of the given SessionFactory.
 * @param sessionFactory the SessionFactory to check
 * @return the DataSource, or {@code null} if none found
 * @see org.hibernate.engine.spi.SessionFactoryImplementor#getConnectionProvider
 */
public static DataSource getDataSource(SessionFactory sessionFactory) {
    if (sessionFactory instanceof SessionFactoryImplementor) {
        ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider();
        return cp.unwrap(DataSource.class);
    }
    return null;
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
private JdbcConnectionAccess buildLocalConnectionAccess() {
    return new JdbcConnectionAccess() {
        @Override
        public Connection obtainConnection() throws SQLException {
            return settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE ? serviceRegistry
                    .getService(ConnectionProvider.class).getConnection()
                    : serviceRegistry.getService(
                            MultiTenantConnectionProvider.class)
                            .getAnyConnection();
        }

        @Override
        public void releaseConnection(Connection connection)
                throws SQLException {
            if (settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE) {
                serviceRegistry.getService(ConnectionProvider.class)
                        .closeConnection(connection);
            } else {
                serviceRegistry.getService(
                        MultiTenantConnectionProvider.class)
                        .releaseAnyConnection(connection);
            }
        }

        @Override
        public boolean supportsAggressiveRelease() {
            return false;
        }
    };
}
项目:books    文件:ManagedProvidedConnectionHelper.java   
@Override
public void prepare(boolean needsAutoCommit) throws SQLException {
    serviceRegistry = createServiceRegistry(cfgProperties);
    connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
    if (needsAutoCommit && !connection.getAutoCommit()) {
        connection.commit();
        connection.setAutoCommit(true);
    }
}
项目:books    文件:ManagedProvidedConnectionHelper.java   
private void releaseConnection() throws SQLException {
    if (connection != null) {
        try {
            new SqlExceptionHelper().logAndClearWarnings(connection);
        } finally {
            try {
                serviceRegistry.getService(ConnectionProvider.class).closeConnection(connection);
            } finally {
                connection = null;
            }
        }
    }
}
项目:vibur-dbcp-hibernate4.012    文件:ViburDBCPConnectionProvider.java   
@Override
public boolean isUnwrappableAs(Class unwrapType) {
    return ConnectionProvider.class.equals(unwrapType) ||
        ViburDBCPConnectionProvider.class.isAssignableFrom(unwrapType);
}
项目:appengine-hibernate    文件:CloudSqlConnectionProvider.java   
@Override
public boolean isUnwrappableAs(Class unwrapType) {
    return ConnectionProvider.class.equals( unwrapType ) ||
            CloudSqlConnectionProvider.class.isAssignableFrom( unwrapType );
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
public ConnectionProvider getConnectionProvider() {
    return jdbcServices.getConnectionProvider();
}
项目:books    文件:SuppliedConnectionProviderConnectionHelper.java   
public SuppliedConnectionProviderConnectionHelper(ConnectionProvider provider) {
    this.provider = provider;
}
项目: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;
}
项目:openeos    文件:ConnectionProviderBuilder.java   
public ConnectionProvider buildConnectionProvider();