Example usage for org.apache.ibatis.datasource.pooled PooledDataSource isPoolPingEnabled

List of usage examples for org.apache.ibatis.datasource.pooled PooledDataSource isPoolPingEnabled

Introduction

In this page you can find the example usage for org.apache.ibatis.datasource.pooled PooledDataSource isPoolPingEnabled.

Prototype

public boolean isPoolPingEnabled() 

Source Link

Usage

From source file:org.mybatis.guice.datasource.builtin.PooledDataSourceProviderTest.java

License:Apache License

@Test
public void get() throws Throwable {
    final String driver = "org.mybatis.guice.TestDriver";
    final String url = "jdbc:h2:mem:testdb";
    final String username = "test_user";
    final String password = "test_password";
    final boolean autoCommit = true;
    final int loginTimeout = 10;
    final Properties driverProperties = new Properties();
    driverProperties.setProperty("my_property", "true");
    final int maximumActiveConnections = 20;
    final int maximumCheckoutTime = 30;
    final int maximumIdleConnections = 40;
    final int pingConnectionsNotUsedFor = 50;
    final boolean pingEnabled = true;
    final String pingQuery = "SELECT 1";
    final int timeToWait = 60;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override//from   ww w . ja  va 2  s. c  o m
        protected void configure() {
            bind(ClassLoader.class).annotatedWith(Names.named("JDBC.driverClassLoader"))
                    .toInstance(driverClassLoader);
            bindConstant().annotatedWith(Names.named("JDBC.driver")).to(driver);
            bindConstant().annotatedWith(Names.named("JDBC.url")).to(url);
            bindConstant().annotatedWith(Names.named("JDBC.username")).to(username);
            bindConstant().annotatedWith(Names.named("JDBC.password")).to(password);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bind(Properties.class).annotatedWith(Names.named("JDBC.driverProperties"))
                    .toInstance(driverProperties);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumActiveConnections"))
                    .to(maximumActiveConnections);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumCheckoutTime"))
                    .to(maximumCheckoutTime);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumIdleConnections"))
                    .to(maximumIdleConnections);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingConnectionsNotUsedFor"))
                    .to(pingConnectionsNotUsedFor);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingEnabled")).to(pingEnabled);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingQuery")).to(pingQuery);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.timeToWait")).to(timeToWait);
        }
    });
    PooledDataSourceProvider provider = injector.getInstance(PooledDataSourceProvider.class);

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

    assertEquals(driver, dataSource.getDriver());
    assertEquals(url, dataSource.getUrl());
    assertEquals(username, dataSource.getUsername());
    assertEquals(password, dataSource.getPassword());
    assertEquals(autoCommit, dataSource.isAutoCommit());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(driverProperties, dataSource.getDriverProperties());
    assertEquals(maximumActiveConnections, dataSource.getPoolMaximumActiveConnections());
    assertEquals(maximumCheckoutTime, dataSource.getPoolMaximumCheckoutTime());
    assertEquals(maximumIdleConnections, dataSource.getPoolMaximumIdleConnections());
    assertEquals(pingConnectionsNotUsedFor, dataSource.getPoolPingConnectionsNotUsedFor());
    assertEquals(pingEnabled, dataSource.isPoolPingEnabled());
    assertEquals(pingQuery, dataSource.getPoolPingQuery());
    assertEquals(timeToWait, dataSource.getPoolTimeToWait());
}

From source file:org.mybatis.guice.datasource.builtin.PooledDataSourceProviderTest.java

License:Apache License

@Test
public void get_OtherValues() throws Throwable {
    final String driver = "org.mybatis.guice.TestDriver2";
    final String url = "jdbc:h2:mem:testdb2";
    final String username = "test_user2";
    final String password = "test_password2";
    final boolean autoCommit = false;
    final int loginTimeout = 11;
    final Properties driverProperties = new Properties();
    driverProperties.setProperty("my_property", "false");
    final int maximumActiveConnections = 21;
    final int maximumCheckoutTime = 31;
    final int maximumIdleConnections = 41;
    final int pingConnectionsNotUsedFor = 51;
    final boolean pingEnabled = false;
    final String pingQuery = "SELECT 1";
    final int timeToWait = 61;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override/*from w  w  w .j  a  v  a2s .  co  m*/
        protected void configure() {
            bind(ClassLoader.class).annotatedWith(Names.named("JDBC.driverClassLoader"))
                    .toInstance(driverClassLoader);
            bindConstant().annotatedWith(Names.named("JDBC.driver")).to(driver);
            bindConstant().annotatedWith(Names.named("JDBC.url")).to(url);
            bindConstant().annotatedWith(Names.named("JDBC.username")).to(username);
            bindConstant().annotatedWith(Names.named("JDBC.password")).to(password);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bind(Properties.class).annotatedWith(Names.named("JDBC.driverProperties"))
                    .toInstance(driverProperties);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumActiveConnections"))
                    .to(maximumActiveConnections);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumCheckoutTime"))
                    .to(maximumCheckoutTime);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumIdleConnections"))
                    .to(maximumIdleConnections);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingConnectionsNotUsedFor"))
                    .to(pingConnectionsNotUsedFor);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingEnabled")).to(pingEnabled);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.pingQuery")).to(pingQuery);
            bindConstant().annotatedWith(Names.named("mybatis.pooled.timeToWait")).to(timeToWait);
        }
    });
    PooledDataSourceProvider provider = injector.getInstance(PooledDataSourceProvider.class);

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

    assertEquals(driver, dataSource.getDriver());
    assertEquals(url, dataSource.getUrl());
    assertEquals(username, dataSource.getUsername());
    assertEquals(password, dataSource.getPassword());
    assertEquals(autoCommit, dataSource.isAutoCommit());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(driverProperties, dataSource.getDriverProperties());
    assertEquals(maximumActiveConnections, dataSource.getPoolMaximumActiveConnections());
    assertEquals(maximumCheckoutTime, dataSource.getPoolMaximumCheckoutTime());
    assertEquals(maximumIdleConnections, dataSource.getPoolMaximumIdleConnections());
    assertEquals(pingConnectionsNotUsedFor, dataSource.getPoolPingConnectionsNotUsedFor());
    assertEquals(pingEnabled, dataSource.isPoolPingEnabled());
    assertEquals(pingQuery, dataSource.getPoolPingQuery());
    assertEquals(timeToWait, dataSource.getPoolTimeToWait());
}