Java Code Examples for org.apache.ibatis.datasource.pooled.PooledDataSource#setPoolTimeToWait()

The following examples show how to use org.apache.ibatis.datasource.pooled.PooledDataSource#setPoolTimeToWait() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskanaEngineTestConfiguration.java    From taskana with Apache License 2.0 6 votes vote down vote up
/**
 * create Default Datasource for in-memory database.
 *
 * @return the default datasource.
 */
private static DataSource createDefaultDataSource() {
  // JdbcDataSource ds = new JdbcDataSource();
  // ds.setURL("jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0");
  // ds.setPassword("sa");
  // ds.setUser("sa");

  String jdbcDriver = "org.h2.Driver";
  String jdbcUrl =
      "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;"
          + "INIT=CREATE SCHEMA IF NOT EXISTS TASKANA\\;"
          + "SET COLLATION DEFAULT_de_DE ";
  String dbUserName = "sa";
  String dbPassword = "sa";
  PooledDataSource ds =
      new PooledDataSource(
          Thread.currentThread().getContextClassLoader(),
          jdbcDriver,
          jdbcUrl,
          dbUserName,
          dbPassword);
  ds.setPoolTimeToWait(POOL_TIME_TO_WAIT);
  ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly

  return ds;
}
 
Example 2
Source File: AbstractAccTest.java    From taskana with Apache License 2.0 6 votes vote down vote up
/**
 * create Default DataSource for in-memory database.
 *
 * @return the TASKANA default datasource.
 */
private static DataSource createDefaultDataSource() {

  String jdbcDriver = "org.h2.Driver";
  String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0";
  String dbUserName = "sa";
  String dbPassword = "sa";
  PooledDataSource ds =
      new PooledDataSource(
          Thread.currentThread().getContextClassLoader(),
          jdbcDriver,
          jdbcUrl,
          dbUserName,
          dbPassword);
  ds.setPoolTimeToWait(POOL_TIME_TO_WAIT);
  ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly

  return ds;
}
 
Example 3
Source File: PooledDataSourceTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  try {
    runScript(ds, JPETSTORE_DDL);
    ds.setDefaultAutoCommit(false);
    ds.setDriverProperties(new Properties() {
      {
        setProperty("username", "sa");
        setProperty("password", "");
      }
    });
    ds.setPoolMaximumActiveConnections(3);
    ds.setPoolMaximumIdleConnections(2);
    ds.setPoolMaximumCheckoutTime(10000);
    ds.setPoolPingConnectionsNotUsedFor(1);
    ds.setPoolPingEnabled(true);
    ds.setPoolPingQuery("SELECT * FROM PRODUCT");
    ds.setPoolTimeToWait(10000);
    ds.setLogWriter(null);
    List<Connection> connections = new ArrayList<Connection>();
    for (int i = 0; i < 3; i++) {
      connections.add(ds.getConnection());
    }
    assertEquals(3, ds.getPoolState().getActiveConnectionCount());
    for (Connection c : connections) {
      c.close();
    }
    assertEquals(2, ds.getPoolState().getIdleConnectionCount());
    assertEquals(4, ds.getPoolState().getRequestCount());
    assertEquals(0, ds.getPoolState().getBadConnectionCount());
    assertEquals(0, ds.getPoolState().getHadToWaitCount());
    assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime());
    assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount());
    assertEquals(0, ds.getPoolState().getAverageWaitTime());
    assertNotNull(ds.getPoolState().toString());
  } finally {
    ds.forceCloseAll();
  }
}
 
Example 4
Source File: PooledDataSourceTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  try {
    runScript(ds, JPETSTORE_DDL);
    ds.setDefaultAutoCommit(false);
    ds.setDriverProperties(new Properties() {
      {
        setProperty("username", "sa");
        setProperty("password", "");
      }
    });
    ds.setPoolMaximumActiveConnections(3);
    ds.setPoolMaximumIdleConnections(2);
    ds.setPoolMaximumCheckoutTime(10000);
    ds.setPoolPingConnectionsNotUsedFor(1);
    ds.setPoolPingEnabled(true);
    ds.setPoolPingQuery("SELECT * FROM PRODUCT");
    ds.setPoolTimeToWait(10000);
    ds.setLogWriter(null);
    List<Connection> connections = new ArrayList<Connection>();
    for (int i = 0; i < 3; i++) {
      connections.add(ds.getConnection());
    }
    assertEquals(3, ds.getPoolState().getActiveConnectionCount());
    for (Connection c : connections) {
      c.close();
    }
    assertEquals(2, ds.getPoolState().getIdleConnectionCount());
    assertEquals(4, ds.getPoolState().getRequestCount());
    assertEquals(0, ds.getPoolState().getBadConnectionCount());
    assertEquals(0, ds.getPoolState().getHadToWaitCount());
    assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime());
    assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount());
    assertEquals(0, ds.getPoolState().getAverageWaitTime());
    assertNotNull(ds.getPoolState().toString());
  } finally {
    ds.forceCloseAll();
  }
}