Search in sources :

Example 16 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.

the class PooledDataSourceTest method shouldNotFailCallingToStringOverAnInvalidConnection.

@Test
void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
    PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
    Connection c = ds.getConnection();
    c.close();
    c.toString();
}
Also used : Connection(java.sql.Connection) JDBCConnection(org.hsqldb.jdbc.JDBCConnection) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) Test(org.junit.jupiter.api.Test) BaseDataTest(org.apache.ibatis.BaseDataTest)

Example 17 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.

the class PooledDataSourceTest method ShouldReturnRealConnection.

@Test
void ShouldReturnRealConnection() throws Exception {
    PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
    Connection c = ds.getConnection();
    JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
    c.close();
}
Also used : Connection(java.sql.Connection) JDBCConnection(org.hsqldb.jdbc.JDBCConnection) JDBCConnection(org.hsqldb.jdbc.JDBCConnection) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) Test(org.junit.jupiter.api.Test) BaseDataTest(org.apache.ibatis.BaseDataTest)

Example 18 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.

the class ScriptRunnerTest method assertProductsTableExistsAndLoaded.

private void assertProductsTableExistsAndLoaded() throws IOException, SQLException {
    PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
    try (Connection conn = ds.getConnection()) {
        SqlRunner executor = new SqlRunner(conn);
        List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT");
        assertEquals(16, products.size());
    } finally {
        ds.forceCloseAll();
    }
}
Also used : Connection(java.sql.Connection) Map(java.util.Map) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource)

Example 19 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.

the class BaseDataTest method createPooledDataSource.

public static PooledDataSource createPooledDataSource(String resource) throws IOException {
    Properties props = Resources.getResourceAsProperties(resource);
    PooledDataSource ds = new PooledDataSource();
    ds.setDriver(props.getProperty("driver"));
    ds.setUrl(props.getProperty("url"));
    ds.setUsername(props.getProperty("username"));
    ds.setPassword(props.getProperty("password"));
    return ds;
}
Also used : Properties(java.util.Properties) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource)

Example 20 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.

the class NetworkTimeoutTest method testNetworkTimeout_PooledDataSource.

@Test
void testNetworkTimeout_PooledDataSource() throws Exception {
    UnpooledDataSource unpooledDataSource = (UnpooledDataSource) PgContainer.getUnpooledDataSource();
    PooledDataSource dataSource = new PooledDataSource(unpooledDataSource);
    dataSource.setDefaultNetworkTimeout(5000);
    try (Connection connection = dataSource.getConnection()) {
        assertEquals(5000, connection.getNetworkTimeout());
    }
}
Also used : Connection(java.sql.Connection) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) Test(org.junit.jupiter.api.Test)

Aggregations

PooledDataSource (org.apache.ibatis.datasource.pooled.PooledDataSource)20 Connection (java.sql.Connection)11 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)7 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)7 DataSource (javax.sql.DataSource)5 BaseDataTest (org.apache.ibatis.BaseDataTest)4 JDBCConnection (org.hsqldb.jdbc.JDBCConnection)4 Test (org.junit.Test)4 Test (org.junit.jupiter.api.Test)4 Properties (java.util.Properties)3 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 PoolState (org.apache.ibatis.datasource.pooled.PoolState)2 Configuration (org.apache.ibatis.session.Configuration)2 StandaloneInMemProcessEngineConfiguration (org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1