Java Code Examples for com.zaxxer.hikari.HikariDataSource#setPoolName()
The following examples show how to use
com.zaxxer.hikari.HikariDataSource#setPoolName() .
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: 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 2
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 3
Source File: ACSShell.java From freeacs with MIT License | 5 votes |
public static DataSource getHikariDataSource(String prefix) { HikariDataSource ds = new HikariDataSource(); String jdbcUrl = prefix + ".datasource.jdbcUrl"; ds.setJdbcUrl( Optional.ofNullable(System.getProperty(jdbcUrl)) .orElseGet(() -> Properties.pr.getProperty(jdbcUrl))); String className = prefix + ".datasource.driverClassName"; ds.setDriverClassName( Optional.ofNullable(System.getProperty(className)) .orElseGet(() -> Properties.pr.getProperty(className))); String user = prefix + ".datasource.username"; ds.setUsername( Optional.ofNullable(System.getProperty(user)) .orElseGet(() -> Properties.pr.getProperty(user))); String password = prefix + ".datasource.password"; ds.setPassword( Optional.ofNullable(System.getProperty(password)) .orElseGet(() -> Properties.pr.getProperty(password))); String poolSize = prefix + ".datasource.maximum-pool-size"; ds.setMaximumPoolSize( Integer.parseInt( Optional.ofNullable(System.getProperty(poolSize)) .orElseGet(() -> Properties.pr.getProperty(poolSize)))); String minimumIdle = prefix + ".datasource.minimum-idle"; ds.setMinimumIdle( Integer.parseInt( Optional.ofNullable(System.getProperty(minimumIdle)) .orElseGet(() -> Properties.pr.getProperty(minimumIdle)))); String poolName = prefix + ".datasource.poolName"; ds.setPoolName( Optional.ofNullable(System.getProperty(poolName)) .orElseGet(() -> Properties.pr.getProperty(poolName))); return ds; }
Example 4
Source File: PostgreSQLSourceConfig.java From Launcher with GNU General Public License v3.0 | 5 votes |
public synchronized Connection getConnection() throws SQLException { if (source == null) { // New data source PGSimpleDataSource postgresqlSource = new PGSimpleDataSource(); // Set credentials postgresqlSource.setServerNames(addresses); postgresqlSource.setPortNumbers(ports); postgresqlSource.setUser(username); postgresqlSource.setPassword(password); postgresqlSource.setDatabaseName(database); // Try using HikariCP source = postgresqlSource; //noinspection Duplicates try { Class.forName("com.zaxxer.hikari.HikariDataSource"); hikari = true; // Used for shutdown. Not instanceof because of possible classpath error // Set HikariCP pool HikariDataSource hikariSource = new HikariDataSource(); hikariSource.setDataSource(source); // Set pool settings hikariSource.setPoolName(poolName); hikariSource.setMinimumIdle(0); hikariSource.setMaximumPoolSize(MAX_POOL_SIZE); hikariSource.setIdleTimeout(TIMEOUT * 1000L); // Replace source with hds source = hikariSource; LogHelper.info("HikariCP pooling enabled for '%s'", poolName); } catch (ClassNotFoundException ignored) { LogHelper.warning("HikariCP isn't in classpath for '%s'", poolName); } } return source.getConnection(); }
Example 5
Source File: DataSourceManager.java From apollo-use-cases with Apache License 2.0 | 5 votes |
/** * create a hikari data source * @see org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.Hikari#dataSource */ public HikariDataSource createDataSource() { HikariDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); if (StringUtils.hasText(dataSourceProperties.getName())) { dataSource.setPoolName(dataSourceProperties.getName()); } Bindable<?> target = Bindable.of(HikariDataSource.class).withExistingValue(dataSource); this.binder.bind("spring.datasource.hikari", target); return dataSource; }
Example 6
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 7
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 8
Source File: TracingQueryExecutionListenerTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Bean public HikariDataSource test1() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:h2:mem:testdb-1-" + ThreadLocalRandom.current().nextInt()); dataSource.setPoolName("test1"); return dataSource; }
Example 9
Source File: TracingQueryExecutionListenerTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Bean public HikariDataSource test2() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:h2:mem:testdb-2-" + ThreadLocalRandom.current().nextInt()); dataSource.setPoolName("test2"); return dataSource; }
Example 10
Source File: DatabaseProvider.java From database with Apache License 2.0 | 5 votes |
public static Pool createPool(Config config) { String url = config.getString("database.url"); if (url == null) { throw new DatabaseException("You must provide database.url"); } HikariDataSource ds = new HikariDataSource(); // If we don't provide a pool name it will automatically generate one, but // the way it does that requires PropertyPermission("*", "read,write") and // will fail if the security sandbox is enabled ds.setPoolName(config.getString("database.pool.name", "HikariPool-" + poolNameCounter.getAndAdd(1))); ds.setJdbcUrl(url); String driverClassName = config.getString("database.driver.class", Flavor.driverForJdbcUrl(url)); ds.setDriverClassName(driverClassName); ds.setUsername(config.getString("database.user")); ds.setPassword(config.getString("database.password")); int poolSize = config.getInteger("database.pool.size", 10); ds.setMaximumPoolSize(poolSize); ds.setAutoCommit(false); Flavor flavor; String flavorString = config.getString("database.flavor"); if (flavorString != null) { flavor = Flavor.valueOf(flavorString); } else { flavor = Flavor.fromJdbcUrl(url); } log.debug("Created '" + flavor + "' connection pool of size " + poolSize + " using driver " + driverClassName); return new Pool(ds, poolSize, flavor, ds); }
Example 11
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 12
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; }