当前位置: 首页>>代码示例>>Java>>正文


Java HikariConfig.addDataSourceProperty方法代码示例

本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.addDataSourceProperty方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.addDataSourceProperty方法的具体用法?Java HikariConfig.addDataSourceProperty怎么用?Java HikariConfig.addDataSourceProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.zaxxer.hikari.HikariConfig的用法示例。


在下文中一共展示了HikariConfig.addDataSourceProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Database

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public Database() {
    try {
        Class.forName("org.mariadb.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(App.getConfig().getString("database.url"));
    config.setUsername(App.getConfig().getString("database.user"));
    config.setPassword(App.getConfig().getString("database.pass"));
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("allowMultiQueries", "true");
    config.setMaximumPoolSize(200); // this is plenty, the websocket uses 32

    dbi = new DBI(new HikariDataSource(config));
    

    getHandle().createPixelsTable();
    getHandle().createUsersTable();
    getHandle().createSessionsTable();
    getHandle().createAdminLogTable();
    getHandle().createReportsTable();
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:27,代码来源:Database.java

示例2: HikariWrapper

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariWrapper(@Nonnull DatabaseCredentials credentials) {
    HikariConfig config = new HikariConfig();

    config.setMaximumPoolSize(25);

    config.setPoolName("helper-sql-" + COUNTER.getAndIncrement());
    config.setDataSourceClassName("org.mariadb.jdbc.MySQLDataSource");
    config.addDataSourceProperty("serverName", credentials.getAddress());
    config.addDataSourceProperty("port", credentials.getPort());
    config.addDataSourceProperty("databaseName", credentials.getDatabase());
    config.setUsername(credentials.getUsername());
    config.setPassword(credentials.getPassword());

    // hack for the mariadb driver
    config.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8");

    // We will wait for 15 seconds to get a connection from the pool.
    // Default is 30, but it shouldn't be taking that long.
    config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000

    // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
    config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000

    hikari = new HikariDataSource(config);
}
 
开发者ID:lucko,项目名称:helper,代码行数:26,代码来源:HikariWrapper.java

示例3: MySQL

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public MySQL(Jecon jecon) {
	super.config = jecon.getConfigStruct();

	jecon.getLogger().info("Connect to MySQL.");

	HikariConfig hikariConfig = new HikariConfig();
	hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");

	// for Performance
	hikariConfig.addDataSourceProperty("cacheServerConfiguration", "true");
	hikariConfig.addDataSourceProperty("alwaysSendSetIsolation", "false");
	hikariConfig.addDataSourceProperty("useLocalSessionState", "true");
	hikariConfig.addDataSourceProperty("elideSetAutoCommits", "true");
	hikariConfig.addDataSourceProperty("maintainTimeStats", "false");
	hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
	hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
	hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

	super.setup(jecon, hikariConfig);
}
 
开发者ID:HimaJyun,项目名称:Jecon,代码行数:21,代码来源:MySQL.java

示例4: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userNames
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:29,代码来源:ExtensionHikariConnectionContext.java

示例5: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() {
    logger.debug("Configuring Datasource");
    String databaseUrl = String.format("jdbc:mysql://%s:%s/%s?%s",
            databaseHostname, databasePort, databaseSchema, databaseOptions);
    logger.info("database.url:" + databaseUrl);
    logger.info("database.user:" + databaseUser);
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("url", databaseUrl);
    config.addDataSourceProperty("user", databaseUser);
    config.setInitializationFailFast(false);
    config.setIdleTimeout(60000);
    String forcePassword = System.getenv("MYSQL_ROOT_PASSWORD");
    // coming from environnment host
    if (forcePassword != null) {
        logger.info("Force the mysql password from host env");
        databasePassword = forcePassword;
    }
    logger.info("URL : " + databaseUrl + " password : " + databasePassword);
    config.addDataSourceProperty("password", databasePassword);
    return new HikariDataSource(config);
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:24,代码来源:DatabaseConfiguration.java

示例6: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() {
    logger.debug("Configuring Datasource");
    String databaseUrl = String.format("jdbc:mysql://%s:%s/%s?%s",
            databaseHostname, databasePort, databaseSchema, databaseOptions);
    logger.debug("database.url:" + databaseUrl);
    logger.debug("database.user:" + databaseUser);
    HikariConfig config = new HikariConfig();

    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("url", databaseUrl);
    config.addDataSourceProperty("user", databaseUser);
    config.addDataSourceProperty("password", databasePassword);
    // config.setAutoCommit(false);
    return new HikariDataSource(config);
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:DatabaseConfigurationTest.java

示例7: createDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public DataSource createDataSource(DataSourceConfig dataSourceConfig) {

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(dataSourceConfig.getUrl());
    hikariConfig.setUsername(dataSourceConfig.getUser());
    hikariConfig.setPassword(dataSourceConfig.getPassword());
    hikariConfig.addDataSourceProperty("cachePrepStmts", dataSourceConfig.isCachePrepStmts());
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", dataSourceConfig.getPrepStmtCacheSize());
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", dataSourceConfig.getPrepStmtCacheSqlLimit());

    hikariConfig.setDriverClassName(dataSourceConfig.getDriverClassName());
    hikariConfig.setPoolName(dataSourceConfig.getPoolName());


    if (dataSourceConfig.getConnectionInitSql() != null) {
        hikariConfig.setConnectionInitSql(dataSourceConfig.getConnectionInitSql());
    }


    hikariConfig.setMaximumPoolSize(dataSourceConfig.getMaximumPoolSize());

    return new HikariDataSource(hikariConfig);
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:25,代码来源:HikariDataSourceFactory.java

示例8: MySQLThreadPool

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private MySQLThreadPool(FileConfiguration config) {
	HikariConfig poolConf = new HikariConfig();
	poolConf.setJdbcUrl("jdbc:mysql://"
			+ config.getString("mysql.host", "localhost")
			+ ":"
			+ config.getInt("mysql.port", 3306)
			+ "/"
			+ config.getString("mysql.database", "Stats4")
			+ config.getString("mysql.extra-opts", ""));
	poolConf.setUsername(config.getString("mysql.username"));
	poolConf.setPassword(config.getString("mysql.password"));
	poolConf.addDataSourceProperty("cachePrepStmts", true);
	poolConf.addDataSourceProperty("prepStmtCacheSize", "256");
	poolConf.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
	poolConf.addDataSourceProperty("useServerPrepStmts", true);
	poolConf.addDataSourceProperty("useLocalSessionState", true);
	poolConf.addDataSourceProperty("useLocalTransactionState", true);
	poolConf.addDataSourceProperty("rewriteBatchedStatements", true);
	poolConf.addDataSourceProperty("cacheResultSetMetadata", true);
	poolConf.addDataSourceProperty("cacheServerConfiguration", true);
	poolConf.addDataSourceProperty("elideSetAutoCommits", true);
	//		poolConf.addDataSourceProperty("maintainTimeStats", false);

	this.dataSource = new HikariDataSource(poolConf);
}
 
开发者ID:Lolmewn,项目名称:Stats4,代码行数:26,代码来源:MySQLThreadPool.java

示例9: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
    dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
    dataSourceConfig.setUsername(environment.getRequiredProperty("spring.datasource.username"));
    dataSourceConfig.setPassword(environment.getRequiredProperty("spring.datasource.password"));
    dataSourceConfig.setMaximumPoolSize(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maximumPoolSize")));
    dataSourceConfig.setMinimumIdle(Integer.parseInt(environment.getRequiredProperty("spring.datasource.minimumIdle")));
    dataSourceConfig.setMaxLifetime(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maxLifetime")));
    dataSourceConfig.setConnectionTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.connectionTimeout")));
    dataSourceConfig.setIdleTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.idleTimeout")));
    dataSourceConfig.addDataSourceProperty("poolName", environment.getRequiredProperty("spring.datasource.poolName"));
    dataSourceConfig.addDataSourceProperty("cachePrepStmts", "true");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return new HikariDataSource(dataSourceConfig);
}
 
开发者ID:RizkiMufrizal,项目名称:Spring-OAuth2-Custom,代码行数:19,代码来源:DataSourceConfiguration.java

示例10: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userName
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:29,代码来源:ExtensionHikariConnectionContext.java

示例11: getDataSourceFromConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:26,代码来源:ConnectionPool.java

示例12: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Heroku Datasource");

    String herokuUrl = System.getenv("JDBC_DATABASE_URL");
    if (herokuUrl != null) {
 HikariConfig config = new HikariConfig();

 //MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
 if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
            config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
            config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
            config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
        }

        config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
        config.addDataSourceProperty("url", herokuUrl);
        return new HikariDataSource(config);
    } else {
        throw new ApplicationContextException("Heroku database URL is not configured, you must set $JDBC_DATABASE_URL");
    }
}
 
开发者ID:OwnYourData,项目名称:oyd-pia,代码行数:23,代码来源:HerokuDatabaseConfiguration.java

示例13: setUpClass

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws ParserConfigurationException, IOException, SAXException, SQLException, LiquibaseException {
    ApplicationConfig config = ConfigurationBuilder.createBuilder().loadXMLConfiguration().getConfiguration();

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:" + config.getDbUrl() + "/" + config.getDbName());
    hikariConfig.setUsername(config.getDbUser());
    hikariConfig.setPassword(config.getDbPassword());
    hikariConfig.setMaximumPoolSize(config.getThreadLimit());
    if(config.isDbIgnoreSSLWarn()) {
        hikariConfig.addDataSourceProperty("useSSL", false);
    }

    dataSource = new HikariDataSource(hikariConfig);

    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));

    Liquibase liquibase = new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);

    liquibase.update(new Contexts(), new LabelExpression());
}
 
开发者ID:XIVStats,项目名称:XIVStats-Gatherer-Java,代码行数:22,代码来源:GathererControllerIT.java

示例14: initConnection

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void initConnection() throws Exception {
	HikariConfig config = new HikariConfig();
	config.setPoolName("Parties");
	config.setJdbcUrl(Variables.storage_settings_mysql_url);
	config.setUsername(Variables.storage_settings_mysql_username);
	config.setPassword(Variables.storage_settings_mysql_password);
	config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
	config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
	config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
	config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);
	
	// Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
	config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
	config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
	config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
	config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
	config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks
	
	hikariDataSource = new HikariDataSource(config);
}
 
开发者ID:AlessioDP,项目名称:Parties,代码行数:21,代码来源:MySQLData.java

示例15: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@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);
}
 
开发者ID:VHAINNOVATIONS,项目名称:BCDS,代码行数:30,代码来源:DatabaseConfiguration.java


注:本文中的com.zaxxer.hikari.HikariConfig.addDataSourceProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。