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/core PersistenceBrokerFactorySyncImpl.java
Date Wed, 18 Feb 2004 19:39:59 GMT
arminw      2004/02/18 11:39:59

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerFactorySyncImpl.java
  Log:
  do real close (return to pool, close connection)
  of used PB instance when not in a JTA tx to avoid
  exhausted connection pool on appServer side
  
  Revision  Changes    Path
  1.2       +31 -15    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java
  
  Index: PersistenceBrokerFactorySyncImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceBrokerFactorySyncImpl.java	9 Jan 2004 19:29:37 -0000	1.1
  +++ PersistenceBrokerFactorySyncImpl.java	18 Feb 2004 19:39:59 -0000	1.2
  @@ -33,7 +33,7 @@
    * This may will be deprecated when we implemented a full JCA compliant connector.
    * <br/>
    * When a new {@link PersistenceBroker} instance is created in method {@link #wrapBrokerWithPoolingHandle}
  - * the given PB instance is wrapped with {@link PersistenceBrokerSync} before it was put
to the PB-pool.
  + * the given PB instance is wrapped with {@link PersistenceBrokerSyncImpl} before it was
put to the PB-pool.
    * When a PB instance was requested class try to lookup the current JTA transaction in
    * {@link #wrapRequestedBrokerInstance} before the pooled PB instance was wrapped with
the PB handle.
    * If a running tx was found the PB instance was registered with the transaction using
the
  @@ -65,21 +65,21 @@
       protected PersistenceBroker wrapBrokerWithPoolingHandle(PersistenceBroker broker, KeyedObjectPool
pool)
       {
           // wrap real PB instance with an extended version of pooling PB
  -        return new PersistenceBrokerSync(broker, pool);
  +        return new PersistenceBrokerSyncImpl(broker, pool);
       }
   
       protected PersistenceBroker wrapRequestedBrokerInstance(PersistenceBroker broker)
       {
           // all PB instance should be of this type
  -        if (!(broker instanceof PersistenceBrokerSync))
  +        if (!(broker instanceof PersistenceBrokerSyncImpl))
           {
  -            throw new PBFactoryException("Expect instance of " + PersistenceBrokerSync.class
  +            throw new PBFactoryException("Expect instance of " + PersistenceBrokerSyncImpl.class
                       + ", found " + broker.getClass());
           }
           /*
           Before we return the PB handle, we jump into the running JTA tx
           */
  -        PersistenceBrokerSync pb = (PersistenceBrokerSync) broker;
  +        PersistenceBrokerSyncImpl pb = (PersistenceBrokerSyncImpl) broker;
           try
           {
               // search for an active tx
  @@ -161,11 +161,11 @@
       //****************************************************
       // inner class
       //****************************************************
  -    public static class PersistenceBrokerSync extends PoolablePersistenceBroker implements
Synchronization
  +    public static class PersistenceBrokerSyncImpl extends PoolablePersistenceBroker implements
Synchronization
       {
  -        private Logger log = LoggerFactory.getLogger(PersistenceBrokerSync.class);
  +        private Logger log = LoggerFactory.getLogger(PersistenceBrokerSyncImpl.class);
   
  -        public PersistenceBrokerSync(PersistenceBroker broker, KeyedObjectPool pool)
  +        public PersistenceBrokerSyncImpl(PersistenceBroker broker, KeyedObjectPool pool)
           {
               super(broker, pool);
           }
  @@ -175,7 +175,7 @@
               if (log.isDebugEnabled()) log.debug("beforeCompletion was called, nothing to
do");
               ConnectionManagerIF cm = serviceConnectionManager();
               if(cm.isBatchMode()) cm.executeBatch();
  -            // close connection immediately to avoid bad reports from server con-pool
  +            // close connection immediately when in JTA-tx to avoid bad reports from server
con-pool
               cm.releaseConnection();
           }
   
  @@ -228,11 +228,27 @@
   
           public boolean close()
           {
  -            if (log.isDebugEnabled()) log.debug("PB close was called, but do not real close
PB instance");
  -            /*
  -            don't really close (return to pool) the underlying PB instance. As recently
  -            as the JTA was completed we can return PB instance to pool
  -            */
  +            if(!isInTransaction())
  +            {
  +                if (log.isDebugEnabled())
  +                    log.debug("PB close was called, pass the close call to underlying PB
instance");
  +                /*
  +                if we not in JTA-tx, we close PB instance in a "normal" way. The PB.close()
  +                should also release the used connection.
  +                */
  +                super.close();
  +            }
  +            else
  +            {
  +                /*
  +                if in JTA-tx, we don't really close the underlying PB instance (return
to PB
  +                instance to pool, release used connection). As recently as the JTA was
  +                completed we can return PB instance to pool. Thus after tx completion method
  +                doRealClose() was called to close (return to pool) underlying PB instance.
  +                */
  +                if (log.isDebugEnabled())
  +                    log.debug("PB close was called, but do not close PB instance when in
JTA-tx");
  +            }
               return true;
           }
   
  
  
  

---------------------------------------------------------------------
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