Example usage for org.apache.commons.dbcp.datasources PerUserPoolDataSource getConnectionPoolDataSource

List of usage examples for org.apache.commons.dbcp.datasources PerUserPoolDataSource getConnectionPoolDataSource

Introduction

In this page you can find the example usage for org.apache.commons.dbcp.datasources PerUserPoolDataSource getConnectionPoolDataSource.

Prototype

public ConnectionPoolDataSource getConnectionPoolDataSource() 

Source Link

Document

Get the value of connectionPoolDataSource.

Usage

From source file:org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceProviderTest.java

@Test
public void get() throws Throwable {
    final boolean autoCommit = true;
    final int loginTimeout = 10;
    final boolean defaultReadOnly = true;
    final int defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
    final String description = "test_description";
    final int minEvictableIdleTimeMillis = 20;
    final int numTestsPerEvictionRun = 30;
    final boolean rollbackAfterValidation = true;
    final boolean testOnBorrow = true;
    final boolean testOnReturn = true;
    final boolean testWhileIdle = true;
    final int timeBetweenEvictionRunsMillis = 40;
    final String validationQuery = "SELECT 1";
    final int maxActive = 50;
    final int maxIdle = 60;
    final int maxWait = 70;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override/*from ww w  .j av a 2 s .  c  o m*/
        protected void configure() {
            bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly);
            bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation"))
                    .to(defaultTransactionIsolation);
            bindConstant().annotatedWith(Names.named("DBCP.description")).to(description);
            bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis"))
                    .to(minEvictableIdleTimeMillis);
            bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun);
            bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation"))
                    .to(rollbackAfterValidation);
            bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow);
            bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn);
            bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle);
            bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis"))
                    .to(timeBetweenEvictionRunsMillis);
            bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery);
            bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive);
            bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle);
            bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait);
        }
    });
    PerUserPoolDataSourceProvider provider = injector.getInstance(PerUserPoolDataSourceProvider.class);

    PerUserPoolDataSource dataSource = (PerUserPoolDataSource) provider.get();

    assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource());
    assertEquals(autoCommit, dataSource.isDefaultAutoCommit());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly());
    assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation());
    assertEquals(description, dataSource.getDescription());
    assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun());
    assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation());
    assertEquals(testOnBorrow, dataSource.isTestOnBorrow());
    assertEquals(testOnReturn, dataSource.isTestOnReturn());
    assertEquals(testWhileIdle, dataSource.isTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis());
    assertEquals(validationQuery, dataSource.getValidationQuery());
    assertEquals(maxActive, dataSource.getDefaultMaxActive());
    assertEquals(maxIdle, dataSource.getDefaultMaxIdle());
    assertEquals(maxWait, dataSource.getDefaultMaxWait());
}

From source file:org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceProviderTest.java

@Test
public void get_OtherValues() throws Throwable {
    final boolean autoCommit = false;
    final int loginTimeout = 11;
    final boolean defaultReadOnly = false;
    final int defaultTransactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
    final String description = "test_description2";
    final int minEvictableIdleTimeMillis = 21;
    final int numTestsPerEvictionRun = 31;
    final boolean rollbackAfterValidation = false;
    final boolean testOnBorrow = false;
    final boolean testOnReturn = false;
    final boolean testWhileIdle = false;
    final int timeBetweenEvictionRunsMillis = 41;
    final String validationQuery = "SELECT 2";
    final int maxActive = 51;
    final int maxIdle = 61;
    final int maxWait = 71;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override//from   w  w w  . j a v  a  2  s.co m
        protected void configure() {
            bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly);
            bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation"))
                    .to(defaultTransactionIsolation);
            bindConstant().annotatedWith(Names.named("DBCP.description")).to(description);
            bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis"))
                    .to(minEvictableIdleTimeMillis);
            bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun);
            bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation"))
                    .to(rollbackAfterValidation);
            bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow);
            bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn);
            bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle);
            bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis"))
                    .to(timeBetweenEvictionRunsMillis);
            bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery);
            bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive);
            bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle);
            bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait);
        }
    });
    PerUserPoolDataSourceProvider provider = injector.getInstance(PerUserPoolDataSourceProvider.class);

    PerUserPoolDataSource dataSource = (PerUserPoolDataSource) provider.get();

    assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource());
    assertEquals(autoCommit, dataSource.isDefaultAutoCommit());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly());
    assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation());
    assertEquals(description, dataSource.getDescription());
    assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun());
    assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation());
    assertEquals(testOnBorrow, dataSource.isTestOnBorrow());
    assertEquals(testOnReturn, dataSource.isTestOnReturn());
    assertEquals(testWhileIdle, dataSource.isTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis());
    assertEquals(validationQuery, dataSource.getValidationQuery());
    assertEquals(maxActive, dataSource.getDefaultMaxActive());
    assertEquals(maxIdle, dataSource.getDefaultMaxIdle());
    assertEquals(maxWait, dataSource.getDefaultMaxWait());
}

From source file:org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceProviderTest.java

@Test
public void get_Jndi() throws Throwable {
    final String jndiKey = "test_key";
    final String jndiValue = "test_value";
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override/*from  w  ww .j a va  2 s.  co  m*/
        protected void configure() {
            bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource);
            bindConstant().annotatedWith(Names.named("DBCP.jndi.key")).to(jndiKey);
            bindConstant().annotatedWith(Names.named("DBCP.jndi.value")).to(jndiValue);
        }
    });
    PerUserPoolDataSourceProvider provider = injector.getInstance(PerUserPoolDataSourceProvider.class);

    PerUserPoolDataSource dataSource = (PerUserPoolDataSource) provider.get();

    assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource());
    assertEquals(jndiValue, dataSource.getJndiEnvironment(jndiKey));
}