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();
}
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();
}
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();
}
}
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;
}
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());
}
}
Aggregations