Java Code Examples for com.zaxxer.hikari.HikariConfig#setPassword()
The following examples show how to use
com.zaxxer.hikari.HikariConfig#setPassword() .
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: HikariDataSourceHelper.java From freeacs with MIT License | 8 votes |
public static DataSource dataSource(Config config) { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(config.getString("datasource.driverClassName")); hikariConfig.setJdbcUrl(config.getString("datasource.jdbcUrl")); hikariConfig.setUsername(config.getString("datasource.username")); hikariConfig.setPassword(config.getString("datasource.password")); hikariConfig.setMinimumIdle(config.getInt("datasource.minimum-idle")); hikariConfig.setMaximumPoolSize(config.getInt("datasource.maximum-pool-size")); hikariConfig.setConnectionTestQuery("SELECT 1"); hikariConfig.setPoolName(config.getString("datasource.poolName")); hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048"); hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true"); hikariConfig.setAutoCommit(true); return new HikariDataSource(hikariConfig); }
Example 2
Source File: SagaPersistenceLoader.java From opensharding-spi-impl with Apache License 2.0 | 6 votes |
private static DataSource initDataSource(final SagaPersistenceConfiguration persistenceConfiguration) { HikariConfig config = new HikariConfig(); config.setJdbcUrl(persistenceConfiguration.getUrl()); config.setUsername(persistenceConfiguration.getUsername()); config.setPassword(persistenceConfiguration.getPassword()); config.setConnectionTimeout(persistenceConfiguration.getConnectionTimeoutMilliseconds()); config.setIdleTimeout(persistenceConfiguration.getIdleTimeoutMilliseconds()); config.setMaxLifetime(persistenceConfiguration.getMaxLifetimeMilliseconds()); config.setMaximumPoolSize(persistenceConfiguration.getMaxPoolSize()); config.setMinimumIdle(persistenceConfiguration.getMinPoolSize()); config.addDataSourceProperty("useServerPrepStmts", Boolean.TRUE.toString()); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", 250); config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); config.addDataSourceProperty("useLocalSessionState", Boolean.TRUE.toString()); config.addDataSourceProperty("rewriteBatchedStatements", Boolean.TRUE.toString()); config.addDataSourceProperty("cacheResultSetMetadata", Boolean.TRUE.toString()); config.addDataSourceProperty("cacheServerConfiguration", Boolean.TRUE.toString()); config.addDataSourceProperty("elideSetAutoCommits", Boolean.TRUE.toString()); config.addDataSourceProperty("maintainTimeStats", Boolean.FALSE.toString()); config.addDataSourceProperty("netTimeoutForStreamingResults", 0); return new HikariDataSource(config); }
Example 3
Source File: DatabaseConfiguration.java From todo-spring-angular with MIT License | 6 votes |
@Bean(destroyMethod = "close") public DataSource dataSource() { log.debug("Configuring Datasource"); if (dataSourcePropertyResolver.getProperty("url") == 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 hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName")); hikariConfig.setJdbcUrl(dataSourcePropertyResolver.getProperty("url")); hikariConfig.setUsername(dataSourcePropertyResolver.getProperty("username")); hikariConfig.setPassword(dataSourcePropertyResolver.getProperty("password")); return new HikariDataSource(hikariConfig); }
Example 4
Source File: ConfigBasedDbProvider.java From webtau with Apache License 2.0 | 6 votes |
@Override public DataSource provide(String name) { if (!name.equals("primary") || !DbConfig.isSet()) { return null; } HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setJdbcUrl(DbConfig.getDbPrimaryUrl()); hikariConfig.setUsername(DbConfig.getDbPrimaryUserName()); hikariConfig.setPassword(DbConfig.getDbPrimaryPassword()); if (!DbConfig.getDbPrimaryDriverClassName().isEmpty()) { hikariConfig.setDriverClassName(DbConfig.getDbPrimaryDriverClassName()); } return new HikariDataSource(hikariConfig); }
Example 5
Source File: HikariCPPlugin.java From jfinal-api-scaffold with MIT License | 6 votes |
@Override public boolean start() { HikariConfig config = new HikariConfig(); config.setMaximumPoolSize(maxPoolSize); // config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); config.setDriverClassName(driverClass); config.setJdbcUrl(jdbcUrl); config.setUsername(user); config.setPassword(password); //防止中文乱码 config.addDataSourceProperty("useUnicode", "true"); config.addDataSourceProperty("characterEncoding", "utf8"); config.setConnectionTestQuery("SELECT 1"); this.dataSource = new HikariDataSource(config); return true; }
Example 6
Source File: DataSourceConfig.java From freeacs with MIT License | 6 votes |
@Bean public DataSource getDataSource(Environment config) { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(config.getProperty("main.datasource.driverClassName")); hikariConfig.setJdbcUrl(config.getProperty("main.datasource.jdbcUrl")); hikariConfig.setUsername(config.getProperty("main.datasource.username")); hikariConfig.setPassword(config.getProperty("main.datasource.password")); hikariConfig.setMinimumIdle(config.getProperty("main.datasource.minimum-idle", Integer.class, 1)); hikariConfig.setMaximumPoolSize(config.getProperty("main.datasource.maximum-pool-size", Integer.class, 10)); hikariConfig.setConnectionTestQuery("SELECT 1"); hikariConfig.setPoolName(config.getProperty("main.datasource.poolName")); hikariConfig.addDataSourceProperty("dataSource.cachePrepStmts", "true"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSize", "250"); hikariConfig.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048"); hikariConfig.addDataSourceProperty("dataSource.useServerPrepStmts", "true"); hikariConfig.setAutoCommit(true); return new HikariDataSource(hikariConfig); }
Example 7
Source File: DefaultDataSourceConfig.java From blog with MIT License | 6 votes |
@Primary @Bean(destroyMethod = "close", name = "dataSource") public DataSource dataSource() throws Exception { String jdbcUrl = new StringBuilder("jdbc:mysql://localhost:3306/") .append(dataSourceDo.getDatabaseName()).toString(); HikariConfig config = new HikariConfig(); config.setDriverClassName("com.mysql.cj.jdbc.Driver"); config.setJdbcUrl(jdbcUrl); config.setUsername(dataSourceDo.getMysqlUserName()); config.setPassword(dataSourceDo.getMysqlPassage()); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.setIdleTimeout(25000); config.setMinimumIdle(5); config.setMaximumPoolSize(30); config.setPoolName("db_pool_blog"); HikariDataSource ds = new HikariDataSource(config); return ds; }
Example 8
Source File: Server.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DataSource createPostgresDataSource() throws ClassNotFoundException { Class.forName("org.postgresql.Driver"); HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:postgresql://tfb-database:5432/hello_world"); config.setUsername("benchmarkdbuser"); config.setPassword("benchmarkdbpass"); config.setMaximumPoolSize(64); return new HikariDataSource(config); }
Example 9
Source File: Main.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
private static DataSource getDataSource(BrokerCommonConfiguration.DataSourceConfiguration dataSourceConfiguration) { HikariConfig config = new HikariConfig(); config.setJdbcUrl(dataSourceConfiguration.getUrl()); config.setUsername(dataSourceConfiguration.getUser()); config.setPassword(dataSourceConfiguration.getPassword()); config.setAutoCommit(false); return new HikariDataSource(config); }
Example 10
Source File: SqlConnectionPool.java From luna with MIT License | 5 votes |
/** * Creates a new connection pool. * * @return The new pool. * @throws SQLException If the pool cannot be created. */ public SqlConnectionPool build() throws SQLException { HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://" + HOST + ":" + PORT + "/" + database + ""); config.setUsername(USERNAME); config.setPassword(PASSWORD); config.setPoolName(poolName); return new SqlConnectionPool(new HikariDataSource(config)); }
Example 11
Source File: Server.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static DataSource createPostgresDataSource() throws ClassNotFoundException { Class.forName("org.postgresql.Driver"); HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:postgresql://tfb-database:5432/hello_world"); config.setUsername("benchmarkdbuser"); config.setPassword("benchmarkdbpass"); config.setMaximumPoolSize(512); return new HikariDataSource(config); }
Example 12
Source File: ReportingDBManager.java From blynk-server with GNU General Public License v3.0 | 5 votes |
private HikariConfig initConfig(BaseProperties serverProperties) { HikariConfig config = new HikariConfig(); config.setJdbcUrl(serverProperties.getProperty("reporting.jdbc.url")); config.setUsername(serverProperties.getProperty("reporting.user")); config.setPassword(serverProperties.getProperty("reporting.password")); config.setAutoCommit(false); config.setConnectionTimeout(serverProperties.getLongProperty("reporting.connection.timeout.millis")); config.setMaximumPoolSize(5); config.setMaxLifetime(0); config.setConnectionTestQuery("SELECT 1"); return config; }
Example 13
Source File: MysqlSchemaRepositoryIT.java From datacollector with Apache License 2.0 | 5 votes |
@BeforeClass public static void connect() throws Exception { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setJdbcUrl(mysql.getJdbcUrl()); hikariConfig.setUsername(mysql.getUsername()); hikariConfig.setPassword(mysql.getPassword()); hikariConfig.addDataSourceProperty("useSSL", false); hikariConfig.setAutoCommit(false); ds = new HikariDataSource(hikariConfig); Utils.runInitScript("schema.sql", ds); }
Example 14
Source File: Utils.java From Rulette with Apache License 2.0 | 5 votes |
/** * This method build a {@link HikariConfig} object from the given properties file. * @param props An {@link Properties} object encapsulating Hikari properties */ public static HikariConfig getHikariConfig(Properties props) { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(props.getProperty(PROPERTY_MYSQL_DRIVER_CLASS)); hikariConfig.setJdbcUrl(props.getProperty(PROPERTY_JDBC_URL)); hikariConfig.setUsername(props.getProperty(PROPERTY_USER_NAME)); hikariConfig.setPassword(props.getProperty(PROPERTY_PASSWORD)); hikariConfig.setMaximumPoolSize(Integer.parseInt(props.getProperty(PROPERTY_MAX_POOL_SIZE))); hikariConfig.setConnectionTimeout(Long.parseLong(props.getProperty(PROPERTY_CONN_TIMEOUT))); return hikariConfig; }
Example 15
Source File: HikariFactory.java From rapidoid with Apache License 2.0 | 5 votes |
public static DataSource createDataSourceFor(JdbcClient jdbc) { HikariConfig config = new HikariConfig(); config.setJdbcUrl(jdbc.url()); config.setUsername(jdbc.username()); config.setPassword(jdbc.password()); config.setDriverClassName(jdbc.driver()); Conf.HIKARI.applyTo(config); return new HikariDataSource(config); }
Example 16
Source File: TestMysqlSchemaRepositoryIT.java From datacollector with Apache License 2.0 | 5 votes |
@BeforeClass public static void connect() throws Exception { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setJdbcUrl(mysql.getJdbcUrl()); hikariConfig.setUsername(mysql.getUsername()); hikariConfig.setPassword(mysql.getPassword()); hikariConfig.setAutoCommit(false); ds = new HikariDataSource(hikariConfig); Utils.runInitScript("schema.sql", ds); }
Example 17
Source File: DataSourceUtil.java From shardingsphere with Apache License 2.0 | 5 votes |
private static DataSource createHikariCP(final DatabaseType databaseType, final String dataSourceName) { HikariConfig result = new HikariConfig(); DatabaseEnvironment databaseEnvironment = IntegrateTestEnvironment.getInstance().getDatabaseEnvironments().get(databaseType); result.setDriverClassName(databaseEnvironment.getDriverClassName()); result.setJdbcUrl(null == dataSourceName ? databaseEnvironment.getURL() : databaseEnvironment.getURL(dataSourceName)); result.setUsername(databaseEnvironment.getUsername()); result.setPassword(databaseEnvironment.getPassword()); result.setMaximumPoolSize(2); result.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); result.setConnectionTestQuery("SELECT 1"); if ("Oracle".equals(databaseType.getName())) { result.setConnectionInitSql("ALTER SESSION SET CURRENT_SCHEMA = " + dataSourceName); } return new HikariDataSource(result); }
Example 18
Source File: Tools.java From flowchat with GNU General Public License v3.0 | 5 votes |
public static final HikariConfig hikariConfig() { HikariConfig hc = new HikariConfig(); DataSources.PROPERTIES = Tools.loadProperties(DataSources.PROPERTIES_FILE); hc.setJdbcUrl(DataSources.PROPERTIES.getProperty("jdbc.url")); hc.setUsername(DataSources.PROPERTIES.getProperty("jdbc.username")); hc.setPassword(DataSources.PROPERTIES.getProperty("jdbc.password")); hc.setMaximumPoolSize(10); return hc; }
Example 19
Source File: AbstractMysqlSource.java From datacollector with Apache License 2.0 | 5 votes |
protected static HikariDataSource connect() { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setJdbcUrl(getJdbcUrl()); hikariConfig.setUsername("root"); hikariConfig.setPassword(MYSQL_PASSWORD); hikariConfig.addDataSourceProperty("useSSL", false); hikariConfig.setAutoCommit(false); return new HikariDataSource(hikariConfig); }
Example 20
Source File: ConnectionPoolContextListener.java From java-docs-samples with Apache License 2.0 | 4 votes |
@SuppressFBWarnings( value = "USBR_UNNECESSARY_STORE_BEFORE_RETURN", justification = "Necessary for sample region tag.") private DataSource createConnectionPool() { // [START cloud_sql_postgres_servlet_create] // The configuration object specifies behaviors for the connection pool. HikariConfig config = new HikariConfig(); // Configure which instance and what database user to connect with. config.setJdbcUrl(String.format("jdbc:postgresql:///%s", DB_NAME)); config.setUsername(DB_USER); // e.g. "root", "postgres" config.setPassword(DB_PASS); // e.g. "my-password" // For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections. // See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details. config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory"); config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME); // ... Specify additional connection properties here. // [START_EXCLUDE] // [START cloud_sql_postgres_servlet_limit] // maximumPoolSize limits the total number of concurrent connections this pool will keep. Ideal // values for this setting are highly variable on app design, infrastructure, and database. config.setMaximumPoolSize(5); // minimumIdle is the minimum number of idle connections Hikari maintains in the pool. // Additional connections will be established to meet this value unless the pool is full. config.setMinimumIdle(5); // [END cloud_sql_postgres_servlet_limit] // [START cloud_sql_postgres_servlet_timeout] // setConnectionTimeout is the maximum number of milliseconds to wait for a connection checkout. // Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an // SQLException. config.setConnectionTimeout(10000); // 10 seconds // idleTimeout is the maximum amount of time a connection can sit in the pool. Connections that // sit idle for this many milliseconds are retried if minimumIdle is exceeded. config.setIdleTimeout(600000); // 10 minutes // [END cloud_sql_postgres_servlet_timeout] // [START cloud_sql_postgres_servlet_backoff] // Hikari automatically delays between failed connection attempts, eventually reaching a // maximum delay of `connectionTimeout / 2` between attempts. // [END cloud_sql_postgres_servlet_backoff] // [START cloud_sql_postgres_servlet_lifetime] // maxLifetime is the maximum possible lifetime of a connection in the pool. Connections that // live longer than this many milliseconds will be closed and reestablished between uses. This // value should be several minutes shorter than the database's timeout value to avoid unexpected // terminations. config.setMaxLifetime(1800000); // 30 minutes // [END cloud_sql_postgres_servlet_lifetime] // [END_EXCLUDE] // Initialize the connection pool using the configuration object. DataSource pool = new HikariDataSource(config); // [END cloud_sql_postgres_servlet_create] return pool; }