本文整理汇总了Java中com.jolbox.bonecp.BoneCP类的典型用法代码示例。如果您正苦于以下问题:Java BoneCP类的具体用法?Java BoneCP怎么用?Java BoneCP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BoneCP类属于com.jolbox.bonecp包,在下文中一共展示了BoneCP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNonBlocking
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public void testNonBlocking() throws SQLException {
final BoneCP bcp = new BoneCP(createConfig());
BlockingOperation.off();
try {
final Connection h1 = bcp.getConnection();
assertNotNull(h1);
final Connection h2 = bcp.getConnection();
assertNotNull(h2);
final Connection h3 = bcp.getConnection();
assertNotNull(h3);
h1.close();
h2.close();
h3.close();
} finally {
BlockingOperation.on();
}
}
示例2: createConnectionPool
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public static void createConnectionPool() {
BoneCPConfig config = new BoneCPConfig();
config.setMaxConnectionsPerPartition(DatabaseConfiguration.getCpMaxConnections());
config.setAcquireRetryAttempts(DatabaseConfiguration.getCpAcquireRetryAttempts());
config.setAcquireRetryDelayInMs(DatabaseConfiguration.getCpAcquireRetryDelay());
config.setConnectionTimeoutInMs(DatabaseConfiguration.getCpConnectionTimeout());
config.setStatisticsEnabled(DatabaseConfiguration.isCpEnableStatistics());
config.setDisableConnectionTracking(true); // set this to true to avoid bonecp closing connections erroniously
config.setJdbcUrl(jdbc_);
config.setUsername(DatabaseConfiguration.getUsername());
config.setPassword(DatabaseConfiguration.getPassword());
config.setDefaultAutoCommit(DatabaseConfiguration.getCpDefaultAutoCommit());
try {
connectionPool_ = new BoneCP(config);
}
catch (Exception e) {
connectionPool_ = null;
logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
}
}
示例3: BoneCPDataSource
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public BoneCPDataSource(ConfigMap<String, String> datasource) throws IOException {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(datasource.get("url"));
config.setUsername(datasource.get("user"));
config.setPassword(datasource.get("password"));
config.setMinConnectionsPerPartition(datasource.getInteger("min_pool_size", 1));
config.setMaxConnectionsPerPartition(datasource.getInteger("max_pool_size", 10));
config.setPartitionCount(datasource.getInteger("partition_size", 1));
try {
this.datasource = new BoneCP(config);
} catch (SQLException e) {
throw new IOException(e);
}
}
示例4: ConnectionPool
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public ConnectionPool(String dbcUrl, String user, String pass, int minConns,
int maxConns, int partCount) throws ClassNotFoundException, SQLException {
/*
* Initialize our connection pool.
*
* We'll use a connection pool and reuse connections on a per-thread basis.
*/
/* setup the connection pool */
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(dbcUrl);
config.setUsername(user);
config.setPassword(pass);
config.setMinConnectionsPerPartition(minConns);
config.setMaxConnectionsPerPartition(maxConns);
config.setPartitionCount(partCount);
// Enable only for debugging.
//config.setCloseConnectionWatch(true);
pool = new BoneCP(config);
}
示例5: run
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
@Override
public void run(KenshoConfiguration configuration,
Environment environment) throws ClassNotFoundException {
final BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(configuration.getDataSourceFactory().getUrl());
config.setUsername(configuration.getDataSourceFactory().getUser());
config.setPassword(configuration.getDataSourceFactory().getPassword());
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(2);
config.setPartitionCount(1);
try {
final BoneCP connectionPool = new BoneCP(config);
final PgStatus status = new PgStatus(connectionPool);
final StatsEngine statsEngine = new StatsEngine(status);
environment.jersey().register(new DashboardResource(statsEngine));
environment.jersey().register(new DataResource(statsEngine));
environment.jersey().register(new QueryResource());
} catch (SQLException e) {
System.exit(0);
e.printStackTrace();
}
}
示例6: preStart
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
@Override
public void preStart() throws Exception {
String driver = ConfigUtils.getOptionalString(config, "driver");
if(driver != null) {
Class.forName(driver);
}
BoneCPConfig boneCpConfig = new BoneCPConfig();
boneCpConfig.setJdbcUrl(config.getString("url"));
boneCpConfig.setUsername(config.getString("user"));
boneCpConfig.setPassword(config.getString("password"));
boneCpConfig.setPoolName(poolName);
boneCpConfig.setDefaultAutoCommit(false);
boneCpConfig.setConnectionTimeout(10, TimeUnit.SECONDS);
boneCpConfig.setMaxConnectionsPerPartition(poolSize);
log.debug("creating database pool");
connectionPool = new BoneCP(boneCpConfig);
f = new FutureUtils(getContext());
transactionHandler = new TransactionHandler<>(new JdbcTransactionSupplier(getSelf(), f), log);
}
示例7: init
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
@Override
protected void init() throws Exception {
BoneCPConfig connPoolConfig = new BoneCPConfig();
connPoolConfig.setJdbcUrl(JDBC_URL);
connPoolConfig.setUsername(DB_USER);
connPoolConfig.setPassword(DB_PASS);
connPoolConfig.setMaxConnectionsPerPartition(DB_POOL_SIZE);
connPoolConfig.setMaxConnectionAgeInSeconds(600);
connPoolConfig.setDefaultAutoCommit(true);
connPoolConfig.setIdleConnectionTestPeriodInSeconds(30);
connPoolConfig.setConnectionTestStatement("SELECT 1");
this.connPool = new BoneCP(connPoolConfig);
// todo: shutdown pool
}
示例8: BigCloneBenchDB
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
private BigCloneBenchDB() throws SQLException {
BoneCPConfig config = new BoneCPConfig();
Path db = Paths.get("bigclonebenchdb/bcb").toAbsolutePath();
config.setJdbcUrl("jdbc:h2:" + db.toString());
config.setUsername("sa");
config.setPassword("");
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
}
示例9: ToolsDB
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
private ToolsDB() throws SQLException {
BoneCPConfig config = new BoneCPConfig();
Path db = Paths.get("toolsdb/tools").toAbsolutePath();
config.setJdbcUrl("jdbc:h2:" + db.toString());
config.setUsername("sa");
config.setPassword("bigclonebencheval");
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
}
示例10: testBlocking
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
@Test(expectedExceptions = {BlockingOperation.class })
public void testBlocking() throws SQLException {
final BoneCP bcp = new BoneCP(createConfig());
BlockingOperation.off();
try {
final Connection h1 = bcp.getConnection();
assertNotNull(h1);
final Connection h2 = bcp.getConnection();
assertNotNull(h2);
final Connection h3 = bcp.getConnection();
assertNotNull(h3);
bcp.getConnection();
fail();
} finally {
BlockingOperation.on();
}
}
示例11: initConnection
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
/**
* Initializes the pool from a property file
* (need to move `Globals` out of here)
*/
private static void initConnection() {
try {
BoneCPConfig config = new BoneCPConfig();
Class.forName(Global.getOptions().get("Store.class"));
config.setJdbcUrl(Global.getOptions().get("Store.dsn"));
config.setUsername(Global.getOptions().get("Store.user"));
config.setPassword(Global.getOptions().get("Store.pw"));
connectionPool = new BoneCP(config); // setup the connection pool
} catch (Exception e) {
logger.error("Could not initialize Triple-Store connection! Exiting ...", e);
System.exit(1);
}
}
示例12: init
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public static void init(String url, String username, String password) throws SQLException, ClassNotFoundException{
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
Class.forName("org.h2.Driver");
connectionPool = new BoneCP(config);
}
示例13: getInfo
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
public DataSourceInfo getInfo(final Object resource) throws Exception {
DataSourceInfo dataSourceInfo = null;
if (canMap(resource)) {
final BoneCPDataSource source = (BoneCPDataSource) resource;
final Field poolField = BoneCPDataSource.class.getDeclaredField("pool");
poolField.setAccessible(true);
final BoneCP pool = (BoneCP) poolField.get(source);
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setBusyConnections(source.getTotalLeased());
dataSourceInfo.setEstablishedConnections(pool.getTotalCreatedConnections());
dataSourceInfo.setMaxConnections(source.getPartitionCount() * source.getMaxConnectionsPerPartition());
dataSourceInfo.setJdbcURL(source.getJdbcUrl());
dataSourceInfo.setUsername(source.getUsername());
dataSourceInfo.setResettable(false);
}
return dataSourceInfo;
}
示例14: createBoneCP
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
private void createBoneCP() {
try {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(String.format("jdbc:mysql://%s:%d/%s", this.host, this.port, this.database));
config.setUsername(this.username);
config.setPassword(this.password);
config.setPartitionCount(2);
config.setMinConnectionsPerPartition(this.minPoolSize);
config.setMaxConnectionsPerPartition(this.maxPoolSize);
boneCP = new BoneCP(config);
this.createConnection();
} catch (Exception ex) {
throw new Error("Unrecoverable error when creating the BoneCP object.", ex);
}
}
示例15: DBPool
import com.jolbox.bonecp.BoneCP; //导入依赖的package包/类
/**
* 创建一个数据库连接池
* @param poolName
* @param host
* @param port
* @param dbName
* @param username
* @param password
* @param partitionCount
* @param minConnCountPerPar
* @param maxConnCountPerPar
* @throws Exception
*/
protected DBPool(String poolName, String host, String port, String dbName, String username, String password, int partitionCount, int minConnCountPerPar,
int maxConnCountPerPar) throws Exception
{
dbUrl = String.format(URL, host, port, dbName);
this.poolName = poolName;
this.partitionCount = partitionCount;
this.maxConnCountPerPar = maxConnCountPerPar;
this.minConnCountPerPar = minConnCountPerPar;
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(dbUrl);
config.setUsername(username);
config.setPassword(password);
// 分区数
config.setPartitionCount(partitionCount);
// 每次创建的新连接个数
config.setAcquireIncrement(2);
// 处理释放后的conn线程数
config.setReleaseHelperThreads(3);
// 分区最大连接数
config.setMaxConnectionsPerPartition(maxConnCountPerPar);
// 分区最小连接数
config.setMinConnectionsPerPartition(minConnCountPerPar);
// 空闲连接存活时间
config.setIdleMaxAgeInMinutes(10);
// 测试连接时间
config.setIdleConnectionTestPeriodInMinutes(10);
// 设置重新获取连接的次数。这个参数默认为5
config.setAcquireRetryAttempts(5);
// 重新获取连接的间隔时间
config.setAcquireRetryDelayInMs(3000);
boneCP = new BoneCP(config);
}