use of com.zaxxer.hikari.util.DriverDataSource in project HikariCP by brettwooldridge.
the class JdbcDriverTest method driverTest1.
@Test
public void driverTest1() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setConnectionTestQuery("VALUES 1");
config.setDriverClassName("com.zaxxer.hikari.mocks.StubDriver");
config.setJdbcUrl("jdbc:stub");
config.addDataSourceProperty("user", "bart");
config.addDataSourceProperty("password", "simpson");
ds = new HikariDataSource(config);
assertTrue(ds.isWrapperFor(DriverDataSource.class));
DriverDataSource unwrap = ds.unwrap(DriverDataSource.class);
assertNotNull(unwrap);
try (Connection connection = ds.getConnection()) {
// test that getConnection() succeeds
}
}
use of com.zaxxer.hikari.util.DriverDataSource in project HikariCP by brettwooldridge.
the class PoolBase method initializeDataSource.
// ***********************************************************************
// Private methods
// ***********************************************************************
/**
* Create/initialize the underlying DataSource.
*/
private void initializeDataSource() {
final String jdbcUrl = config.getJdbcUrl();
final String username = config.getUsername();
final String password = config.getPassword();
final String dsClassName = config.getDataSourceClassName();
final String driverClassName = config.getDriverClassName();
final String dataSourceJNDI = config.getDataSourceJNDI();
final Properties dataSourceProperties = config.getDataSourceProperties();
DataSource dataSource = config.getDataSource();
if (dsClassName != null && dataSource == null) {
dataSource = createInstance(dsClassName, DataSource.class);
PropertyElf.setTargetFromProperties(dataSource, dataSourceProperties);
} else if (jdbcUrl != null && dataSource == null) {
dataSource = new DriverDataSource(jdbcUrl, driverClassName, dataSourceProperties, username, password);
} else if (dataSourceJNDI != null && dataSource == null) {
try {
InitialContext ic = new InitialContext();
dataSource = (DataSource) ic.lookup(dataSourceJNDI);
} catch (NamingException e) {
throw new PoolInitializationException(e);
}
}
if (dataSource != null) {
setLoginTimeout(dataSource);
createNetworkTimeoutExecutor(dataSource, dsClassName, jdbcUrl);
}
this.dataSource = dataSource;
}
Aggregations