Java Code Examples for com.zaxxer.hikari.HikariDataSource#setAutoCommit()
The following examples show how to use
com.zaxxer.hikari.HikariDataSource#setAutoCommit() .
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: DatabaseConfiguration.java From galeb with Apache License 2.0 | 6 votes |
@Bean public HikariDataSource dataSource(DataSourceProperties properties) { HikariDataSource hikariDataSource = (HikariDataSource) properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); hikariDataSource.setConnectionTimeout(DB_CONN_TIMEOUT); hikariDataSource.setMaximumPoolSize(DB_MAX_POOL_SIZE); hikariDataSource.setMaxLifetime(DB_MAX_LIFE_TIME); hikariDataSource.setAutoCommit(DB_AUTOCOMMIT); hikariDataSource.setConnectionTestQuery("SELECT 1"); hikariDataSource.addDataSourceProperty("cachePrepStmts", DB_CACHE_PREP_STMTS); hikariDataSource.addDataSourceProperty("prepStmtCacheSize", DB_PREP_STMT_CACHE_SIZE); hikariDataSource.addDataSourceProperty("prepStmtCacheSqlLimit", DB_PREP_STMT_CACHE_SQL_LIMIT); hikariDataSource.addDataSourceProperty("useServerPrepStmts", DB_USE_SERVER_PREP_STMTS); hikariDataSource.addDataSourceProperty("useLocalSessionState", DB_USE_LOCAL_SESSION_STATE); hikariDataSource.addDataSourceProperty("rewriteBatchedStatements", DB_REWRITE_BATCHED_STATEMENTS); hikariDataSource.addDataSourceProperty("cacheResultSetMetadata", DB_CACHE_RESULT_SET_METADATA); hikariDataSource.addDataSourceProperty("cacheServerConfiguration", DB_CACHE_SERVER_CONFIGURATION); hikariDataSource.addDataSourceProperty("elideSetAutoCommits", DB_ELIDE_SET_AUTO_COMMITS); hikariDataSource.addDataSourceProperty("maintainTimeStats", DB_MAINTAIN_TIME_STATS); return hikariDataSource; }
Example 2
Source File: LocDataSourceAutoConfiguration.java From loc-framework with MIT License | 6 votes |
private HikariDataSource createHikariDataSource(JdbcProperties jdbcProperties) { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setJdbcUrl(jdbcProperties.getJdbcUrl()); hikariDataSource.setUsername(jdbcProperties.getUsername()); hikariDataSource.setPassword(jdbcProperties.getPassword()); JdbcPoolProperties jdbcPoolProperties = jdbcProperties.getJdbcPool(); hikariDataSource.setAutoCommit(jdbcPoolProperties.isAutoCommit()); hikariDataSource.setConnectionTimeout(jdbcPoolProperties.getConnectionTimeout()); hikariDataSource.setIdleTimeout(jdbcPoolProperties.getIdleTimeout()); hikariDataSource.setMaxLifetime(jdbcPoolProperties.getMaxLifetime()); hikariDataSource.setMaximumPoolSize(jdbcPoolProperties.getMaximumPoolSize()); hikariDataSource.setMinimumIdle(jdbcPoolProperties.getMinimumIdle()); hikariDataSource .setInitializationFailTimeout(jdbcPoolProperties.getInitializationFailTimeout()); hikariDataSource.setIsolateInternalQueries(jdbcPoolProperties.isIsolateInternalQueries()); hikariDataSource.setReadOnly(jdbcPoolProperties.isReadOnly()); hikariDataSource.setRegisterMbeans(jdbcPoolProperties.isRegisterMbeans()); Optional.ofNullable(jdbcPoolProperties.getDriverClassName()) .ifPresent(hikariDataSource::setDriverClassName); hikariDataSource.setValidationTimeout(jdbcPoolProperties.getValidationTimeout()); hikariDataSource.setLeakDetectionThreshold(jdbcPoolProperties.getLeakDetectionThreshold()); return hikariDataSource; }
Example 3
Source File: MySQLDAOTestUtil.java From conductor with Apache License 2.0 | 6 votes |
private void createDatabase(String dbName) { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:mysql://localhost:33307/conductor"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setAutoCommit(false); dataSource.setMaximumPoolSize(2); try (Connection connection = dataSource.getConnection()) { try(Statement statement = connection.createStatement()) { statement.execute("CREATE DATABASE IF NOT EXISTS "+dbName); } } catch (SQLException sqlException) { logger.error("Unable to create default connection for docker mysql db", sqlException); throw new RuntimeException(sqlException); }finally { dataSource.close(); } }
Example 4
Source File: PostgresDAOTestUtil.java From conductor with Apache License 2.0 | 5 votes |
private HikariDataSource getDataSource(Configuration config) { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(config.getProperty("jdbc.url", JDBC_URL_PREFIX + "conductor")); dataSource.setUsername(config.getProperty("jdbc.username", "postgres")); dataSource.setPassword(config.getProperty("jdbc.password", "postgres")); dataSource.setAutoCommit(false); // Prevent DB from getting exhausted during rapid testing dataSource.setMaximumPoolSize(8); flywayMigrate(dataSource); return dataSource; }
Example 5
Source File: MySQLDAOTestUtil.java From conductor with Apache License 2.0 | 5 votes |
private HikariDataSource getDataSource(Configuration config) { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(config.getProperty("jdbc.url", "jdbc:mysql://localhost:33307/conductor")); dataSource.setUsername(config.getProperty("jdbc.username", "conductor")); dataSource.setPassword(config.getProperty("jdbc.password", "password")); dataSource.setAutoCommit(false); // Prevent DB from getting exhausted during rapid testing dataSource.setMaximumPoolSize(8); flywayMigrate(dataSource); return dataSource; }
Example 6
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 7
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; }