com.jolbox.bonecp.BoneCPDataSource Java Examples

The following examples show how to use com.jolbox.bonecp.BoneCPDataSource. 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: BoneCPDataSourceFactoryBean.java    From cloud-config with MIT License 6 votes vote down vote up
@Override
protected DataSource createInstance() throws Exception {
    Preconditions.checkNotNull(config, "config cannot be empty");
    final BoneCPDataSource targetDataSource = createNewDataSource();
    final DelegatingDataSource proxyDataSource = createProxyDataSource(targetDataSource);
    config.setReloadCallback(new ReloadCallback() {
        @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();
        }
    });
    return proxyDataSource;
}
 
Example #2
Source File: BoneCPDataSourceFactoryBean.java    From cloud-config with MIT License 6 votes vote down vote up
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;
}
 
Example #3
Source File: CompareWithPopularPool.java    From clearpool with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBonecp() throws Exception {
  BoneCPDataSource dataSource = new BoneCPDataSource();
  dataSource.setMinConnectionsPerPartition(this.corePoolSize);
  dataSource.setMaxConnectionsPerPartition(this.maxPoolSize);
  dataSource.setDriverClass(this.driverClassName);
  dataSource.setJdbcUrl(this.url);
  dataSource.setStatementsCacheSize(100);
  dataSource.setServiceOrder("LIFO");
  dataSource.setUsername(this.username);
  dataSource.setPassword(this.password);
  dataSource.setPartitionCount(1);
  dataSource.setAcquireIncrement(5);
  for (int i = 0; i < this.loop; ++i) {
    ThreadProcessUtils.process(dataSource, "boneCP", this.count, threadCount, physicalCon);
  }
  System.out.println();
}
 
Example #4
Source File: DefaultDataSourceProvider.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Create a pooled datasource for the application.
 *
 * Default sqlite database does not work with a connection pool, actually
 * most embedded databases do not, hence returning native implementation for
 * default db.
 */
@Override
public DataSource get() {
  String jdbcUrl = configuration.getJdbcUrl();
  if (StringUtils.contains(jdbcUrl, "derby")) {
    return new DerbyDataSourceProvider(configuration).get();
  } else if (StringUtils.contains(jdbcUrl, "sqlite")) {
    return new SqliteDataSourceProvider(configuration).get();
  }

  BoneCPDataSource cpDataSource = new BoneCPDataSource();
  cpDataSource.setDriverClass(configuration.getDriverClass());
  cpDataSource.setJdbcUrl(configuration.getJdbcUrl());
  cpDataSource.setUsername(configuration.getUserName());
  cpDataSource.setPassword(configuration.getPassword());
  cpDataSource.setDefaultAutoCommit(configuration.setAutoCommit());
  cpDataSource.setConnectionTimeoutInMs(configuration.getConnectionTimeout());
  cpDataSource.setMaxConnectionsPerPartition(
      configuration.getMaxActiveConnections());
  cpDataSource.setMaxConnectionAgeInSeconds(
      configuration.getMaxConnectionAge());
  cpDataSource.setIdleMaxAgeInSeconds(
      configuration.getMaxIdleConnectionAge());
  cpDataSource.setIdleConnectionTestPeriodInSeconds(
      configuration.getIdleConnectionTestPeriod());
  cpDataSource.setConnectionTestStatement(
      configuration.getConnectionTestStatement());

  return cpDataSource;
}
 
Example #5
Source File: SequenceDaoTest.java    From cloud-config with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    dataSource = new BoneCPDataSource();
    dataSource.setDriverClass("org.h2.Driver");
    dataSource.setJdbcUrl(JDBC_URL);
    jdbcSequenceDao = new JdbcSequenceDao();
    jdbcSequenceDao.setJdbcTemplate(new JdbcTemplate(dataSource));
    jdbcSequenceDao.setStep(step);
    jdbcSequenceDao.setDefaultMaxLimit(maxLimit);
}
 
Example #6
Source File: MysqlUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the connection pool.
 */
public static final void init(String database, String username, String password, 
		String server, int maxConn, int minConn, String jndi) {
	String dbUrl = StringUtil.concat("jdbc:mysql://", server, ":3306/", database, 
			"?connectTimeout=", 10000, "&useUnicode=true&characterEncoding=utf8");
	
	logger.info("Try to connect to Mysql with url: {}", dbUrl);
	
  // create a new configuration object
 	BoneCPConfig config = new BoneCPConfig();
  // set the JDBC url
 	config.setJdbcUrl(dbUrl);
 	config.setPartitionCount(2);
 	config.setMaxConnectionsPerPartition(maxConn);
 	config.setMinConnectionsPerPartition(minConn);
 	config.setUsername(username);
 	config.setPassword(password);
	
  // setup the connection pool
	try {
		BoneCPDataSource dataSource = new BoneCPDataSource(config);
		Context jndiContext = GameContext.getInstance().getJndiContext();
		jndiContext.bind(jndi, dataSource);
		dataSourceMap.put(jndi, dataSource);
		dataSourceReadyMap.put(jndi, Boolean.TRUE);
	} catch (Exception e) {
		logger.warn("The connection to Mysql database is unavailable. Exception:{}", e.getMessage());
		dataSourceReadyMap.put(jndi, Boolean.FALSE);
	}
}
 
Example #7
Source File: MysqlUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Destroy and shutdown the connection pool.
 */
public static void destroy() {
	for ( BoneCPDataSource dataSource : dataSourceMap.values() ) {
		if ( dataSource != null ) {
			dataSource.close();
			dataSource = null;
			logger.info("The connection to Mysql database is destroyed.");
		}			
	}
}
 
Example #8
Source File: FlexyPoolConfiguration.java    From flexy-pool with Apache License 2.0 5 votes vote down vote up
@Bean
public Configuration<BoneCPDataSource> configuration() {
    return new Configuration.Builder<BoneCPDataSource>(
            uniqueId,
            poolingDataSource,
            BoneCPPoolAdapter.FACTORY
    ).build();
}
 
Example #9
Source File: FlexyPoolConfiguration.java    From flexy-pool with Apache License 2.0 5 votes vote down vote up
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
    Configuration<BoneCPDataSource> configuration = configuration();
    return new FlexyPoolDataSource<BoneCPDataSource>(configuration,
            new RetryConnectionAcquiringStrategy.Factory(2)
    );
}
 
Example #10
Source File: BoneCPDataSourceCreator.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource pool(final String name, final DataSource ds, final Properties properties) {
    final BoneCPDataSource dataSourceProvidedPool = createPool(properties);
    dataSourceProvidedPool.setDatasourceBean(ds);
    if (dataSourceProvidedPool.getPoolName() == null) {
        dataSourceProvidedPool.setPoolName(name);
    }
    return dataSourceProvidedPool;
}
 
Example #11
Source File: BoneCPDataSourceFactoryBean.java    From cloud-config with MIT License 4 votes vote down vote up
@Override
protected void destroyInstance(DataSource instance) throws Exception {
    ((BoneCPDataSource)((DelegatingDataSource)instance).getTargetDataSource()).close();
}
 
Example #12
Source File: BoneCPDataSourceServiceImporter.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Override
protected void passivateDataSourcePool( BoneCPDataSource dataSourcePool )
        throws Exception
{
    dataSourcePool.close();
}
 
Example #13
Source File: BoneCPPoolAdapter.java    From flexy-pool with Apache License 2.0 4 votes vote down vote up
@Override
public PoolAdapter<BoneCPDataSource> newInstance(
        ConfigurationProperties<BoneCPDataSource, Metrics, PoolAdapter<BoneCPDataSource>> configurationProperties) {
return new BoneCPPoolAdapter(configurationProperties);
}
 
Example #14
Source File: BoneCPPoolAdapter.java    From flexy-pool with Apache License 2.0 4 votes vote down vote up
/**
 * Init constructor
 */
public BoneCPPoolAdapter(ConfigurationProperties<BoneCPDataSource, Metrics, PoolAdapter<BoneCPDataSource>> configurationProperties) {
    super(configurationProperties);
}
 
Example #15
Source File: BoneCPDataSourceCreator.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
protected void doDestroy(final CommonDataSource dataSource) throws Throwable {
    ((BoneCPDataSource) dataSource).close();
}