List of usage examples for org.apache.commons.dbcp PoolingDriver getConnectionPool
public synchronized ObjectPool getConnectionPool(String name) throws SQLException
From source file:ManualPoolingDriverExample.java
public static void printDriverStats() throws Exception { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); ObjectPool connectionPool = driver.getConnectionPool("example"); System.out.println("NumActive: " + connectionPool.getNumActive()); System.out.println("NumIdle: " + connectionPool.getNumIdle()); }
From source file:com.evanmclean.evlib.commons.dbcp.DbcpUtils.java
/** * Close all DBCP pools.//from www . j av a2 s . co m */ public static void closePools() { final PoolingDriver driver = getPoolingDriver(); if (driver != null) { final String[] pns = driver.getPoolNames(); for (String pn : pns) try { final ObjectPool pool = driver.getConnectionPool(pn); if (pool != null) pool.clear(); } catch (Throwable ex) { // empty } } }
From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java
/** * How many are idle in the pool./*from w w w . j a v a2s . c o m*/ * <p> * @return number idle */ public int getNumIdleInPool() { int numIdle = 0; try { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME); ObjectPool connectionPool = driver.getConnectionPool(this.getPoolName()); if (log.isDebugEnabled()) { log.debug(connectionPool); } numIdle = connectionPool.getNumIdle(); } catch (Exception e) { log.error(e); } return numIdle; }
From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java
/** * How many are active in the pool.// ww w .j a v a2 s . c o m * <p> * @return number active */ public int getNumActiveInPool() { int numActive = 0; try { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME); ObjectPool connectionPool = driver.getConnectionPool(this.getPoolName()); if (log.isDebugEnabled()) { log.debug(connectionPool); } numActive = connectionPool.getNumActive(); } catch (Exception e) { log.error(e); } return numActive; }
From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java
/** * @throws Exception/*from ww w. j a v a 2s.c o m*/ */ public void logDriverStats() throws Exception { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME); ObjectPool connectionPool = driver.getConnectionPool(this.getPoolName()); if (connectionPool != null) { if (log.isDebugEnabled()) { log.debug(connectionPool); } if (log.isInfoEnabled()) { log.info("NumActive: " + getNumActiveInPool()); log.info("NumIdle: " + getNumIdleInPool()); } } else { log.warn("Could not find pool."); } }
From source file:org.eclipse.osee.jdbc.internal.PoolFactory.java
public Map<String, String> getPoolStats() { Map<String, String> stats = new LinkedHashMap<String, String>(); PoolingDriver driver = poolingDriver.get(); stats.put("db.pool.driver", poolConfiguration.getPoolConnectionDriver()); String poolVersion = String.format("%s.%s", driver.getMajorVersion(), driver.getMinorVersion()); stats.put("db.pool.version", poolVersion); String[] names = driver.getPoolNames(); int count = 0; for (String name : names) { try {// w w w . j a v a 2s .c o m ObjectPool<?> pool = driver.getConnectionPool(name); stats.put(String.format("db.pool.%s.id", count), name); stats.put(String.format("db.pool.%s.active", count), String.valueOf(pool.getNumActive())); stats.put(String.format("db.pool.%s.idle", count), String.valueOf(pool.getNumIdle())); } catch (SQLException ex) { // Do Nothing } finally { count++; } } return stats; }
From source file:org.infoglue.cms.util.workflow.InfoGlueJDBCPropertySet.java
public void printDriverStats() throws Exception { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); ObjectPool connectionPool = driver.getConnectionPool("infoGlueJDBCPropertySet"); if (logger.isInfoEnabled()) { logger.info("NumActive: " + connectionPool.getNumActive()); logger.info("NumIdle: " + connectionPool.getNumIdle()); }// www. j a v a 2 s . c o m }
From source file:org.openbravo.database.ConnectionProviderImpl.java
public ObjectPool getPool(String poolName) throws PoolNotFoundException { if (poolName == null || poolName.equals("")) throw new PoolNotFoundException("Couldnt get an unnamed pool"); ObjectPool connectionPool = null;//from w ww . j a v a2 s .c o m try { PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); connectionPool = driver.getConnectionPool(contextName + "_" + poolName); } catch (SQLException ex) { log4j.error(ex); } if (connectionPool == null) throw new PoolNotFoundException(poolName + " not found"); else return connectionPool; }
From source file:org.opencms.db.CmsDriverManager.java
/** * Returns the number of active connections managed by a pool.<p> * /*from w w w .ja va 2 s. co m*/ * @param dbPoolUrl the url of a pool * @return the number of active connections * @throws CmsDbException if something goes wrong */ public int getActiveConnections(String dbPoolUrl) throws CmsDbException { try { for (Iterator<PoolingDriver> i = m_connectionPools.iterator(); i.hasNext();) { PoolingDriver d = i.next(); ObjectPool p = d.getConnectionPool(dbPoolUrl); return p.getNumActive(); } } catch (Exception exc) { CmsMessageContainer message = Messages.get().container(Messages.ERR_ACCESSING_POOL_1, dbPoolUrl); throw new CmsDbException(message, exc); } CmsMessageContainer message = Messages.get().container(Messages.ERR_UNKNOWN_POOL_URL_1, dbPoolUrl); throw new CmsDbException(message); }
From source file:org.opencms.db.CmsDriverManager.java
/** * Returns the number of idle connections managed by a pool.<p> * /* w ww .j av a 2s . com*/ * @param dbPoolUrl the url of a pool * @return the number of idle connections * @throws CmsDbException if something goes wrong */ public int getIdleConnections(String dbPoolUrl) throws CmsDbException { try { for (Iterator<PoolingDriver> i = m_connectionPools.iterator(); i.hasNext();) { PoolingDriver d = i.next(); ObjectPool p = d.getConnectionPool(dbPoolUrl); return p.getNumIdle(); } } catch (Exception exc) { CmsMessageContainer message = Messages.get().container(Messages.ERR_ACCESSING_POOL_1, dbPoolUrl); throw new CmsDbException(message, exc); } CmsMessageContainer message = Messages.get().container(Messages.ERR_UNKNOWN_POOL_URL_1, dbPoolUrl); throw new CmsDbException(message); }