Java Code Examples for com.zaxxer.hikari.HikariConfig#setDataSourceClassName()
The following examples show how to use
com.zaxxer.hikari.HikariConfig#setDataSourceClassName() .
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: AbstractEmbeddedDataSourceHelper.java From freeacs with MIT License | 8 votes |
public static void setUpBeforeClass() throws ManagedProcessException { randomFolder = "./db/" + UUID.randomUUID(); DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder(); configBuilder.setPort(3307); configBuilder.setDataDir(randomFolder); db = DB.newEmbeddedDB(configBuilder.build()); db.start(); db.createDB("acs", "acs", "acs"); db.source("install.sql", "acs", "acs", "acs"); String url = configBuilder.getURL("acs"); HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDataSourceClassName("org.mariadb.jdbc.MariaDbDataSource"); hikariConfig.addDataSourceProperty("url", url); hikariConfig.addDataSourceProperty("user", "acs"); hikariConfig.addDataSourceProperty("password", "acs"); dataSource = new HikariDataSource(hikariConfig); }
Example 2
Source File: JDBCZuulFilterDaoBuilder.java From s2g-zuul with MIT License | 6 votes |
public JDBCZuulFilterDaoBuilder() { HikariConfig config = new HikariConfig(); config.setDataSourceClassName(dataSourceClass.get()); config.addDataSourceProperty("url", url.get()); config.addDataSourceProperty("user", user.get()); config.addDataSourceProperty("password", password.get()); config.setMinimumPoolSize(minPoolSize.get()); config.setMaximumPoolSize(maxPoolSize.get()); config.setConnectionTimeout(connectionTimeout.get()); config.setIdleTimeout(idleTimeout.get()); config.setMaxLifetime(maxLifetime.get()); this.dataSource = new HikariDataSource(config); this.filterTable = filterTableName.get(); //+ "_" + environment.get(); }
Example 3
Source File: MySqlIntegrationTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Before public void initializeConnectionAndTable() throws SQLException { HikariConfig config = new HikariConfig(); config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource"); config.setConnectionTestQuery("VALUES 1"); // Note "ignorecase=true": H2 does not support `COLLATE NOCASE` for case-insensitive equals queries. // MySQL is by default case-insensitive so this is OK to make as an assumption. config.addDataSourceProperty("URL", "jdbc:h2:mem:test;ignorecase=true"); config.addDataSourceProperty("user", "sa"); config.addDataSourceProperty("password", "sa"); HikariDataSource ds = new HikariDataSource(config); Connection connection = ds.getConnection(); try (Statement st = connection.createStatement()) { st.execute("DROP TABLE IF EXISTS authme"); st.execute(sqlInitialize); } hikariSource = ds; }
Example 4
Source File: PostgreSqlIntegrationTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Before public void initializeConnectionAndTable() throws SQLException { HikariConfig config = new HikariConfig(); config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource"); config.setConnectionTestQuery("VALUES 1"); config.addDataSourceProperty("URL", "jdbc:h2:mem:test;ignorecase=true"); config.addDataSourceProperty("user", "sa"); config.addDataSourceProperty("password", "sa"); HikariDataSource ds = new HikariDataSource(config); Connection connection = ds.getConnection(); try (Statement st = connection.createStatement()) { st.execute("DROP TABLE IF EXISTS authme"); st.execute(sqlInitialize); } hikariSource = ds; }
Example 5
Source File: LoginSecurityConverterTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
private Connection initializeMySqlTable() throws IOException, SQLException { File sqlInitFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "datasource/converter/loginsecurity.sql"); String initStatement = new String(Files.readAllBytes(sqlInitFile.toPath())); HikariConfig config = new HikariConfig(); config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource"); config.setConnectionTestQuery("VALUES 1"); config.addDataSourceProperty("URL", "jdbc:h2:mem:test"); config.addDataSourceProperty("user", "sa"); config.addDataSourceProperty("password", "sa"); HikariDataSource ds = new HikariDataSource(config); Connection connection = ds.getConnection(); try (Statement st = connection.createStatement()) { st.execute("DROP TABLE IF EXISTS authme"); st.execute(initStatement); } return connection; }
Example 6
Source File: HikariCPPostgreSQLJPAConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
@Override public DataSource actualDataSource() { Properties dataSourceProperties = new Properties(); dataSourceProperties.setProperty("user", jdbcUser); dataSourceProperties.setProperty("password", jdbcPassword); dataSourceProperties.setProperty("databaseName", jdbcDatabase); dataSourceProperties.setProperty("serverName", jdbcHost); dataSourceProperties.setProperty("portNumber", jdbcPort); HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDataSourceClassName(dataSourceClassName); hikariConfig.setDataSourceProperties(dataSourceProperties); hikariConfig.setMinimumPoolSize(1); hikariConfig.setMaximumPoolSize(3); return new HikariDataSource(hikariConfig); }
Example 7
Source File: DatabaseConfiguration.java From ServiceCutter with Apache License 2.0 | 6 votes |
@Bean(destroyMethod = "close") @ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}") public DataSource dataSource() { log.debug("Configuring Datasource"); if (dataSourcePropertyResolver.getProperty("url") == null && dataSourcePropertyResolver.getProperty("databaseName") == null) { log.error("Your database connection pool configuration is incorrect! The application" + " cannot start. Please check your Spring profile, current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } HikariConfig config = new HikariConfig(); config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName")); if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) { config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName")); config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName")); } else { config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url")); } config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username")); config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password")); if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } return new HikariDataSource(config); }
Example 8
Source File: PostgreConnectionFactory.java From LuckPerms with MIT License | 6 votes |
@Override protected void appendConfigurationInfo(HikariConfig config) { String address = this.configuration.getAddress(); String[] addressSplit = address.split(":"); address = addressSplit[0]; String port = addressSplit.length > 1 ? addressSplit[1] : "5432"; String database = this.configuration.getDatabase(); String username = this.configuration.getUsername(); String password = this.configuration.getPassword(); config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource"); config.addDataSourceProperty("serverName", address); config.addDataSourceProperty("portNumber", port); config.addDataSourceProperty("databaseName", database); config.addDataSourceProperty("user", username); config.addDataSourceProperty("password", password); }
Example 9
Source File: HelperSql.java From helper with MIT License | 6 votes |
public HelperSql(@Nonnull DatabaseCredentials credentials) { final HikariConfig hikari = new HikariConfig(); hikari.setPoolName("helper-sql-" + POOL_COUNTER.getAndIncrement()); hikari.setDataSourceClassName(DATA_SOURCE_CLASS); hikari.addDataSourceProperty("serverName", credentials.getAddress()); hikari.addDataSourceProperty("port", credentials.getPort()); hikari.addDataSourceProperty("databaseName", credentials.getDatabase()); hikari.setUsername(credentials.getUsername()); hikari.setPassword(credentials.getPassword()); hikari.setMaximumPoolSize(MAXIMUM_POOL_SIZE); hikari.setMinimumIdle(MINIMUM_IDLE); hikari.setMaxLifetime(MAX_LIFETIME); hikari.setConnectionTimeout(CONNECTION_TIMEOUT); hikari.setLeakDetectionThreshold(LEAK_DETECTION_THRESHOLD); // ensure we use unicode (this calls #setProperties, a hack for the mariadb driver) hikari.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8"); this.source = new HikariDataSource(hikari); this.stream = SqlStream.connect(this.source); }
Example 10
Source File: DatabaseConfig.java From spring-boot-react-blog with Apache License 2.0 | 6 votes |
@Bean(destroyMethod = "close") public HikariDataSource dataSource(DataSourceProperties dataSourceProperties, ApplicationProperties applicationProperties) { log.debug("Configuring Datasource"); HikariConfig config = new HikariConfig(); config.setDataSourceClassName(dataSourceProperties.getDriverClassName()); config.addDataSourceProperty("url", dataSourceProperties.getUrl()); if (dataSourceProperties.getUsername() != null) { config.addDataSourceProperty("user", dataSourceProperties.getUsername()); } else { config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user } if (dataSourceProperties.getPassword() != null) { config.addDataSourceProperty("password", dataSourceProperties.getPassword()); } else { config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password } return new HikariDataSource(config); }
Example 11
Source File: DatabaseConfiguration.java From angularjs-springboot-bookstore with MIT License | 5 votes |
@Bean(destroyMethod = "shutdown") @ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}") public DataSource dataSource() { log.debug("Configuring Datasource"); if (dataSourcePropertyResolver.getProperty("url") == null && dataSourcePropertyResolver.getProperty("databaseName") == null) { log.error("Your database connection pool configuration is incorrect! The application" + " cannot start. Please check your Spring profile, current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } HikariConfig config = new HikariConfig(); config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName")); if(StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) { config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName")); config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName")); } else { config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url")); } config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username")); config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password")); if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } return new HikariDataSource(config); }
Example 12
Source File: DatabaseConfiguration.java From expper with GNU General Public License v3.0 | 5 votes |
@Bean(destroyMethod = "close") @ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}") public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) { log.debug("Configuring Datasource"); if (dataSourceProperties.getUrl() == null) { log.error("Your database connection pool configuration is incorrect! The application" + " cannot start. Please check your Spring profile, current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } HikariConfig config = new HikariConfig(); config.setDataSourceClassName(dataSourceProperties.getDriverClassName()); config.addDataSourceProperty("url", dataSourceProperties.getUrl()); if (dataSourceProperties.getUsername() != null) { config.addDataSourceProperty("user", dataSourceProperties.getUsername()); } else { config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user } if (dataSourceProperties.getPassword() != null) { config.addDataSourceProperty("password", dataSourceProperties.getPassword()); } else { config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password } if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } return new HikariDataSource(config); }
Example 13
Source File: HikariCpJDK7IT.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void defaultTest1() throws InterruptedException, SQLException, NoSuchMethodException { final HikariConfig config = new HikariConfig(); config.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); config.addDataSourceProperty("url", JDBC_URL); HikariDataSource dataSource = new HikariDataSource(config); try { Connection connection = dataSource.getConnection(); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); Constructor<HikariDataSource> constructor = HikariDataSource.class.getConstructor(HikariConfig.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource(com.zaxxer.hikari.HikariConfig)")); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.pool.BaseHikariPool.BaseHikariPool(com.zaxxer.hikari.HikariConfig, java.lang.String, java.lang.String)")); verifier.verifyTrace(event(serviceType, getConnectionMethod1)); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }
Example 14
Source File: HikariCpIT.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void defaultTest1() throws InterruptedException, SQLException, NoSuchMethodException { final HikariConfig config = new HikariConfig(); config.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); config.addDataSourceProperty("url", JDBC_URL); HikariDataSource dataSource = new HikariDataSource(config); try { Connection connection = dataSource.getConnection(); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); Constructor<HikariDataSource> constructor = HikariDataSource.class.getConstructor(HikariConfig.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource(com.zaxxer.hikari.HikariConfig)")); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.pool.BaseHikariPool.BaseHikariPool(com.zaxxer.hikari.HikariConfig, java.lang.String, java.lang.String)")); verifier.verifyTrace(event(serviceType, getConnectionMethod1)); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }
Example 15
Source File: HikariConnectionFactory.java From LuckPerms with MIT License | 5 votes |
protected void appendConfigurationInfo(HikariConfig config) { String address = this.configuration.getAddress(); String[] addressSplit = address.split(":"); address = addressSplit[0]; String port = addressSplit.length > 1 ? addressSplit[1] : "3306"; config.setDataSourceClassName(getDriverClass()); config.addDataSourceProperty("serverName", address); config.addDataSourceProperty("port", port); config.addDataSourceProperty("databaseName", this.configuration.getDatabase()); config.setUsername(this.configuration.getUsername()); config.setPassword(this.configuration.getPassword()); }
Example 16
Source File: PSqlDriverManager.java From jphp with Apache License 2.0 | 5 votes |
@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); }
Example 17
Source File: HikariCPDataSourceProvider.java From vertx-jdbc-client with Apache License 2.0 | 4 votes |
@Override public DataSource getDataSource(JsonObject json) throws SQLException { final HikariConfig config = new HikariConfig(); for (Map.Entry<String, Object> entry : json) { switch (entry.getKey()) { case "dataSourceClassName": config.setDataSourceClassName((String) entry.getValue()); break; case "jdbcUrl": config.setJdbcUrl((String) entry.getValue()); break; case "username": config.setUsername((String) entry.getValue()); break; case "password": config.setPassword((String) entry.getValue()); break; case "autoCommit": config.setAutoCommit((Boolean) entry.getValue()); break; case "connectionTimeout": config.setConnectionTimeout(getLong(entry.getValue())); break; case "idleTimeout": config.setIdleTimeout(getLong(entry.getValue())); break; case "maxLifetime": config.setMaxLifetime(getLong(entry.getValue())); break; case "connectionTestQuery": config.setConnectionTestQuery((String) entry.getValue()); break; case "minimumIdle": config.setMinimumIdle((Integer) entry.getValue()); break; case "maximumPoolSize": config.setMaximumPoolSize((Integer) entry.getValue()); break; case "metricRegistry": throw new UnsupportedOperationException(entry.getKey()); case "healthCheckRegistry": throw new UnsupportedOperationException(entry.getKey()); case "poolName": config.setPoolName((String) entry.getValue()); break; case "isolationInternalQueries": config.setIsolateInternalQueries((Boolean) entry.getValue()); break; case "allowPoolSuspension": config.setAllowPoolSuspension((Boolean) entry.getValue()); break; case "readOnly": config.setReadOnly((Boolean) entry.getValue()); break; case "registerMBeans": config.setRegisterMbeans((Boolean) entry.getValue()); break; case "catalog": config.setCatalog((String) entry.getValue()); break; case "connectionInitSql": config.setConnectionInitSql((String) entry.getValue()); break; case "driverClassName": config.setDriverClassName((String) entry.getValue()); break; case "transactionIsolation": config.setTransactionIsolation((String) entry.getValue()); break; case "validationTimeout": config.setValidationTimeout(getLong(entry.getValue())); break; case "leakDetectionThreshold": config.setLeakDetectionThreshold(getLong(entry.getValue())); break; case "dataSource": throw new UnsupportedOperationException(entry.getKey()); case "threadFactory": throw new UnsupportedOperationException(entry.getKey()); case "datasource": // extension to support configuring datasource.* properties for (Map.Entry<String, Object> key : ((JsonObject) entry.getValue())) { config.addDataSourceProperty(key.getKey(), key.getValue()); } break; } } return new HikariDataSource(config); }