/** Create dataSource object using given parameters */
  public DataSource setupDataSource(
      String connectionURL, String username, String password, int minIdle, int maxActive)
      throws Exception {
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    connectionPool.setMinIdle(minIdle);
    connectionPool.setMaxActive(maxActive);
    connectionPool.setMaxWait(1000 * 60);

    pool = connectionPool;
    ConnectionFactory connectionFactory =
        new DriverManagerConnectionFactory(connectionURL, username, password);
    PoolableConnectionFactory factory =
        new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);

    pool.setFactory(factory);
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
    dataSource.setAccessToUnderlyingConnectionAllowed(true);
    return dataSource;
  }
 private void initPool() {
   PoolConfig pconfig = Db.getInstance().getPoolConfig();
   int poolSize = Db.supports(Capability.ROW_LEVEL_LOCKING) ? pconfig.mPoolSize : 1;
   // if no row lock, we need serial access to the underlying db file
   // still need external synchronization for now since other connections to zimbra.db can occur
   // through DbPool
   mConnectionPool =
       new GenericObjectPool(null, poolSize, GenericObjectPool.WHEN_EXHAUSTED_BLOCK, -1, poolSize);
   ConnectionFactory cfac = ZimbraConnectionFactory.getConnectionFactory(pconfig);
   boolean defAutoCommit = false, defReadOnly = false;
   new PoolableConnectionFactory(cfac, mConnectionPool, null, null, defReadOnly, defAutoCommit);
   try {
     PoolingDataSource pds = new PoolingDataSource(mConnectionPool);
     pds.setAccessToUnderlyingConnectionAllowed(true);
     Db.getInstance().startup(pds, pconfig.mPoolSize);
     mDataSource = pds;
   } catch (SQLException e) {
     ZimbraLog.system.error("failed to initialize offline db pool", e);
   }
 }