use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class ShutdownTest method testShutdownDuringInit.
@Test
public void testShutdownDuringInit() throws Exception {
final HikariConfig config = newHikariConfig();
config.setMinimumIdle(5);
config.setMaximumPoolSize(5);
config.setConnectionTimeout(1000);
config.setValidationTimeout(1000);
config.setInitializationFailTimeout(0);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
StubConnection.slowCreate = true;
UtilityElf.quietlySleep(3000L);
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestProxies method testProxyCreation.
@Test
public void testProxyCreation() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(0);
config.setMaximumPoolSize(1);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
Connection conn = ds.getConnection();
assertNotNull(conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
assertNotNull(conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
assertNotNull(conn.prepareCall("some sql"));
assertNotNull(conn.prepareCall("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
assertNotNull(conn.prepareCall("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
assertNotNull(conn.prepareStatement("some sql", PreparedStatement.NO_GENERATED_KEYS));
assertNotNull(conn.prepareStatement("some sql", new int[3]));
assertNotNull(conn.prepareStatement("some sql", new String[3]));
assertNotNull(conn.prepareStatement("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
assertNotNull(conn.prepareStatement("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
assertNotNull(conn.toString());
assertTrue(conn.isWrapperFor(Connection.class));
assertTrue(conn.isValid(10));
assertFalse(conn.isClosed());
assertTrue(conn.unwrap(StubConnection.class) instanceof StubConnection);
try {
conn.unwrap(TestProxies.class);
fail();
} catch (SQLException e) {
// pass
}
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestProxies method testStatementProxy.
@Test
public void testStatementProxy() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(0);
config.setMaximumPoolSize(1);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
Connection conn = ds.getConnection();
PreparedStatement stmt = conn.prepareStatement("some sql");
stmt.executeQuery();
stmt.executeQuery("some sql");
assertFalse(stmt.isClosed());
assertNotNull(stmt.getGeneratedKeys());
assertNotNull(stmt.getResultSet());
assertNotNull(stmt.getConnection());
assertTrue(stmt.unwrap(StubStatement.class) instanceof StubStatement);
try {
stmt.unwrap(TestProxies.class);
fail();
} catch (SQLException e) {
// pass
}
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class HikariConnectionProvider method configure.
// *************************************************************************
// Configurable
// *************************************************************************
@SuppressWarnings("rawtypes")
@Override
public void configure(Map props) throws HibernateException {
try {
LOGGER.debug("Configuring HikariCP");
this.hcfg = HikariConfigurationUtil.loadConfiguration(props);
this.hds = new HikariDataSource(this.hcfg);
} catch (Exception e) {
throw new HibernateException(e);
}
LOGGER.debug("HikariCP Configured");
}
use of com.zaxxer.hikari.HikariDataSource in project jphp by jphp-compiler.
the class PSqlDriverManager method getPool.
@Signature
public static PSqlConnectionPool getPool(Environment env, String url, String driverName, @Nullable Properties properties) throws SQLException {
HikariConfig config = new HikariConfig(properties == null ? new Properties() : properties);
if (config.getDataSourceClassName() == null) {
config.setDataSourceClassName(dataSourceClasses.get(driverName));
}
HikariDataSource pool = new HikariDataSource(config);
pool.setDriverClassName(_getDriverClass(driverName));
pool.setJdbcUrl("jdbc:" + url);
return new PSqlConnectionPool(env, pool);
}
Aggregations