Example usage for org.apache.commons.dbcp.datasources SharedPoolDataSource getJndiEnvironment

List of usage examples for org.apache.commons.dbcp.datasources SharedPoolDataSource getJndiEnvironment

Introduction

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

Prototype

public String getJndiEnvironment(String key) 

Source Link

Document

Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext.

Usage

From source file:org.mybatis.guice.datasource.dbcp.SharedPoolDataSourceProviderTest.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//  w  w w  .  ja  v a2 s  .c o  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);
        }
    });
    SharedPoolDataSourceProvider provider = injector.getInstance(SharedPoolDataSourceProvider.class);

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

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