Example usage for org.apache.ibatis.datasource.unpooled UnpooledDataSource isAutoCommit

List of usage examples for org.apache.ibatis.datasource.unpooled UnpooledDataSource isAutoCommit

Introduction

In this page you can find the example usage for org.apache.ibatis.datasource.unpooled UnpooledDataSource isAutoCommit.

Prototype

public Boolean isAutoCommit() 

Source Link

Usage

From source file:org.mybatis.guice.datasource.builtin.UnpooledDataSourceProviderTest.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");
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override/* w w  w  . ja  va2s  .  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);
        }
    });
    UnpooledDataSourceProvider provider = injector.getInstance(UnpooledDataSourceProvider.class);

    UnpooledDataSource dataSource = (UnpooledDataSource) 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());
}

From source file:org.mybatis.guice.datasource.builtin.UnpooledDataSourceProviderTest.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");
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override//from ww  w.j  a v  a2  s  .  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);
        }
    });
    UnpooledDataSourceProvider provider = injector.getInstance(UnpooledDataSourceProvider.class);

    UnpooledDataSource dataSource = (UnpooledDataSource) 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());
}