當前位置: 首頁>>代碼示例>>Java>>正文


Java HikariConfig.setConnectionInitSql方法代碼示例

本文整理匯總了Java中com.zaxxer.hikari.HikariConfig.setConnectionInitSql方法的典型用法代碼示例。如果您正苦於以下問題:Java HikariConfig.setConnectionInitSql方法的具體用法?Java HikariConfig.setConnectionInitSql怎麽用?Java HikariConfig.setConnectionInitSql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.zaxxer.hikari.HikariConfig的用法示例。


在下文中一共展示了HikariConfig.setConnectionInitSql方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: dataSource

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
    HikariConfig configuration = new HikariConfig();
    configuration.setJdbcUrl(url);
    configuration.setUsername(username);
    configuration.setPassword(password);
    configuration.setAutoCommit(false);
    configuration.setMaximumPoolSize(maxPoolSize);
    configuration.setConnectionTimeout(connectionTimeout);
    configuration.setMaxLifetime(maxLifetime);
    Properties properties = new Properties();
    properties.setProperty("cachePrepStmts", cachePrepStmts);
    properties.setProperty("prepStmtCacheSize", prepStmtCacheSize);
    properties.setProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit);
    properties.setProperty("useServerPrepStmts", useServerPrepStmts);
    configuration.setDataSourceProperties(properties);
    configuration.setConnectionInitSql("SET NAMES " + connectionCharacter);
    return new HikariDataSource(configuration);
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:21,代碼來源:MybatisAutoConfiguration.java

示例3: setup

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
protected void setup(Jecon jecon, HikariConfig hikariConfig) {
	this.jecon = jecon;
	if (config == null) {
		config = jecon.getConfigStruct();
	}
	this.prefix = config.getDbConfig().prefix;

	hikariConfig.setJdbcUrl(config.getDbConfig().url);
	hikariConfig.setInitializationFailFast(true);
	hikariConfig.setAutoCommit(true);
	hikariConfig.setConnectionInitSql("/* Jecon */SELECT 1");

	if (config.getDbConfig().poolSize > 0) {
		hikariConfig.setMaximumPoolSize(config.getDbConfig().poolSize);
	}
	if (config.getDbConfig().timeout > 0) {
		hikariConfig.setIdleTimeout(config.getDbConfig().timeout);
	}

	hikariConfig.setDataSourceProperties(config.getDbConfig().propaties);

	// HikariDataSourceをインスタンス化
	this.hikariDc = new HikariDataSource(hikariConfig);

	this.createTable();
}
 
開發者ID:HimaJyun,項目名稱:Jecon,代碼行數:27,代碼來源:Database.java

示例4: getHikariConfig

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
private HikariConfig getHikariConfig(AgroalDataSourceConfiguration dataSourceConfiguration) {
    if ( dataSourceConfiguration.isXA() ) {
        throw new UnsupportedOperationException( "Unsupported. Hikari does not support XA" );
    }

    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setDataSourceJNDI( dataSourceConfiguration.jndiName() );
    hikariConfig.setLeakDetectionThreshold( poolConfiguration.leakTimeout().toMillis() );
    hikariConfig.setIdleTimeout( poolConfiguration.reapTimeout().toMillis() );
    hikariConfig.setValidationTimeout( poolConfiguration.validationTimeout().toMillis() );

    if ( factoryConfiguration.jdbcTransactionIsolation().isDefined() ) {
        hikariConfig.setTransactionIsolation( "TRANSACTION_" + factoryConfiguration.jdbcTransactionIsolation().name() );
    }

    hikariConfig.setJdbcUrl( factoryConfiguration.jdbcUrl() );
    hikariConfig.setAutoCommit( factoryConfiguration.autoCommit() );
    hikariConfig.setConnectionInitSql( factoryConfiguration.initialSql() );

    Principal principal = factoryConfiguration.principal();
    if ( principal != null ) {
        hikariConfig.setUsername( factoryConfiguration.principal().getName() );
    }
    for ( Object credential : factoryConfiguration.credentials() ) {
        if ( credential instanceof SimplePassword ) {
            hikariConfig.setPassword( ( (SimplePassword) credential ).getWord() );
        }
    }

    hikariConfig.setMaximumPoolSize( poolConfiguration.maxSize() );
    hikariConfig.setConnectionTimeout( poolConfiguration.acquisitionTimeout().toMillis() );
    hikariConfig.setDriverClassName( factoryConfiguration.driverClassName() );

    return hikariConfig;
}
 
開發者ID:agroal,項目名稱:agroal,代碼行數:37,代碼來源:HikariUnderTheCovers.java

示例5: DatabaseConnectionPool

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
public DatabaseConnectionPool(DatabaseProperties properties) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
    hikariConfig.setJdbcUrl(properties.getDatasourceUrl());
    hikariConfig.setUsername(properties.getDatasourceUser());
    hikariConfig.setPassword(properties.getDatasourcePassword());
    hikariConfig.setConnectionInitSql(properties.getConnectionInitSql());
    hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    hikariConfig.addDataSourceProperty("useServerPrepStmts", "true");
    dataSource = new HikariDataSource(hikariConfig);
}
 
開發者ID:theaquarium,項目名稱:diax-dialect,代碼行數:14,代碼來源:DatabaseConnectionPool.java

示例6: createIndexEngine

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
private IndexEngine createIndexEngine() {
    if (System.getProperty("postgres") != null) {
        HikariConfig config = new HikariConfig();
        config.setMaximumPoolSize(50);
        config.setLeakDetectionThreshold(2000);
        config.setConnectionInitSql("SET log_statement = 'all'; SET search_path = 'public'");


        return new CascadingIndexEngine(new PostgreSQLIndexEngine(getPostgreSQLDataSource(), config),
                                        new MemoryIndexEngine());
    } else {
        return new MemoryIndexEngine();
    }
}
 
開發者ID:eventsourcing,項目名稱:es4j,代碼行數:15,代碼來源:TestWithRepository.java

示例7: build

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> property : this.properties.entrySet()) {
        properties.setProperty(property.getKey(), property.getValue());
    }

    final HikariConfig config = new HikariConfig();
    config.setDataSourceProperties(properties);
    if (this.autoCommitByDefault.isPresent()) {
        config.setAutoCommit(this.autoCommitByDefault.get());
    }
    config.setCatalog(this.defaultCatalog);
    if (this.readOnlyByDefault.isPresent()) {
        config.setReadOnly(this.readOnlyByDefault.get());
    }
    config.setDriverClassName(this.driverClass);
    config.setConnectionInitSql(this.initializationQuery);
    config.setMaximumPoolSize(this.maxSize);
    config.setMinimumIdle(this.minSize);
    if (this.getMaxConnectionAge().isPresent()) {
        config.setMaxLifetime(this.maxConnectionAge.toMilliseconds());
    }
    config.setPoolName(name);
    config.setJdbcUrl(this.url);
    config.setUsername(this.user);
    config.setPassword(this.user != null && this.password == null ? "" : this.password);
    config.setConnectionTestQuery(this.validationQuery);
    if (this.getValidationQueryTimeout().isPresent()) {
        config.setValidationTimeout(this.validationQueryTimeout.toMilliseconds());
    }
    if (this.defaultTransactionIsolation.isPresent()) {
        config.setTransactionIsolation(this.defaultTransactionIsolation.get().toString());
    }
    return new ManagedPooledDataSource(config, metricRegistry);
}
 
開發者ID:mtakaki,項目名稱:dropwizard-hikaricp,代碼行數:37,代碼來源:DataSourceFactory.java


注:本文中的com.zaxxer.hikari.HikariConfig.setConnectionInitSql方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。