@Override
  public DataSourceInfo getInfo(final Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;
    if (canMap(resource)) {
      final BoneCPDataSource source = (BoneCPDataSource) resource;
      BoneCP pool;
      try {
        pool = source.getPool();
      } catch (NoSuchMethodError ex) {
        logger.trace("", ex);
        // This is an older version of BoneCP (pre-0.8.0)
        final Field poolField = BoneCPDataSource.class.getDeclaredField("pool");
        poolField.setAccessible(true);
        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);
      dataSourceInfo.setType("bonecp");
    }
    return dataSourceInfo;
  }
Exemple #2
0
 // call at end of program to close all physical threads
 public static void shutdownConnectionPool() {
   try {
     BoneCP connectionPool = DatabaseConnection.getConnectionPool();
     Logger.writeLog("Shutting down connection pool.", Logger.LOG_TYPE_VERBOSE);
     if (connectionPool != null) {
       connectionPool.shutdown();
       Logger.writeLog("Connection pooling is destroyed successfully.", Logger.LOG_TYPE_VERBOSE);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 @Override
 public void ShutdownPool() {
   // TODO Auto-generated method stub
   if (_boneCP != null) {
     _boneCP.shutdown();
   }
 }
 @Override
 public Connection GetConnection() {
   // TODO Auto-generated method stub
   if (_boneCP == null) {
     System.out.println(String.format("line 56 ConnectionManager cp=null"));
   }
   try {
     _connection = _boneCP.getConnection();
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     System.out.println(e);
   }
   try {
     System.out.println(_connection.getCatalog());
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return _connection;
 }
  public void shutDown() throws SQLException {

    closeAllConnections();
    connectionPool.close();
  }
  public Connection getConnection() throws SQLException {

    Connection returnConnection = connectionPool.getConnection();
    openConnections.add(returnConnection);
    return returnConnection;
  }