@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)); }
pbds = new BoneCPDataSource(); pbds.setDatasourceBean(mysqlcpds); pbds.setMinConnectionsPerPartition(1); pbds.setMaxConnectionsPerPartition(10); pbds.setIdleConnectionTestPeriodInMinutes(60); pbds.setIdleMaxAgeInMinutes(240); pbds.setPartitionCount(1);
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcConfig, "JdbcConfig must not be NULL."); BoneCPConfig config = new BoneCPConfig(); Field[] fields = BoneCPConfig.class.getDeclaredFields(); Iterator<Object> itor = jdbcConfig.keySet().iterator(); while (itor.hasNext()){ String name = (String)itor.next(); Object value = jdbcConfig.get(name); for (Field field: fields){ if (field.getName().equalsIgnoreCase(name)){ try { field.setAccessible(true); field.set(config, value); } catch (Exception e) { // should never happen } } } } dataSource = new BoneCPDataSource(config); }
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));
public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { Reference ref = (Reference) object; Enumeration<RefAddr> addrs = ref.getAll(); Properties props = new Properties(); while (addrs.hasMoreElements()) { RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")){ Class.forName((String) addr.getContent()); } else { props.put(addr.getType(), addr.getContent()); } } BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
public static void main(String[] args) { Class.forName("org.hsqldb.jdbcDriver"); BoneCPDataSource ds = new BoneCPDataSource(); ds.setJdbcUrl("jdbc:hsqldb:mem:test"); ds.setUsername("sa");
@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; }
@Singleton @Produces public javax.sql.DataSource produceDataSource() { try { Class.forName(config.getDriver()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } BoneCPDataSource ds = new BoneCPDataSource(); ds.setUser(config.getUser()); ds.setPassword(config.getPassword()); ds.setJdbcUrl(config.getUrl()); DataSource datasource = new DataSource(ds); return datasource; } }
@Override public DataSource getDataSource(JsonObject config) throws SQLException { BoneCPConfig boneCPConfig = new BoneCPConfig(); mergeConfig(boneCPConfig, config); // we now need to change the default class loader mostly for the cases where // we do not use fat jars. In that case other connection pools will fail // loading the drivers boneCPConfig.setClassLoader(getClassLoader()); return new BoneCPDataSource(boneCPConfig); }
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; } }
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; }
@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; } });
@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()); }
@Bean public DataSource dataSource() { BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER)); dataSource.setJdbcUrl(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_URL)); dataSource.setUsername(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME)); dataSource.setPassword(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD)); return dataSource; }
@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 new BoneCPDataSource(config); }
/** * 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; }
@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; } }
private BoneCPDataSource createDataSource() { ResourceHelper.forName(config.getJdbcDriver(), getClass()); BoneCPDataSource datasource = new BoneCPDataSource(); datasource.setDriverClass(config.getJdbcDriver()); datasource.setJdbcUrl(config.getJdbcUrl()); datasource.setUsername(config.getJdbcUser()); datasource.setPassword(config.getJdbcPassword()); datasource.setMinConnectionsPerPartition(config.getPoolMinConnections()); datasource.setMaxConnectionsPerPartition(config.getPoolMaxConnections()); return datasource; } }
private DataSource getBoneCPDatSource() { final BoneCPConfig dbConfig = new BoneCPConfig(); dbConfig.setJdbcUrl(config.getJdbcUrl()); dbConfig.setUsername(config.getUsername()); dbConfig.setPassword(config.getPassword()); dbConfig.setMinConnectionsPerPartition(config.getMinIdle()); dbConfig.setMaxConnectionsPerPartition(config.getMaxActive()); dbConfig.setConnectionTimeout(config.getConnectionTimeout().getPeriod(), config.getConnectionTimeout().getUnit()); /* dbConfig.setIdleMaxAge(config.getIdleMaxAge().getPeriod(), config.getIdleMaxAge().getUnit()); dbConfig.setMaxConnectionAge(config.getMaxConnectionAge().getPeriod(), config.getMaxConnectionAge().getUnit()); dbConfig.setIdleConnectionTestPeriod(config.getIdleConnectionTestPeriod().getPeriod(), config.getIdleConnectionTestPeriod().getUnit()); */ dbConfig.setPartitionCount(1); dbConfig.setDisableJMX(false); return new BoneCPDataSource(dbConfig); }
private BoneCPDataSource createNewDataSource() { BoneCPDataSource target = new BoneCPDataSource(); target.setDriverClass(config.getDriverClassName()); target.setJdbcUrl(config.getJdbcUrl()); target.setUsername(config.getUserName()); target.setPassword(config.getPassword()); target.setIdleConnectionTestPeriodInMinutes(config.getIdleConnectionTestPeriodInMinutes()); target.setIdleMaxAgeInMinutes(config.getIdleMaxAgeInMinutes()); target.setMaxConnectionsPerPartition(config.getMaxConnectionsPerPartition()); target.setMinConnectionsPerPartition(config.getMinConnectionsPerPartition()); target.setPartitionCount(config.getPartitionCount()); target.setAcquireIncrement(config.getAcquireIncrement()); target.setStatementsCacheSize(config.getStatementsCacheSize()); target.setDisableJMX(true); return target; }