本文整理汇总了Java中com.jolbox.bonecp.BoneCPConfig类的典型用法代码示例。如果您正苦于以下问题:Java BoneCPConfig类的具体用法?Java BoneCPConfig怎么用?Java BoneCPConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BoneCPConfig类属于com.jolbox.bonecp包,在下文中一共展示了BoneCPConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnectionPool
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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));
}
}
示例2: BoneCPDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}
}
示例3: createConfig
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的package包/类
private BoneCPConfig createConfig() {
final BoneCPConfig config = new BoneCPConfig();
config.setPartitionCount(1);
config.setLazyInit(false);
config.setMinConnectionsPerPartition(3);
config.setMaxConnectionsPerPartition(3);
config.setDatasourceBean(new AbstractDataSource() {
@Override
public Connection getConnection() throws SQLException {
return Mockito.mock(Connection.class);
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return getConnection();
}
public Logger getParentLogger() {
return null;
}
});
config.setConnectionTimeoutInMs(Timeout.standardTimeoutMillis());
config.setConnectionHook(new BoneCPHack(config.getConnectionHook()));
return config;
}
示例4: ConnectionPool
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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: mysqlDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的package包/类
private static DataSource mysqlDataSource() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(Exception e) {
throw new Error(e);
}
BoneCPConfig config = new BoneCPConfig();
configureBoneCp(config);
config.setJdbcUrl("jdbc:mysql://localhost/sfm");
config.setUsername("sfm");
config.setPassword("");
return new BoneCPDataSource(config);
}
示例6: hsqlDbDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的package包/类
private static DataSource hsqlDbDataSource() {
try {
Class.forName("org.hsqldb.jdbc.JDBCDriver");
} catch(Exception e) {
throw new Error(e);
}
BoneCPConfig config = new BoneCPConfig();
configureBoneCp(config);
config.setJdbcUrl("jdbc:hsqldb:mem:mymemdb");
config.setUsername("SA");
config.setPassword("");
return new BoneCPDataSource(config);
}
示例7: run
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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();
}
}
示例8: preStart
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}
示例9: afterPropertiesSet
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
this.jdbcConfig = JdbcConfig.current;
Map cfg = this.jdbcConfig.get(Map.class, this.name);
this.engineType = ObjectUtils.toString(cfg.get("type"));
BoneCPConfig config = new BoneCPConfig();
config.setDisableJMX(false);
config.setUsername(ObjectUtils.toString(cfg.get("user")));
config.setPassword(ObjectUtils.toString(cfg.get("pwd")));
config.setProperties(this.jdbcConfig.getPoolProperties());
config.setStatisticsEnabled(true);
config.setConnectionHook(getConnectionHook());
String url = ObjectUtils.toString(cfg.get("url"));
config.setJdbcUrl(this.getJdbcFullUrl(url));
this.shardPooledDataSource = new ShardPooledDataSource(config);
shardPooledDataSource.setDriverClass(this.getDriver());
}
示例10: init
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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
}
示例11: BigCloneBenchDB
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}
示例12: ToolsDB
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}
示例13: createDataSource
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的package包/类
/**
* Выполняет конфигурацию и создание пула соединений с БД
*
* @param dataSourceDescriptor описания БД
* @param parameters параметры соединения
* @return Возвращает пул соединений с БД
*/
private DataSource createDataSource(DataSourceDescriptor dataSourceDescriptor, DataSourceSyncParameters parameters) {
// Проверяем, что такой драйвер зарегистрирован
checkDriverClass(dataSourceDescriptor);
// Выполняем конфигурацию пула соединений
BoneCPConfig configuration = new BoneCPConfig();
// Driver properties
{
String[] driverProperties = StringUtils.split(parameters.getJdbcProperties(), ";");
if (driverProperties != null) {
configuration.setDriverProperties(createConnectionProperties(driverProperties));
}
}
// URL
{
configuration.setJdbcUrl(parameters.getJdbcUrl());
configuration.setUsername(parameters.getUsername());
configuration.setPassword(parameters.getPassword());
}
// Connection properties
{
configuration.setDefaultAutoCommit(false);
configuration.setConnectionTimeout(parameters.getTimeout(), TimeUnit.SECONDS);
if (StringUtils.hasText(dataSourceDescriptor.getValidateQuery())) {
configuration.setConnectionTestStatement(dataSourceDescriptor.getValidateQuery());
}
configuration.setPartitionCount(1);
}
// Создаем и возвращаем пул
return new BoneCPDataSource(configuration);
}
示例14: initConnection
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}
}
示例15: init
import com.jolbox.bonecp.BoneCPConfig; //导入依赖的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);
}