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/util ProxyHelper.java
Date Sat, 04 Oct 2003 17:48:00 GMT
arminw      2003/10/04 10:48:00

  Modified:    src/java/org/apache/ojb/odmg TransactionImpl.java
               src/java/org/apache/ojb/broker/util ProxyHelper.java
  Log:
  - fix NullpointerException on doClose-method
  in TransactionImpl, posted by several user
  - minor changes in doClose-method
  
  Revision  Changes    Path
  1.47      +49 -42    db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- TransactionImpl.java	3 Oct 2003 12:39:40 -0000	1.46
  +++ TransactionImpl.java	4 Oct 2003 17:48:00 -0000	1.47
  @@ -61,8 +61,8 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  +import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.accesslayer.MaterializationListener;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -71,6 +71,7 @@
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.util.ArrayIterator;
   import org.apache.ojb.broker.util.GUID;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.configuration.Configurable;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  @@ -89,7 +90,6 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
  -import java.util.HashMap;
   import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.Vector;
  @@ -123,7 +123,7 @@
       private boolean useImplicitLocking;
       private String txGUID;
       protected PersistenceBroker broker = null;
  -    private HashMap registeredForLock = new HashMap();
  +    private ArrayList registeredForLock = new ArrayList();
       private OJBTxManager txManager;
   
       /**
  @@ -244,7 +244,7 @@
           if (log.isDebugEnabled()) log.debug("lock object was called on tx " + this);
           checkOpen();
   
  -        if (!(obj instanceof VirtualProxy) && !(obj instanceof Proxy))
  +        if (!ProxyHelper.isProxy(obj))
           {
               ClassDescriptor cld = this.getBroker().getClassDescriptor(obj.getClass());
               if (!cld.isAcceptLocks())
  @@ -320,7 +320,7 @@
           if broker isn't in PB-tx, start tx
           */
           if (log.isDebugEnabled()) log.debug("call beginTransaction() on PB instance");
  -        if(!broker.isInTransaction()) broker.beginTransaction();
  +        if(!getBroker().isInTransaction()) broker.beginTransaction();
   
           // Notify objects of impending commits.
           Enumeration enum = objectEnvelopeTable.elements();
  @@ -340,7 +340,7 @@
               item = (ObjectEnvelope) enum.nextElement();
               item.afterCommit();
           }
  -        registeredForLock = new HashMap();
  +        registeredForLock.clear();
       }
   
       /**
  @@ -382,11 +382,6 @@
   
           try
           {
  -            // clear the temporary used named roots map
  -            // we should do that, because same tx instance
  -            // could be used several times
  -            myNrm.clear();
  -
               Enumeration enum = objectEnvelopeTable.elements();
               while (enum.hasMoreElements())
               {
  @@ -399,7 +394,6 @@
               {
                   removeLock(it.next(), Transaction.WRITE);
               }
  -            unmaterializedLocks.clear();
   
               // this tx is no longer interested in materialization callbacks
               unRegisterFromAllIndirectionHandlers();
  @@ -409,31 +403,47 @@
               /**
                * MBAIRD: Be nice and close the table to release all refs
                */
  -            try
  -            {
  -                objectEnvelopeTable.refresh();
  -                // we reuse ObjectEnvelopeTable instance
  -                // objectEnvelopeTable = null;
  -            }
  -            catch (Exception e)
  -            {
  -                if (log.isDebugEnabled())
  -                {
  -                    log.debug("error closing object envelope table : " + e.getMessage());
  -                    e.printStackTrace();
  -                }
  -            }
               if (log.isDebugEnabled())
                   log.debug("Close Transaction and release current PB " + broker + " on tx
" + this);
               // remove current thread from LocalTxManager
               // to avoid problems for succeeding calls of the same thread
               txManager.deregisterTx(this);
  -            if (broker != null)
  +            // now cleanup and prepare for reuse
  +            refresh();
  +        }
  +    }
  +
  +    /**
  +     * cleanup tx and prepare for reuse
  +     */
  +    protected void refresh()
  +    {
  +        try
  +        {
  +            objectEnvelopeTable.refresh();
  +            // we reuse ObjectEnvelopeTable instance
  +            // objectEnvelopeTable = null;
  +        }
  +        catch (Exception e)
  +        {
  +            if (log.isDebugEnabled())
               {
  -                broker.close();
  -                broker = null;
  +                log.debug("error closing object envelope table : " + e.getMessage());
  +                e.printStackTrace();
               }
           }
  +        if(broker != null && !broker.isClosed())
  +        {
  +            broker.close();
  +        }
  +        // clear the temporary used named roots map
  +        // we should do that, because same tx instance
  +        // could be used several times
  +        myNrm.clear();
  +        broker = null;
  +        registeredForLock.clear();
  +        unmaterializedLocks.clear();
  +        m_txStatus = Status.STATUS_NO_TRANSACTION;
       }
   
       /**
  @@ -775,7 +785,7 @@
        * OJB implicitely acquires read locks on registered objects.
        */
       private synchronized void register(Object newTxObject, int lockMode)
  -            throws LockNotGrantedException, PersistenceBrokerException, IllegalAccessException
  +            throws LockNotGrantedException, PersistenceBrokerException
       {
           Object objectToRegister = newTxObject;
           IndirectionHandler handler = null;
  @@ -860,11 +870,8 @@
       {
           try
           {
  -            if ((!(obj instanceof VirtualProxy))
  -                && (!(obj instanceof Proxy))
  +            if ((!ProxyHelper.isProxy(obj))
                   && (ref != null))
  -               // && (!(ref instanceof VirtualProxy))
  -               // && (!(ref instanceof Proxy)))
               {
               	Object refInstance = ref;
               	if (ref instanceof VirtualProxy)
  @@ -1044,10 +1051,11 @@
       private void lockReferences(ClassDescriptor cld, Object newTxObject, int lockMode)
               throws PersistenceBrokerException
       {
  -        if ((newTxObject != null)
  -                && !(newTxObject instanceof VirtualProxy)
  -                && !(newTxObject instanceof Proxy))
  -            registeredForLock.put(newTxObject, newTxObject);
  +        if ((newTxObject != null) && !ProxyHelper.isProxy(newTxObject))
  +        {
  +            registeredForLock.add(newTxObject);
  +        }
  +
           Iterator i = cld.getObjectReferenceDescriptors().iterator();
           while (i.hasNext())
           {
  @@ -1055,9 +1063,9 @@
               Object refObj = rds.getPersistentField().get(newTxObject);
               if (refObj != null)
               {
  -                if ((refObj instanceof VirtualProxy) || (refObj instanceof Proxy))
  +                if (ProxyHelper.isProxy(refObj))
                       lock(refObj, lockMode);
  -                else if (!registeredForLock.containsKey(refObj))
  +                else if (!registeredForLock.contains(refObj))
                   {
                       lock(refObj, lockMode);
                   }
  @@ -1219,5 +1227,4 @@
       {
       	useImplicitLocking = value;
       }
  -
   }
  
  
  
  1.16      +13 -1     db-ojb/src/java/org/apache/ojb/broker/util/ProxyHelper.java
  
  Index: ProxyHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ProxyHelper.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ProxyHelper.java	18 Jul 2003 17:22:28 -0000	1.15
  +++ ProxyHelper.java	4 Oct 2003 17:48:00 -0000	1.16
  @@ -56,12 +56,15 @@
   
   //#ifdef JDK13
   import java.lang.reflect.Proxy;
  +import java.lang.reflect.InvocationHandler;
   //#else
   /*
   import com.develop.java.lang.reflect.Proxy;
  +import com.develop.java.lang.reflect.InvocationHandler;
   */
   //#endif
   import java.lang.reflect.Constructor;
  +
   import java.util.List;
   import java.util.Set;
   
  @@ -340,4 +343,13 @@
           return collectionProxyConstructor;
       }
   
  +    /**
  +     * Returns <tt>true</tt> if the given object is a {@link java.lang.reflect.Proxy}
  +     * or a {@link VirtualProxy} instance.
  +     */
  +    public static boolean isProxy(Object proxyOrObject)
  +    {
  +        return ((proxyOrObject instanceof Proxy) && Proxy.isProxyClass(proxyOrObject.getClass()))
  +                || proxyOrObject instanceof VirtualProxy;
  +    }
   }
  
  
  

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