@Bean(destroyMethod = "close") public DataSource mainDataSource() { BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(jdbcDriverClass); dataSource.setJdbcUrl(jdbcUrl); dataSource.setUsername(jdbcUsername); dataSource.setPassword(jdbcPassword); dataSource.setIdleConnectionTestPeriodInMinutes(2); dataSource.setIdleMaxAge(2, TimeUnit.HOURS); dataSource.setMaxConnectionsPerPartition(60); dataSource.setMinConnectionsPerPartition(20); dataSource.setPartitionCount(3); dataSource.setAcquireIncrement(10); dataSource.setStatementsCacheSize(50); return dataSource; } }
@Override public void close(DataSource dataSource) throws SQLException { if (dataSource instanceof BoneCPDataSource) { ((BoneCPDataSource) dataSource).close(); } } }
@Bean public DataSource dataSource() { BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass("org.postgresql.Driver"); dataSource.setJdbcUrl("jdbc:postgresql://localhost/oauthDB"); dataSource.setUsername("my_username"); dataSource.setPassword("*****"); return dataSource; }
BoneCPDataSource source = new BoneCPDataSource(); source.setDriverClass("org.h2.Driver"); source.setJdbcUrl("jdbc:h2:mem:x"); String name = new JdbcSession(source) .sql("SELECT name FROM user WHERE id = ?") .set(555) .select(new SingleHandler<String>(String.class));
@Inject public DBITransactionFactory(BoneCPConfig config, HealthCheckRegistry healthChecks) { super(); // Register for health check healthChecks.register("MySql", new PrivateMySqlHealthCheck(this)); LOGGER.debug("Creating BoneCPDataSource"); this.dataSource = new BoneCPDataSource(config); this.dbi = new DBI(dataSource); // Register JDBI argument factories dbi.registerArgumentFactory(new UUIDArgumentFactory()); dbi.registerArgumentFactory(new ExperimentIDArgumentFactory()); dbi.registerArgumentFactory(new BucketLabelArgumentFactory()); }
throws Exception BoneCPDataSource pool = new BoneCPDataSource(); pool.setDriverClass( config.driver().get() ); pool.setJdbcUrl( config.url().get() ); pool.setUsername( config.username().get() ); pool.setPassword( config.password().get() ); pool.setMinConnectionsPerPartition( config.minPoolSize().get() ); pool.setMaxConnectionsPerPartition( config.maxPoolSize().get() ); pool.setLoginTimeout( config.loginTimeoutSeconds().get() ); pool.setMaxConnectionAgeInSeconds( config.maxConnectionAgeSeconds().get() ); pool.setConnectionTestStatement( config.validationQuery().get() ); pool.setProperties( poolProperties );
int PartitionCount; BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(driver); dataSource.setJdbcUrl(db_url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setMinConnectionsPerPartition(MinConnPerPartition); dataSource.setMaxConnectionsPerPartition(MaxConnPerPartition); dataSource.setPartitionCount(PartitionCount); dataSource.setAcquireIncrement(AcquireIncrement); dataSource.setStatementsCacheSize(StatementsCacheSize); dataSource.setMaxConnectionAgeInSeconds(timeoutPeriod); dataSource.setConnectionTestStatement(validationSQL); try (Connection testConn = dataSource.getConnection(); PreparedStatement stmt = testConn.prepareStatement(validationSQL))
BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(conf.getProperty("db.driver")); dataSource.setJdbcUrl(conf.getProperty("db.url")); dataSource.setUsername(conf.getProperty("db.user")); dataSource.setPassword(conf.getProperty("db.password")); dataSource.setIdleConnectionTestPeriodInMinutes( Long.parseLong( conf.getProperty("db.bonecp.idleConnectionTestPeriod"))); dataSource.setIdleMaxAgeInSeconds( Long.parseLong( conf.getProperty("db.bonecp.idleMaxAge"))); dataSource.setMaxConnectionsPerPartition( Integer.parseInt( conf.getProperty("db.bonecp.maxConnections")));
private void createDataSource(WrappedDataSource source) throws SQLException { final BoneCPDataSource datasource = new BoneCPDataSource(); Configuration dbConf = source.getConfiguration(); String driver = dbConf.getWithDefault("driver", null); datasource.setClassLoader(instance.getClass().getClassLoader()); Properties hack = new Properties(); hack.put(BoneCP.DRIVER_INSTANCE_PROPERTY, instance); datasource.setDriverProperties(hack); datasource.setConnectionHook(new AbstractConnectionHook() { @Override public void onCheckIn(ConnectionHandle connection) { datasource.setUsername(dbConf.get("user")); datasource.setPassword(dbConf.get("pass")); datasource.setPassword(dbConf.get("password")); datasource.setPartitionCount(dbConf.getIntegerWithDefault("partitionCount", 1)); datasource.setMaxConnectionsPerPartition(dbConf.getIntegerWithDefault("maxConnectionsPerPartition", 30)); datasource.setMinConnectionsPerPartition(dbConf.getIntegerWithDefault("minConnectionsPerPartition", 5)); datasource.setAcquireIncrement(dbConf.getIntegerWithDefault("acquireIncrement", 1)); datasource.setAcquireRetryAttempts(dbConf.getIntegerWithDefault("acquireRetryAttempts", 10)); datasource.setAcquireRetryDelayInMs(dbConf.getIntegerWithDefault("acquireRetryDelay", 1000)); datasource.setConnectionTimeoutInMs(dbConf.getIntegerWithDefault("connectionTimeout", 1000)); datasource.setIdleMaxAge(dbConf.getIntegerWithDefault("idleMaxAge", 1000 * 60 * 10), java.util.concurrent.TimeUnit.MILLISECONDS); datasource.setMaxConnectionAge(dbConf.getIntegerWithDefault("maxConnectionAge", 1000 * 60 * 60), java.util.concurrent.TimeUnit.MILLISECONDS); datasource.setDisableJMX(dbConf.getBooleanWithDefault("disableJMX", true));
public static DataSource getDataSource(File file) throws ClassNotFoundException, IOException, DaoException { Class.forName("org.h2.Driver"); BoneCPDataSource ds = new BoneCPDataSource(); ds.setPartitionCount(8); ds.setMaxConnectionsPerPartition(4); ds.setJdbcUrl("jdbc:h2:"+file.getAbsolutePath()); ds.setUsername("sa"); ds.setPassword(""); // Initialize the database to create files try { ds.getConnection().close(); } catch (SQLException e) { throw new DaoException(e); } return ds; } }
com.jolbox.bonecp.BoneCPDataSource ds = new com.jolbox.bonecp.BoneCPDataSource(config); if (size >= 0) ds.setStatementsCacheSize(size); if (size >= 0) ds.setMaxConnectionsPerPartition(size); if (size >= 0) ds.setMinConnectionsPerPartition(size); if (value > 0) ds.setIdleMaxAgeInMinutes(value); ds.setDriverClass(dbDriver); ds.setJdbcUrl(storeMgr.getConnectionURL()); ds.setUsername(dbUser); ds.setPassword(dbPassword);
try { Class.forName(config.getString("driver")); BoneCPDataSource ds = new BoneCPDataSource(); ds.setDisableConnectionTracking(true); ds.setJdbcUrl(config.getString("url")); ds.setUsername(config.getString("username")); ds.setPassword(config.getString("password")); String partitions = config.getString("partitions"); if (partitions.equals("default")) { ds.setPartitionCount(Math.max(8, Runtime.getRuntime().availableProcessors())); } else { ds.setPartitionCount(Integer.valueOf(partitions)); while (cnxPerPartition * ds.getPartitionCount() < getMinimumReasonableConnections()) { cnxPerPartition++; LOG.warn("Raised connections per partition to " + cnxPerPartition); ds.setMaxConnectionsPerPartition(cnxPerPartition);
/** * Data source. * @return Source */ @Cacheable(forever = true) private static DataSource bonecp() { final BoneCPDataSource src = new BoneCPDataSource(); src.setDriverClass("org.postgresql.Driver"); src.setJdbcUrl(Manifests.read("Aintshy-PgsqlJdbc")); src.setUser(Manifests.read("Aintshy-PgsqlUser")); src.setPassword(Manifests.read("Aintshy-PgsqlPassword")); return src; }
@Override public DataSource create(Configuration hdpConfig) throws SQLException { LOG.debug("Creating BoneCP connection pool for the MetaStore"); String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig); String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig); String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig); int maxPoolSize = MetastoreConf.getIntVar(hdpConfig, MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS); Properties properties = DataSourceProvider.getPrefixedProperties(hdpConfig, BONECP); long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L); String partitionCount = properties.getProperty(PARTITION_COUNT_PROPERTY, "1"); BoneCPConfig config = null; try { config = new BoneCPConfig(properties); } catch (Exception e) { throw new SQLException("Cannot create BoneCP configuration: ", e); } config.setJdbcUrl(driverUrl); // if we are waiting for connection for a long time, something is really wrong // better raise an error than hang forever // see DefaultConnectionStrategy.getConnectionInternal() config.setConnectionTimeoutInMs(connectionTimeout); config.setMaxConnectionsPerPartition(maxPoolSize); config.setPartitionCount(Integer.parseInt(partitionCount)); config.setUser(user); config.setPassword(passwd); return initMetrics(new BoneCPDataSource(config)); }
@Override public BoneCPDataSource load(UsernamePassword key) throws Exception { BoneCPDataSource ds = null; ds = new BoneCPDataSource(getConfig()); ds.setUsername(key.getUsername()); ds.setPassword(key.getPassword()); return ds; } });
private static void populateForMySQLFull(Matcher matcher, String url, BoneCPDataSource datasource) { String username = matcher.group(1); String password = matcher.group(2); String host = matcher.group(3); String db = matcher.group(4); String defaultProperties = DEFAULT_MYSQL_PROPERTIES; if (MYSQL_CUSTOM_PROPERTIES.matcher(url).find()) { defaultProperties = ""; } datasource.setJdbcUrl(String.format("jdbc:mysql://%s/%s", host, db + defaultProperties)); datasource.setUsername(username); datasource.setPassword(password); }
private static void populateForH2(String url, BoneCPDataSource datasource, boolean isDev) { if (!url.contains("DB_CLOSE_DELAY") && isDev) { datasource.setJdbcUrl(url + ";DB_CLOSE_DELAY=-1"); } else { datasource.setJdbcUrl(url); } } }
/** * Initialize a new {@link com.jolbox.bonecp.BoneCPDataSource} instance with given configuration * properties * * @see AbstractDataSourceFactory#callConstructor(Class, java.util.Properties) */ @Override protected DataSource callConstructor(Class clazz, Properties configProperties) throws Exception { BoneCPConfig config = new BoneCPConfig(configProperties); BoneCPDataSource dataSource = (BoneCPDataSource) clazz.getConstructor(BoneCPConfig.class).newInstance(config); dataSource.setDriverClass(configProperties.getProperty("driverClass")); return dataSource; } }
@Override public void reload() throws Exception { // switch data source BoneCPDataSource oldTargetDataSource = (BoneCPDataSource)proxyDataSource.getTargetDataSource(); BoneCPDataSource newTargetDataSource = createNewDataSource(); newTargetDataSource.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool proxyDataSource.setTargetDataSource(newTargetDataSource); oldTargetDataSource.close(); } });
private BoneCPDataSource createBoneCPDataSource(Properties props) throws Exception { BoneCPDataSource dataSource = null; if (props == null) { dataSource = new BoneCPDataSource(); dataSource.setMaxConnectionsPerPartition(maxActive); dataSource.setMinConnectionsPerPartition(minIdle); } else { BoneCPConfig config = new BoneCPConfig(props); dataSource = new BoneCPDataSource(config); } dataSource.setJdbcUrl(jdbcUrl); dataSource.setDriverClass(jdbcDriver); dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }