com.jolbox.bonecp.BoneCP类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中com.jolbox.bonecp.BoneCP类的一些代码示例,展示了BoneCP类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BoneCP类的具体详情如下:
包路径:com.jolbox.bonecp.BoneCP
类名称:BoneCP

BoneCP介绍

[英]Connection pool (main class).
[中]连接池(主类)。

代码示例

代码示例来源:origin: org.ddbstoolkit.toolkit.jdbc/ddbstoolkit-jdbc

/**
 * Get JDBC connection
 * @return Connection
 * @throws SQLException SQL Exception
 */
public Connection getConnection() throws SQLException {
  return connectionPool.getConnection();
}

代码示例来源:origin: org.wisdom-framework/wisdom-jdbc-datasources

/**
 * Just a synonym to shutdown.
 */
public void close() {
  shutdown();
}

代码示例来源:origin: com.splout.db/splout-commons

public JDBCManager(String driver, String connectionUri, int nConnectionsPool, String userName, String password) throws SQLException, ClassNotFoundException {
  
  Class.forName(driver);
  
  BoneCPConfig config = new BoneCPConfig();
  config.setJdbcUrl(connectionUri);
  config.setMinConnectionsPerPartition(nConnectionsPool);
  config.setMaxConnectionsPerPartition(nConnectionsPool);
  config.setUsername(userName);
  config.setPassword(password);
  config.setPartitionCount(1);
  config.setDefaultAutoCommit(false);
  connectionPool = new BoneCP(config); // setup the connection pool
}

代码示例来源:origin: stackoverflow.com

/**
 * Get a status information of the JDBC connections.
 * 
 * @return The status information of the JDBC connections.
 */
public String getConnectionStatus() {
  String status = "unknown";
  if (dataSource instanceof BoneCPDataSource) {

    BoneCPDataSource bcpDataSource = (BoneCPDataSource) dataSource;
    BoneCP bcp = bcpDataSource.getPool();
    status = "JDBC connections: " + bcp.getTotalLeased()
      + " in use / " + bcp.getTotalFree()
      + " in pool / total created "
      + bcp.getTotalCreatedConnections();

  }
  return status;
}

代码示例来源:origin: johnewart/gearman-java

conn = connectionPool.getConnection();
if(conn != null)
  st = conn.prepareStatement(fetchJobHandlesQuery);
  rs = st.executeQuery();
  while(rs.next())
    final String jobHandle = rs.getString("job_handle");
    jobHandles.add(jobHandle);
try {
  if(rs != null)
    rs.close();
    conn.close();

代码示例来源:origin: yangbutao/disgear

config = new BoneCPConfig("bonecp-config.xml");
  } catch (Exception e) {
    e.printStackTrace();
  connectionPool = new BoneCP(config); // setup the connection pool
  connection = connectionPool.getConnection(); // fetch a
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt
        .executeQuery("select * from lsmp_lottery_user");
    while (rs.next()) {
      String key = rs.getString("LUSER_NUM");
      String userName = rs.getString("LUSER_NAME");
      String userId = rs.getString("ID");
      String userProvinceNum = rs.getString("LUSER_PROVINCE_NUM");
  connectionPool.shutdown(); // shutdown connection pool.
} catch (SQLException e) {
  e.printStackTrace();
  if (connection != null) {
    try {
      connection.close();
    } catch (SQLException e) {
      e.printStackTrace();

代码示例来源:origin: johnewart/gearman-java

conn = connectionPool.getConnection();
if (conn != null) {
  st = conn.prepareStatement(countQuery);
  rs = st.executeQuery();
  if (rs.next()) {
    return rs.getInt("exceptionCount");
  } else {
    return -1;
try {
  if (rs != null)
    rs.close();
    conn.close();

代码示例来源:origin: datasalt/splout-db

Statement stmt = null;
try {
 connection = connectionPool.getConnection(); // fetch a connection
 stmt = connection.createStatement();
 QueryResult result = null;
 if (stmt.execute(query)) {
  rs = stmt.getResultSet();
  result = convertResultSetToQueryResult(rs, maxResults);
 } else {
 try {
  if (rs != null) {
   rs.close();
   stmt.close();
  connection.close();
 } catch (SQLException e) {
  throw convertException(e);

代码示例来源:origin: johnewart/gearman-java

conn = connectionPool.getConnection();
if(conn != null)
  DatabaseMetaData dbm = conn.getMetaData();
  ResultSet tables = dbm.getTables(null, null, tableName, null);
  if(!tables.next())
    st = conn.prepareStatement(createTableQuery);
    st.executeUpdate();
    st = conn.prepareStatement(createUidIndexQuery);
    st.executeUpdate();
    st = conn.prepareStatement(createJobHandleIndexQuery);
    if(createdTables.next()) {
      LOG.debug("Created exceptions table: " + tableName);
      success = true;

代码示例来源:origin: johnewart/gearman-java

@Override
public void deleteAll() {
  Statement st = null;
  Connection conn = null;
  try {
    conn = connectionPool.getConnection();
    if(conn != null)
    {
      st = conn.createStatement();
      final String deleteAllQuery = String.format("DELETE FROM %s", tableName);
      int deleted = st.executeUpdate(deleteAllQuery);
      LOG.debug("Deleted " + deleted + " jobs...");
    }
  } catch (SQLException se) {
    LOG.error("SQL Error deleting all jobs: " , se);
  } finally {
    try {
      if(st != null)
        st.close();
      if(conn != null)
        conn.close();
    } catch (SQLException innerEx) {
      LOG.debug("Error cleaning up: " + innerEx);
    }
  }
}

代码示例来源:origin: johnewart/gearman-java

@Override
public void delete(final String functionName, final String uniqueID) {
  PreparedStatement st = null;
  Connection conn = null;
  try {
    conn = connectionPool.getConnection();
    if(conn != null)
    {
      st = conn.prepareStatement(deleteJobQuery);
      st.setString(1, functionName);
      st.setString(2, uniqueID);
      int deleted = st.executeUpdate();
      LOG.debug("Deleted " + deleted + " records for " + functionName + "/" +uniqueID);
    }
    deleteCounter.inc();
    pendingCounter.dec();
  } catch (SQLException se) {
    LOG.error("SQL Error deleting job: " , se);
  } finally {
    try {
      if(st != null)
        st.close();
      if(conn != null)
        conn.close();
    } catch (SQLException innerEx) {
      LOG.debug("Error cleaning up: " + innerEx);
    }
  }
}

代码示例来源:origin: stackoverflow.com

pool.shutdown();
  Connection connection = connections.get();
  if (connection != null) {
    connection.commit();
    connection.close();
    connections.set(null);
  Connection connection = connections.get();
  if (connection == null) {
    connection = pool.getConnection();
    connection.setAutoCommit(false);
    connections.set(connection);

代码示例来源:origin: org.apache.sentry/sentry-shaded-miscellaneous

Connection result = null;
Connection oldRawConnection = connectionHandle.getInternalConnection();
String url = this.getConfig().getJdbcUrl();
int acquireRetryAttempts = this.getConfig().getAcquireRetryAttempts();
long acquireRetryDelayInMs = this.getConfig().getAcquireRetryDelayInMs();
AcquireFailConfig acquireConfig = new AcquireFailConfig();
acquireConfig.setAcquireRetryAttempts(new AtomicInteger(acquireRetryAttempts));
acquireConfig.setAcquireRetryDelayInMs(acquireRetryDelayInMs);
acquireConfig.setLogMessage("Failed to acquire connection to "+url);
ConnectionHook connectionHook = this.getConfig().getConnectionHook();
do{ 
  result = null;
  try { 
    result = this.obtainRawInternalConnection();
    tryAgain = false;
    if (acquireRetryAttempts != this.getConfig().getAcquireRetryAttempts()){
      logger.info("Successfully re-established connection to "+url);
    this.getDbIsDown().set(false);
    ConnectionHandle.sendInitSQL(result, this.getConfig().getInitSQL());
  } catch (SQLException e) {
        oldRawConnection.close();

代码示例来源:origin: org.wisdom-framework/wisdom-jdbc-datasources

Connection result = null;
DataSource datasourceBean = this.config.getDatasourceBean();
String url = this.config.getJdbcUrl();
String username = this.config.getUsername();
String password = this.config.getPassword();
Properties props = this.config.getDriverProperties();
  try {
    this.driverInitialized = true;
    result = getConnection(url, username, password, props);
    result.close();
  } catch (SQLException t) {
result = getConnection(url, username, password, props);
  result.setClientInfo(this.clientInfo);

代码示例来源:origin: org.apache.sentry/sentry-shaded-miscellaneous

this.connectionHook = pool.getConfig().getConnectionHook();
this.url = pool.getConfig().getJdbcUrl();
this.finalizableRefs = pool.getFinalizableRefs(); 
this.defaultReadOnly = pool.getConfig().getDefaultReadOnly();
this.defaultCatalog = pool.getConfig().getDefaultCatalog();
this.defaultTransactionIsolationValue = pool.getConfig().getDefaultTransactionIsolationValue();
this.defaultAutoCommit = pool.getConfig().getDefaultAutoCommit();
this.resetConnectionOnClose = pool.getConfig().isResetConnectionOnClose();
this.connectionTrackingDisabled = pool.getConfig().isDisableConnectionTracking();
this.statisticsEnabled = pool.getConfig().isStatisticsEnabled();
this.statistics = pool.getStatistics();
this.detectUnresolvedTransactions = pool.getConfig().isDetectUnresolvedTransactions();
this.detectUnclosedStatements = pool.getConfig().isDetectUnclosedStatements();
this.closeOpenStatements = pool.getConfig().isCloseOpenStatements();
if (this.closeOpenStatements){
  trackedStatement = new MapMaker().makeMap();
this.connectionHook = this.pool.getConfig().getConnectionHook();
this.maxConnectionAgeInMs = pool.getConfig().getMaxConnectionAge(TimeUnit.MILLISECONDS);
this.doubleCloseCheck = pool.getConfig().isCloseConnectionWatch();
this.logStatementsEnabled = pool.getConfig().isLogStatementsEnabled();
int cacheSize = pool.getConfig().getStatementsCacheSize();
if ( (cacheSize > 0) && newConnection ) {
  this.preparedStatementCache = new StatementCache(cacheSize, pool.getConfig().isStatisticsEnabled(), pool.getStatistics());
  this.callableStatementCache = new StatementCache(cacheSize, pool.getConfig().isStatisticsEnabled(), pool.getStatistics());
  this.statementCachingEnabled = true;

代码示例来源:origin: com.github.javaclub/jorm

config = new BoneCPConfig();
    String bonecpXmlFile = getJdbcProperties().getProperty(Environment.POOL_CFG_BONECP);
    AssertUtil.notEmpty(bonecpXmlFile, "The BoneCP xml configuration file path can't be empty.");
      bonecpXmlFile = bonecpXmlFile.substring(10);
    config.setConfigFile(bonecpXmlFile);
  } else {
    config = new BoneCPConfig();	// create a new configuration object
     config.setJdbcUrl(getJdbcProperties().getProperty(Environment.JDBC_URL));	// set the JDBC url
    config.setUsername(getJdbcProperties().getProperty(Environment.USERNAME));	// set the username
    config.setMaxConnectionsPerPartition(poolMaxSize);
  this.bonecp = new BoneCP(config);
  if(LOG.isInfoEnabled()) {
    LOG.info("Fetching a test connnection.");
  conn = bonecp.getConnection();
} catch (Throwable t) {
  t.printStackTrace();
  if(null != conn) {
    try {
      conn.close();
    } catch (SQLException e) {
    } finally {

代码示例来源:origin: org.apache.sentry/sentry-shaded-miscellaneous

ConnectionHook connectionHook = con.getPool().getConfig().getConnectionHook();
int acquireRetryAttempts = con.getPool().getConfig().getAcquireRetryAttempts();
long acquireRetryDelay = con.getPool().getConfig().getAcquireRetryDelayInMs();
AcquireFailConfig acquireConfig = new AcquireFailConfig();
acquireConfig.setAcquireRetryAttempts(new AtomicInteger(acquireRetryAttempts));
  try{
    con.clearStatementCaches(true);
    con.getInternalConnection().close();
  } catch(Throwable t){
    con.setInternalConnection(memorize(con.getPool().obtainInternalConnection(con), con));
  } catch(SQLException e){
    throw con.markPossiblyBroken(e);

代码示例来源:origin: johnewart/gearman-java

@Override
public String getIdentifier() {
  String result = url;
  try {
    Connection connection = connectionPool.getConnection();
    DatabaseMetaData metaData = connection.getMetaData();
    int majorVersion, minorVersion;
    String productName, productVersion;
    majorVersion = metaData.getDatabaseMajorVersion();
    minorVersion = metaData.getDatabaseMinorVersion();
    productName = metaData.getDatabaseProductName();
    productVersion = metaData.getDatabaseProductVersion();
    result = String.format("%s (%s v%d.%d) - %s", productName, productVersion, majorVersion, minorVersion, url);
  } catch (SQLException e) {
    e.printStackTrace();
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

final Connection connection = connectionPool.getConnection();
  ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:mysql://192.0.0.1:3306/database"); // jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
config.setUsername("root"); 
config.setPassword("");
connectionPool = new BoneCP(config);

代码示例来源:origin: org.ddbstoolkit.toolkit.jdbc/ddbstoolkit-jdbc

public JDBCConnectionPool(final String jdbcString, final int numberOfConnection) throws SQLException {
  super();
  this.numberOfConnection = numberOfConnection;
  this.jdbcString = jdbcString;
  BoneCPConfig config = new BoneCPConfig();
   config.setJdbcUrl(jdbcString);
  this.connectionPool = new BoneCP(config);
  this.connectionSession = new HashMap<String, Connection>();
}

相关文章