db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionFactoryPooledImpl.java
Date Sun, 24 Jul 2005 23:40:18 GMT
arminw      2005/07/24 16:40:18

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE ConnectionFactoryPooledImpl.java
  Log:
  improve error message, minor changes
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.15.2.7  +37 -19    db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
  
  Index: ConnectionFactoryPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
  retrieving revision 1.15.2.6
  retrieving revision 1.15.2.7
  diff -u -r1.15.2.6 -r1.15.2.7
  --- ConnectionFactoryPooledImpl.java	30 Apr 2005 20:55:15 -0000	1.15.2.6
  +++ ConnectionFactoryPooledImpl.java	24 Jul 2005 23:40:18 -0000	1.15.2.7
  @@ -39,7 +39,6 @@
    * connections for different JdbcConnectionDescriptors
    * using Commons Pool API.
    *
  - * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>.
    * @version $Id$
    * @see <a href="http://jakarta.apache.org/commons/pool/">Commons Pool Website</a>
    */
  @@ -47,12 +46,15 @@
   {
   
       private Logger log = LoggerFactory.getLogger(ConnectionFactoryPooledImpl.class);
  -    private Map connectionPools = new HashMap();
  +    /** Key=PBKey, value=ObjectPool. */
  +    private Map poolMap = new HashMap();
  +    /** Synchronize object for operations not synchronized on Map only. */
  +    private Object poolSynch = new Object();
   
       public void releaseJdbcConnection(JdbcConnectionDescriptor jcd, Connection con)
               throws LookupException
       {
  -        final ObjectPool op = (ObjectPool) connectionPools.get(jcd.getPBKey());
  +        final ObjectPool op = (ObjectPool) poolMap.get(jcd.getPBKey());
           try
           {
               /* mkalen: NB - according to the Commons Pool API we should _not_ perform
  @@ -75,14 +77,14 @@
   
       public Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd) throws LookupException
       {
  -        ObjectPool op = (ObjectPool) connectionPools.get(jcd.getPBKey());
  +        ObjectPool op = (ObjectPool) poolMap.get(jcd.getPBKey());
           if (op == null)
           {
  -            log.info("Create new connection pool:" + jcd);
  -            op = createConnectionPool(jcd);
  -            synchronized (connectionPools)
  +            synchronized (poolSynch)
               {
  -                connectionPools.put(jcd.getPBKey(), op);
  +                log.info("Create new connection pool:" + jcd);
  +                op = createConnectionPool(jcd);
  +                poolMap.put(jcd.getPBKey(), op);
               }
           }
           final Connection conn;
  @@ -92,15 +94,31 @@
           }
           catch (NoSuchElementException e)
           {
  -            throw new LookupException("Could not borrow connection from pool, " +
  -                                      "ObjectPool exhausted for jcd-alias " + jcd.getJcdAlias()
+
  -                                      " Active/Idle instances=" + op.getNumActive() + "/"
+
  -                                      op.getNumIdle());
  +            int active = 0;
  +            int idle = 0;
  +            try
  +            {
  +                active = op.getNumActive();
  +                idle = op.getNumIdle();
  +            }
  +            catch(Exception ignore){}
  +            throw new LookupException("Could not borrow connection from pool, seems ObjectPool
is exhausted." +
  +                    " Active/Idle instances in pool=" + active + "/" +  idle
  +                    + ". "+ JdbcConnectionDescriptor.class.getName() + ":  " + jcd, e);
           }
           catch (Exception e)
           {
  -            throw new LookupException("Could not borrow connection from pool - " +
  -                    JdbcConnectionDescriptor.class.getName() + ":  " + jcd, e);
  +            int active = 0;
  +            int idle = 0;
  +            try
  +            {
  +                active = op.getNumActive();
  +                idle = op.getNumIdle();
  +            }
  +            catch(Exception ignore){}
  +            throw new LookupException("Could not borrow connection from pool." +
  +                    " Active/Idle instances in pool=" + active + "/" +  idle
  +                    + ". "+ JdbcConnectionDescriptor.class.getName() + ":  " + jcd, e);
           }
           return conn;
       }
  @@ -123,11 +141,10 @@
        */
       public void releaseAllResources()
       {
  -        super.releaseAllResources();
  -        synchronized (connectionPools)
  +        synchronized (poolSynch)
           {
  -            Collection pools = connectionPools.values();
  -            connectionPools = new HashMap(connectionPools.size());
  +            Collection pools = poolMap.values();
  +            poolMap = new HashMap(poolMap.size());
               ObjectPool op = null;
               for (Iterator iterator = pools.iterator(); iterator.hasNext();)
               {
  @@ -142,6 +159,7 @@
                   }
               }
           }
  +        super.releaseAllResources();
       }
   
       //**************************************************************************************
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message