Java 类io.dropwizard.db.ManagedPooledDataSource 实例源码

项目:dropwizard-mybatis    文件:ConfigurableLazyDataSourceFactory.java   
/** {@inheritDoc} */
@Override
public ManagedDataSource build(MetricRegistry metricRegistry, String name) throws
        ClassNotFoundException {
    ManagedDataSource managedDataSource = super.build(metricRegistry, name);

    if (isLazy) {
        if (managedDataSource instanceof ManagedPooledDataSource) {
        /* of course we can't depend on it by method protocol, but right now
         * (currently used version of dropwizard 0.7.1 as well as last currently available 0.8.1)
         * exactly this implementation will be returned by super.build(MetricRegistry mr, String name) method
         */
            ManagedPooledDataSource managedPooledDataSource = (ManagedPooledDataSource) managedDataSource;
            return new LazyManagedPooledDataSource(managedPooledDataSource.getPoolProperties(), metricRegistry);
        }

        throw new AssertionError(
                "You can't use this DataSourceFactory implementation with your dropwizard version");
    } else {
        return managedDataSource;
    }
}
项目:CredentialStorageService-dw-hibernate    文件:SessionFactoryFactoryTest.java   
@Test
    public void setsPoolName() {
        this.build();

        final ArgumentCaptor<SessionFactoryManager> sessionFactoryManager = ArgumentCaptor.forClass(SessionFactoryManager.class);
        verify(this.lifecycleEnvironment).manage(sessionFactoryManager.capture());
        final ManagedPooledDataSource dataSource = (ManagedPooledDataSource) sessionFactoryManager.getValue().getDataSource();
//        assertThat(dataSource.toString()).isEqualTo("hibernate");
    }
项目:CredentialStorageService-dw-hibernate    文件:SessionFactoryFactoryTest.java   
@Test
    public void setsACustomPoolName() {
        this.sessionFactory = this.factory.build(this.bundle, this.environment, this.config,
                ImmutableList.<Class<?>>of(Person.class), "custom-hibernate-db");

        final ArgumentCaptor<SessionFactoryManager> sessionFactoryManager = ArgumentCaptor.forClass(SessionFactoryManager.class);
        verify(this.lifecycleEnvironment).manage(sessionFactoryManager.capture());
        final ManagedPooledDataSource dataSource = (ManagedPooledDataSource) sessionFactoryManager.getValue().getDataSource();
//        assertThat(dataSource.getPool().getName()).isEqualTo("custom-hibernate-db");
    }
项目:dropwizard-entitymanager    文件:EntityManagerFactoryFactoryTest.java   
@Test
public void setsPoolName() {
    build();

    ArgumentCaptor<EntityManagerFactoryManager> manager = ArgumentCaptor.forClass(EntityManagerFactoryManager.class);
    verify(lifecycleEnvironment).manage(manager.capture());
    ManagedPooledDataSource dataSource = (ManagedPooledDataSource) manager.getValue().getDataSource();
    assertThat(dataSource.getPool().getName()).isEqualTo("hibernate-entitymanager");
}
项目:dropwizard-entitymanager    文件:EntityManagerFactoryFactoryTest.java   
@Test
public void setsACustomPoolName() {
    this.entityManagerFactory = factory.build(bundle, environment, config,
            ImmutableList.<Class<?>>of(Person.class), "custom-hibernate-db");

    ArgumentCaptor<EntityManagerFactoryManager> manager = ArgumentCaptor.forClass(EntityManagerFactoryManager.class);
    verify(lifecycleEnvironment).manage(manager.capture());
    ManagedPooledDataSource dataSource = (ManagedPooledDataSource) manager.getValue().getDataSource();
    assertThat(dataSource.getPool().getName()).isEqualTo("custom-hibernate-db");
}