Java Code Examples for com.zaxxer.hikari.HikariDataSource#addDataSourceProperty()
The following examples show how to use
com.zaxxer.hikari.HikariDataSource#addDataSourceProperty() .
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: FastJdbc.java From litchi with Apache License 2.0 | 6 votes |
public void addJdbc(JSONObject config) { String dbType = config.getString("dbType"); String dbName = config.getString("dbName"); String host = config.getString("host"); String userName = config.getString("userName"); String password = config.getString("password"); // int initialSize = config.getInteger("initialSize"); // int maxActive = config.getInteger("maxActive"); // int maxIdle = config.getInteger("maxIdle"); // int minIdle = config.getInteger("minIdle"); HikariDataSource ds = new HikariDataSource(); String jdbc = "jdbc:mysql://%s/%s?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC"; ds.setJdbcUrl(String.format(jdbc, host, dbName)); ds.setUsername(userName); ds.setPassword(password); ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "500"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); QueryRunner queryRunner = new QueryRunner(ds); jdbcMaps.put(dbType, queryRunner); LOGGER.info("add jdbcId = {}", config.getString("id")); }
Example 2
Source File: DatabaseConfiguration.java From galeb with Apache License 2.0 | 6 votes |
@Bean public HikariDataSource dataSource(DataSourceProperties properties) { HikariDataSource hikariDataSource = (HikariDataSource) properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); hikariDataSource.setConnectionTimeout(DB_CONN_TIMEOUT); hikariDataSource.setMaximumPoolSize(DB_MAX_POOL_SIZE); hikariDataSource.setMaxLifetime(DB_MAX_LIFE_TIME); hikariDataSource.setAutoCommit(DB_AUTOCOMMIT); hikariDataSource.setConnectionTestQuery("SELECT 1"); hikariDataSource.addDataSourceProperty("cachePrepStmts", DB_CACHE_PREP_STMTS); hikariDataSource.addDataSourceProperty("prepStmtCacheSize", DB_PREP_STMT_CACHE_SIZE); hikariDataSource.addDataSourceProperty("prepStmtCacheSqlLimit", DB_PREP_STMT_CACHE_SQL_LIMIT); hikariDataSource.addDataSourceProperty("useServerPrepStmts", DB_USE_SERVER_PREP_STMTS); hikariDataSource.addDataSourceProperty("useLocalSessionState", DB_USE_LOCAL_SESSION_STATE); hikariDataSource.addDataSourceProperty("rewriteBatchedStatements", DB_REWRITE_BATCHED_STATEMENTS); hikariDataSource.addDataSourceProperty("cacheResultSetMetadata", DB_CACHE_RESULT_SET_METADATA); hikariDataSource.addDataSourceProperty("cacheServerConfiguration", DB_CACHE_SERVER_CONFIGURATION); hikariDataSource.addDataSourceProperty("elideSetAutoCommits", DB_ELIDE_SET_AUTO_COMMITS); hikariDataSource.addDataSourceProperty("maintainTimeStats", DB_MAINTAIN_TIME_STATS); return hikariDataSource; }
Example 3
Source File: PostgreSqlDataSource.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
/** * Sets up the connection arguments to the database. */ private void setConnectionArguments() { ds = new HikariDataSource(); ds.setPoolName("AuthMePostgreSQLPool"); // Pool Settings ds.setMaximumPoolSize(poolSize); ds.setMaxLifetime(maxLifetime * 1000); // Database URL ds.setDriverClassName("org.postgresql.Driver"); ds.setJdbcUrl("jdbc:postgresql://" + this.host + ":" + this.port + "/" + this.database); // Auth ds.setUsername(this.username); ds.setPassword(this.password); // Random stuff ds.addDataSourceProperty("reWriteBatchedInserts", "true"); // Caching ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("preparedStatementCacheQueries", "275"); logger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); }
Example 4
Source File: DatabaseConfig.java From NametagEdit with GNU General Public License v3.0 | 6 votes |
@Override public void load() { FileConfiguration config = handler.getConfig(); shutdown(); hikari = new HikariDataSource(); hikari.setMaximumPoolSize(config.getInt("MinimumPoolSize", 10)); hikari.setPoolName("NametagEdit Pool"); hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); hikari.addDataSourceProperty("useSSL", false); hikari.addDataSourceProperty("requireSSL", false); hikari.addDataSourceProperty("verifyServerCertificate", false); hikari.addDataSourceProperty("serverName", config.getString("MySQL.Hostname")); hikari.addDataSourceProperty("port", config.getString("MySQL.Port")); hikari.addDataSourceProperty("databaseName", config.getString("MySQL.Database")); hikari.addDataSourceProperty("user", config.getString("MySQL.Username")); hikari.addDataSourceProperty("password", config.getString("MySQL.Password")); new DatabaseUpdater(handler, hikari, plugin).runTaskAsynchronously(plugin); }
Example 5
Source File: MySQL.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Sets up the connection arguments to the database. */ private void setConnectionArguments() { ds = new HikariDataSource(); ds.setPoolName("AuthMeMYSQLPool"); // Pool Settings ds.setMaximumPoolSize(poolSize); ds.setMaxLifetime(maxLifetime * 1000); // Database URL ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); // Auth ds.setUsername(this.username); ds.setPassword(this.password); // Request mysql over SSL ds.addDataSourceProperty("useSSL", String.valueOf(useSsl)); // Disabling server certificate verification on need if (!serverCertificateVerification) { ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false)); } // Encoding ds.addDataSourceProperty("characterEncoding", "utf8"); ds.addDataSourceProperty("encoding", "UTF-8"); ds.addDataSourceProperty("useUnicode", "true"); // Random stuff ds.addDataSourceProperty("rewriteBatchedStatements", "true"); ds.addDataSourceProperty("jdbcCompliantTruncation", "false"); // Caching ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "275"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); logger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); }
Example 6
Source File: IntegrationTestSupport.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static JdbcTemplate jdbc(MySqlConnectionConfiguration configuration, @Nullable String timezone) { HikariDataSource source = new HikariDataSource(); source.setJdbcUrl(String.format("jdbc:mysql://%s:%d/%s", configuration.getDomain(), configuration.getPort(), configuration.getDatabase())); source.setUsername(configuration.getUser()); source.setPassword(Optional.ofNullable(configuration.getPassword()).map(Object::toString).orElse(null)); source.setMaximumPoolSize(1); source.setConnectionTimeout(Optional.ofNullable(configuration.getConnectTimeout()).map(Duration::toMillis).orElse(0L)); if (timezone != null) { source.addDataSourceProperty("serverTimezone", timezone); } return new JdbcTemplate(source); }
Example 7
Source File: MysqlStartupHookProvider.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
static void initDataSource() { MysqlConfig config = (MysqlConfig) Config.getInstance().getJsonObjectConfig(CONFIG_NAME, MysqlConfig.class); ds = new HikariDataSource(); ds.setJdbcUrl(config.getJdbcUrl()); ds.setUsername(config.getUsername()); ds.setPassword(config.getPassword()); ds.setMaximumPoolSize(config.getMaximumPoolSize()); ds.addDataSourceProperty("useServerPrepStmts", config.isUseServerPrepStmts()); ds.addDataSourceProperty("CachePrepStmts", config.isCachePrepStmts()); ds.addDataSourceProperty("CacheCallableStmts", config.isCacheCallableStmts()); ds.addDataSourceProperty("PrepStmtCacheSize", config.getPrepStmtCacheSize()); ds.addDataSourceProperty("PrepStmtCacheSqlLimit", config.getPrepStmtCacheSqlLimit()); }
Example 8
Source File: HikariCpIT.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void defaultTest3() throws InterruptedException, SQLException { HikariDataSource dataSource = new HikariDataSource(); dataSource.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); dataSource.addDataSourceProperty("url", JDBC_URL); try { Connection connection = dataSource.getConnection("", ""); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource()")); verifier.verifyTrace(event(serviceType, getConnectionMethod2, annotation(AnnotationKey.ARGS0.getName(), ""))); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }
Example 9
Source File: HikariCpIT.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void defaultTest2() throws InterruptedException, SQLException { HikariDataSource dataSource = new HikariDataSource(); dataSource.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); dataSource.addDataSourceProperty("url", JDBC_URL); try { Connection connection = dataSource.getConnection(); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource()")); verifier.verifyTrace(event(serviceType, getConnectionMethod1)); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.pool.BaseHikariPool.BaseHikariPool(com.zaxxer.hikari.HikariConfig, java.lang.String, java.lang.String)")); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }
Example 10
Source File: HikariCpJDK7IT.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void defaultTest3() throws InterruptedException, SQLException, NoSuchMethodException { HikariDataSource dataSource = new HikariDataSource(); dataSource.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); dataSource.addDataSourceProperty("url", JDBC_URL); try { Connection connection = dataSource.getConnection("", ""); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource()")); verifier.verifyTrace(event(serviceType, getConnectionMethod2, annotation(AnnotationKey.ARGS0.getName(), ""))); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }
Example 11
Source File: MySQLDbService.java From ecs-sync with Apache License 2.0 | 5 votes |
@Override protected JdbcTemplate createJdbcTemplate() { HikariDataSource ds = new HikariDataSource(); ds.setJdbcUrl(connectString); if (username != null) ds.setUsername(username); if (password != null) ds.setPassword(password); ds.setMaximumPoolSize(16); ds.setMinimumIdle(2); ds.addDataSourceProperty("characterEncoding", "utf8"); ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "256"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); ds.addDataSourceProperty("defaultFetchSize", "" + Integer.MIN_VALUE); return new JdbcTemplate(ds); }
Example 12
Source File: DataSourceHandler.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
/** * Constructor used for MySQL * * @param host * @param port * @param database * @param username * @param password * @throws SQLException */ public DataSourceHandler(final String host, final String port, final String database, final String username, final String password) throws SQLException{ // Check database's informations and init connection this.host = Preconditions.checkNotNull(host); this.port = Preconditions.checkNotNull(port); this.database = Preconditions.checkNotNull(database); this.username = Preconditions.checkNotNull(username); this.password = Preconditions.checkNotNull(password); BAT.getInstance().getLogger().config("Initialization of HikariCP in progress ..."); BasicConfigurator.configure(new NullAppender()); ds = new HikariDataSource(); ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?useLegacyDatetimeCode=false&serverTimezone=" + TimeZone.getDefault().getID()); ds.setUsername(this.username); ds.setPassword(this.password); ds.addDataSourceProperty("cachePrepStmts", "true"); ds.setMaximumPoolSize(8); try { final Connection conn = ds.getConnection(); int intOffset = Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000; String offset = String.format("%02d:%02d", Math.abs(intOffset / 3600), Math.abs((intOffset / 60) % 60)); offset = (intOffset >= 0 ? "+" : "-") + offset; conn.createStatement().executeQuery("SET time_zone='" + offset + "';"); conn.close(); BAT.getInstance().getLogger().config("BoneCP is loaded !"); } catch (final SQLException e) { BAT.getInstance().getLogger().severe("BAT encounters a problem during the initialization of the database connection." + " Please check your logins and database configuration."); if(e.getCause() instanceof CommunicationsException){ BAT.getInstance().getLogger().severe(e.getCause().getMessage()); } if(BAT.getInstance().getConfiguration().isDebugMode()){ BAT.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e); } throw e; } sqlite = false; }
Example 13
Source File: DatabaseConfig.java From spring-security-jwt-rest-stateless with MIT License | 5 votes |
@Bean public HikariDataSource getDataSource(){ HikariDataSource dataSource = new HikariDataSource(); dataSource.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); dataSource.addDataSourceProperty("databaseName", "demorest"); dataSource.addDataSourceProperty("portNumber", "3306"); dataSource.addDataSourceProperty("serverName", "127.0.0.1"); dataSource.addDataSourceProperty("user", "root"); dataSource.addDataSourceProperty("password", ""); return dataSource; }
Example 14
Source File: SampleSpringApplication.java From SpringBootMultiTenancy with MIT License | 5 votes |
public DataSource tenantTwo() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setInitializationFailTimeout(0); dataSource.setMaximumPoolSize(5); dataSource.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource"); dataSource.addDataSourceProperty("url", "jdbc:postgresql://127.0.0.1:5432/sampledb2"); dataSource.addDataSourceProperty("user", "philipp"); dataSource.addDataSourceProperty("password", "test_pwd"); return dataSource; }
Example 15
Source File: SampleSpringApplication.java From SpringBootMultiTenancy with MIT License | 5 votes |
public DataSource tenantOne() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setInitializationFailTimeout(0); dataSource.setMaximumPoolSize(5); dataSource.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource"); dataSource.addDataSourceProperty("url", "jdbc:postgresql://127.0.0.1:5432/sampledb"); dataSource.addDataSourceProperty("user", "philipp"); dataSource.addDataSourceProperty("password", "test_pwd"); return dataSource; }
Example 16
Source File: BatchProcessing.java From Java-11-Cookbook-Second-Edition with MIT License | 5 votes |
private static DataSource createDataSource() { HikariDataSource ds = new HikariDataSource(); ds.setPoolName("cookpool"); ds.setDriverClassName("org.postgresql.Driver"); ds.setJdbcUrl("jdbc:postgresql://localhost/cookbook"); ds.setUsername( "cook"); //ds.setPassword("123Secret"); ds.setMaximumPoolSize(2); ds.setMinimumIdle(2); ds.addDataSourceProperty("reWriteBatchedInserts", Boolean.TRUE); return ds; }
Example 17
Source File: HikariPool.java From Java-11-Cookbook-Second-Edition with MIT License | 5 votes |
private static DataSource createDataSource1() { HikariDataSource ds = new HikariDataSource(); ds.setPoolName("cookpool"); ds.setDriverClassName("org.postgresql.Driver"); ds.setJdbcUrl("jdbc:postgresql://localhost/cookbook"); ds.setUsername( "cook"); //ds.setPassword("123Secret"); ds.setMaximumPoolSize(10); ds.setMinimumIdle(2); ds.addDataSourceProperty("cachePrepStmts", Boolean.TRUE); ds.addDataSourceProperty("prepStmtCacheSize", 256); ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); ds.addDataSourceProperty("useServerPrepStmts", Boolean.TRUE); return ds; }
Example 18
Source File: IntegrationTestSupport.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static JdbcTemplate jdbc(MySqlConnectionConfiguration configuration, @Nullable String timezone) { HikariDataSource source = new HikariDataSource(); source.setJdbcUrl(String.format("jdbc:mysql://%s:%d/%s", configuration.getDomain(), configuration.getPort(), configuration.getDatabase())); source.setUsername(configuration.getUser()); source.setPassword(Optional.ofNullable(configuration.getPassword()).map(Object::toString).orElse(null)); source.setMaximumPoolSize(1); source.setConnectionTimeout(Optional.ofNullable(configuration.getConnectTimeout()).map(Duration::toMillis).orElse(0L)); if (timezone != null) { source.addDataSourceProperty("serverTimezone", timezone); } return new JdbcTemplate(source); }
Example 19
Source File: HikariCPProvider.java From tastjava with MIT License | 4 votes |
@Override public boolean register() { if (IsRegistered) { return HAS_REGISTERED; } HikariDataSource ds = new HikariDataSource(); //basic config ds.setJdbcUrl(jdbcURL); ds.setDriverClassName(jdbcDriver); ds.setUsername(jdbcUsername); ds.setPassword(jdbcPassword); //custom config ds.setAutoCommit(autoCommit); ds.setConnectionTimeout(connectionTimeout); ds.setIdleTimeout(idleTimeout); ds.setMaxLifetime(maxLifetime); ds.setMaximumPoolSize(maximumPoolSize); ds.setValidationTimeout(validationTimeout); ds.setLeakDetectionThreshold(leakDetectionThreshold); if (!StrUtil.isBlank(poolName)) { ds.setPoolName(poolName); } if (!StrUtil.isBlank(catalog)) { ds.setCatalog(catalog); } if (!StrUtil.isBlank(connectionInitSql)) { ds.setConnectionInitSql(connectionInitSql); } if (!StrUtil.isBlank(transactionIsolation)) { ds.setTransactionIsolation(transactionIsolation); } if (jdbcURL.contains(":mysql:")) { ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "250"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); ds.addDataSourceProperty("useServerPrepStmts", "true"); } setDataSource(ds); setIsRegistered(HAS_REGISTERED); return HAS_REGISTERED; }
Example 20
Source File: HikariCpJDK7IT.java From pinpoint with Apache License 2.0 | 4 votes |
@Test public void defaultTest2() throws InterruptedException, SQLException, NoSuchMethodException { HikariDataSource dataSource = new HikariDataSource(); dataSource.setDataSourceClassName(DATA_SOURCE_CLASS_NAME); dataSource.addDataSourceProperty("url", JDBC_URL); try { Connection connection = dataSource.getConnection(); Assert.assertNotNull(connection); Thread.sleep(500); connection.close(); Thread.sleep(500); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.HikariDataSource.HikariDataSource()")); verifier.verifyTrace(event(serviceType, getConnectionMethod1)); verifier.verifyTrace(event(serviceType, "com.zaxxer.hikari.pool.BaseHikariPool.BaseHikariPool(com.zaxxer.hikari.HikariConfig, java.lang.String, java.lang.String)")); verifier.verifyTrace(event(serviceType, proxyConnectionMethod)); } finally { if (dataSource != null) { dataSource.close(); } } }