本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setDriverClassName方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setDriverClassName方法的具体用法?Java HikariConfig.setDriverClassName怎么用?Java HikariConfig.setDriverClassName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.zaxxer.hikari.HikariConfig
的用法示例。
在下文中一共展示了HikariConfig.setDriverClassName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultHikariConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Nonnull
public static HikariConfig getDefaultHikariConfig() {
final HikariConfig hikariConfig = new HikariConfig();
//more database connections don't help with performance, so use a default value based on available cores
//http://www.dailymotion.com/video/x2s8uec_oltp-performance-concurrent-mid-tier-connections_tech
hikariConfig.setMaximumPoolSize(Math.max(Runtime.getRuntime().availableProcessors(), 4));
//timeout the validation query (will be done automatically through Connection.isValid())
hikariConfig.setValidationTimeout(3000);
hikariConfig.setConnectionTimeout(10000);
hikariConfig.setAutoCommit(false);
hikariConfig.setDriverClassName("org.postgresql.Driver");
return hikariConfig;
}
示例2: 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);
}
示例3: enableDatabaseMySQLTest
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
try {
final DB database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
final HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
database.stop();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assert.fail();
}
}
示例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);
}
示例5: setUp
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@BeforeClass
public void setUp() throws SQLException {
Connection connection = DriverManager.getConnection(databaseUrl + ";create=true");
Statement statement = connection.createStatement();
statement.executeUpdate(CREATE_MB_COORDINATOR_HEARTBEAT_TABLE);
statement.executeUpdate(CREATE_MB_NODE_HEARTBEAT_TABLE);
connection.close();
Map<String, String> rdbmsCoordinationOptions = new HashMap<>();
rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.NODE_IDENTIFIER, nodeOneId);
rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.HEARTBEAT_INTERVAL, "5000");
rdbmsCoordinationOptions.put(RdbmsCoordinationConstants.COORDINATOR_ENTRY_CREATION_WAIT_TIME, "3000");
HikariConfig hikariDatasourceConfig = new HikariConfig();
hikariDatasourceConfig.setJdbcUrl(databaseUrl);
hikariDatasourceConfig.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
hikariDatasourceConfig.setAutoCommit(false);
DataSource datasource = new HikariDataSource(hikariDatasourceConfig);
RdbmsCoordinationDaoImpl rdbmsCoordinationDaoImpl = new RdbmsCoordinationDaoImpl(datasource);
rdbmsCoordinationStrategy =
new RdbmsCoordinationStrategy(rdbmsCoordinationDaoImpl, rdbmsCoordinationOptions);
rdbmsCoordinationStrategy.start();
}
示例6: 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);
}
示例7: enableDatabaseSQLiteTest
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
try {
final HikariConfig config = new HikariConfig();
config.setDriverClassName("org.sqlite.JDBC");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assertions.fail(ex);
}
}
示例8: enableDatabaseMySQLTest
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
try {
final DB database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
final HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
database.stop();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assertions.fail(ex);
}
}
示例9: start
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void start() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(this.conURL);
config.setUsername(this.username);
config.setPassword(this.password);
config.setDriverClassName(this.driverName);
config.setMaximumPoolSize(max);
config.setMinimumIdle(min);
if (this.testSql != null && this.testSql.trim().length() > 0) {
config.setConnectionTestQuery(testSql);
}
config.setPoolName("HikariCPPool[" + username + "]");
config.addDataSourceProperty("cachePrepStmts", AppProperties.get("HikariCPPool_cachePrepStmts", "true"));
config.addDataSourceProperty("prepStmtCacheSize", AppProperties.get("HikariCPPool_prepStmtCacheSize", "250"));
config.addDataSourceProperty("prepStmtCacheSqlLimit",
AppProperties.get("HikariCPPool_prepStmtCacheSqlLimit", "2048"));
config.setConnectionTimeout(AppProperties.getAsInt("HikariCPPool_connectionTimeout", 30000));
config.setIdleTimeout(AppProperties.getAsInt("HikariCPPool_idleTimeout", 600000));
config.setMaxLifetime(AppProperties.getAsInt("HikariCPPool_maxLifetime", 1800000));
// HikariDataSource ds = new HikariDataSource(config);
// this.datasource=ds.getDataSource();
this.datasource = new HikariDataSource(config);
}
示例10: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@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);
}
示例11: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
/**
* Prepare @{link DataSource} to access underlying database. We will use HikariCP because currently this is a industry tsndartd
*
* @param environment Interface representing the environment in which the current application is running.
*/
@Bean(destroyMethod = "close")
DataSource dataSource(Environment environment) {
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(environment.getRequiredProperty("db.driver"));
dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("db.url"));
dataSourceConfig.setUsername(environment.getRequiredProperty("db.username"));
dataSourceConfig.setPassword(environment.getRequiredProperty("db.password"));
return new HikariDataSource(dataSourceConfig);
}
示例12: getDataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
@Primary
public DataSource getDataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
config.setUsername("root");
config.setPassword("root");
config.setMaximumPoolSize(500);
config.setMinimumIdle(10);
return new HikariDataSource(config);
}
示例13: createLocalOracleDb
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private Database createLocalOracleDb() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:XE");
config.setUsername("test");
config.setPassword("somepwd");
config.setAutoCommit(false);
config.setDriverClassName("oracle.jdbc.driver.OracleDriver");
Database oracleDb = new Database(new HikariDataSource(config));
return oracleDb;
}
示例14: setupPool
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void setupPool() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setUsername(username);
config.setPassword(password);
config.setMinimumIdle(minimumIdle);
config.setMaximumPoolSize(poolSize);
config.setConnectionTimeout(connectionTimeout);
config.setConnectionTestQuery(testQuery);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
dataSource = new HikariDataSource(config);
}
示例15: createDataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private static DataSource createDataSource() {
HikariConfig hikariDataSourceConfig = new HikariConfig();
hikariDataSourceConfig.setJdbcUrl(DATABASE_URL);
hikariDataSourceConfig.setDriverClassName(DRIVER_CLASS_NAME);
hikariDataSourceConfig.setAutoCommit(false);
return new HikariDataSource(hikariDataSourceConfig);
}