You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2004/02/08 14:19:47 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker Identity.java

tomdz       2004/02/08 05:19:47

  Modified:    src/java/org/apache/ojb/odmg TransactionImpl.java
                        ObjectEnvelope.java
               src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
                        BaseConnection.java
               src/java/org/apache/ojb/otm/copy
                        MetadataObjectCopyStrategy.java
               src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
                        ProxyHelper.java
               src/java/org/apache/ojb/broker/accesslayer
                        PlainPrefetcher.java StatementsForClassImpl.java
               src/java/org/apache/ojb/broker Identity.java
  Log:
  Unified proxy handling so that only those classes that actually create proxy objects have to use Proxy/VirtualProxy. All other classes now use ProxyHelper and IndirectionHandler. Also contains a first fix that only identifies those Proxy objects as ojb-proxies that have IndirectionHandler as their invocation handler.
  
  Revision  Changes    Path
  1.52      +8 -46     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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- TransactionImpl.java	4 Jan 2004 01:32:10 -0000	1.51
  +++ TransactionImpl.java	8 Feb 2004 13:19:46 -0000	1.52
  @@ -62,7 +62,6 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.accesslayer.MaterializationListener;
  @@ -96,15 +95,6 @@
   import java.util.Vector;
   import java.util.Arrays;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -
  -
   /**
    *
    * Implementation of Transaction for org.odmg.Transaction.
  @@ -803,14 +793,7 @@
           IndirectionHandler handler = null;
   
           // Proxies must be treated specially
  -        if (newTxObject instanceof VirtualProxy)
  -        {
  -            handler = VirtualProxy.getIndirectionHandler((VirtualProxy) newTxObject);
  -        }
  -        else if (newTxObject instanceof Proxy)
  -        {
  -            handler = (IndirectionHandler) Proxy.getInvocationHandler(newTxObject);
  -        }
  +        handler = ProxyHelper.getIndirectionHandler(newTxObject);
   
           /*
           if the object is a Proxy there are two options:
  @@ -882,20 +865,9 @@
       {
           try
           {
  -            if ((!ProxyHelper.isProxy(obj))
  -                && (ref != null))
  +            if (!ProxyHelper.isProxy(obj) && (ref != null))
               {
  -            	Object refInstance = ref;
  -            	if (ref instanceof VirtualProxy)
  -            	{
  -            		refInstance = ((VirtualProxy) ref).getRealSubject();
  -            	}
  -            	else if (ref instanceof Proxy)
  -            	{
  -            		IndirectionHandler ih = (IndirectionHandler) Proxy.getInvocationHandler(ref);
  -            		refInstance = ih.getRealSubject();
  -            	}
  -
  +            	Object refInstance = ProxyHelper.getRealObject(ref);
                   ClassDescriptor objCld = this.getBroker().getClassDescriptor(obj.getClass());
                   org.apache.ojb.broker.metadata.FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
   
  @@ -1001,9 +973,9 @@
                       while (colIterator.hasNext())
                       {
                           Object item = colIterator.next();
  -                        if (Proxy.isProxyClass(item.getClass()))
  +                        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(item);
  +                        if (handler != null)
                           {
  -                            IndirectionHandler handler = (IndirectionHandler) Proxy.getInvocationHandler(item);
                               if (!handler.alreadyMaterialized())
                               {
                                   continue;
  @@ -1013,18 +985,6 @@
                                   item = handler.getRealSubject();
                               }
                           }
  -                        if (item instanceof VirtualProxy)
  -                        {
  -                            VirtualProxy proxy = (VirtualProxy) item;
  -                            if (!proxy.alreadyMaterialized())
  -                            {
  -                                continue;
  -                            }
  -                            else
  -                            {
  -                                item = proxy.getRealSubject();
  -                            }
  -                        }
                           //if itemCld refers to an interface the foreignKeyFieldDescriptors
                           //have to be computed again for each concrete class
                           if (itemCld.isInterface())
  @@ -1076,7 +1036,9 @@
               if (refObj != null)
               {
                   if (ProxyHelper.isProxy(refObj))
  +                {    
                       lock(refObj, lockMode);
  +                }
                   else if (!registeredForLock.contains(refObj))
                   {
                       lock(refObj, lockMode);
  
  
  
  1.27      +7 -23     db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ObjectEnvelope.java	7 Jan 2004 11:41:19 -0000	1.26
  +++ ObjectEnvelope.java	8 Feb 2004 13:19:47 -0000	1.27
  @@ -61,7 +61,6 @@
    */
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -81,14 +80,6 @@
   import java.util.Iterator;
   import java.util.Map;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -
   /**
    * ObjectEnvelope is used during ODMG transactions as a wrapper for a persistent objects declaration
    *
  @@ -267,30 +258,23 @@
                * if it's been materialized, we put it in the map, because it could change.
                * if it hasn't been materialized, it hasn't changed.
                *
  -             * Also handle virtual proxies.
  +             * Also handles virtual proxies.
                */
  -            if ((temp != null) && (Proxy.isProxyClass(temp.getClass())))
  +            IndirectionHandler handler = ProxyHelper.getIndirectionHandler(temp);
  +
  +            if (handler != null)
               {
                   /**
                    * only register if the proxy has been materialized
                    * if it's materialized later and the map is compared, it will
                    * trigger the update
                    */
  -                IndirectionHandler handler = (IndirectionHandler) Proxy.getInvocationHandler(temp);
                   fieldValues.put(rds, handler.getIdentity());
               }
  -            else if ((temp!=null) && (temp instanceof VirtualProxy))
  -            {
  -                /**
  -                 * only register if the virtual proxy has been materialized
  -                 * if it's materialized later and the map is compared, it will
  -                 * trigger the update
  -                 */
  -                VirtualProxy proxy = (VirtualProxy) temp;
  -                fieldValues.put(rds, VirtualProxy.getIndirectionHandler(proxy).getIdentity());
  -            }
               else
  -                fieldValues.put(rds,temp);
  +            {    
  +                fieldValues.put(rds, temp);
  +            }
   		}
           /**
            * MBAIRD
  
  
  
  1.33      +2 -29     db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
  
  Index: ConcreteEditingContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ConcreteEditingContext.java	5 Jan 2004 01:40:00 -0000	1.32
  +++ ConcreteEditingContext.java	8 Feb 2004 13:19:47 -0000	1.33
  @@ -54,13 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
   import java.lang.reflect.Array;
   import java.math.BigDecimal;
   import java.util.ArrayList;
  @@ -78,7 +71,6 @@
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.accesslayer.CollectionProxy;
   import org.apache.ojb.broker.accesslayer.CollectionProxyListener;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
  @@ -192,7 +184,7 @@
   
           if (newObj != null)
           {
  -            handler = getIndirectionHandler(newObj);
  +            handler = ProxyHelper.getIndirectionHandler(newObj);
               if ((handler != null) && handler.alreadyMaterialized())
               {
                   newObj = handler.getRealSubject();
  @@ -693,25 +685,6 @@
           releaseLocksAndClear();
       }
   
  -    /**
  -     * @return IndirectionHandler for the proxy object or null
  -     */
  -    private static IndirectionHandler getIndirectionHandler(Object object)
  -    {
  -        if (Proxy.isProxyClass(object.getClass()))
  -        {
  -            return (IndirectionHandler) Proxy.getInvocationHandler(object);
  -        }
  -        else if (object instanceof VirtualProxy)
  -        {
  -            return VirtualProxy.getIndirectionHandler((VirtualProxy) object);
  -        }
  -        else
  -        {
  -            return null;
  -        }
  -    }
  -
       private void removeMaterializationListener()
       {
           for (Iterator it = _order.iterator(); it.hasNext();)
  @@ -1476,7 +1449,7 @@
               object = theObject;
               if (object != null)
               {
  -                handler = getIndirectionHandler(object);
  +                handler = ProxyHelper.getIndirectionHandler(object);
                   if ((handler != null) && handler.alreadyMaterialized())
                   {
                       object = handler.getRealSubject();
  
  
  
  1.28      +2 -28     db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java
  
  Index: BaseConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- BaseConnection.java	5 Feb 2004 18:33:29 -0000	1.27
  +++ BaseConnection.java	8 Feb 2004 13:19:47 -0000	1.28
  @@ -56,11 +56,11 @@
   
   import org.apache.ojb.broker.*;
   import org.apache.ojb.broker.cache.ObjectCache;
  -import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.accesslayer.OJBIterator;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.ReportQuery;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
   import org.apache.ojb.broker.util.configuration.Configurator;
   import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
  @@ -73,13 +73,6 @@
   import org.odmg.ODMGRuntimeException;
   import org.odmg.OQLQuery;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.ListIterator;
  @@ -154,25 +147,6 @@
           return _tx;
       }
   
  -    private static boolean isMaterialized(Object object)
  -    {
  -        IndirectionHandler handler;
  -
  -        if (Proxy.isProxyClass(object.getClass()))
  -        {
  -            handler = (IndirectionHandler) Proxy.getInvocationHandler(object);
  -        }
  -        else if (object instanceof VirtualProxy)
  -        {
  -            handler = VirtualProxy.getIndirectionHandler((VirtualProxy) object);
  -        }
  -        else
  -        {
  -            return true;
  -        }
  -        return handler.alreadyMaterialized();
  -    }
  -
       //////////////////////////////////////
       // OTMConnection protocol
       //////////////////////////////////////
  @@ -189,7 +163,7 @@
   
           object = _editingContext.lookup(oid);
   
  -        if ((object == null) || !isMaterialized(object))
  +        if ((object == null) || !ProxyHelper.isMaterialized(object))
           {
               object = _pb.getObjectByIdentity(oid);
               if (object != null)
  
  
  
  1.15      +4 -12     db-ojb/src/java/org/apache/ojb/otm/copy/MetadataObjectCopyStrategy.java
  
  Index: MetadataObjectCopyStrategy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/copy/MetadataObjectCopyStrategy.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MetadataObjectCopyStrategy.java	25 Oct 2003 23:59:27 -0000	1.14
  +++ MetadataObjectCopyStrategy.java	8 Feb 2004 13:19:47 -0000	1.15
  @@ -54,26 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.metadata.*;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.accesslayer.CollectionProxy;
   import org.apache.ojb.broker.util.ConstructorHelper;
   import org.apache.ojb.broker.util.IdentityMapFactory;
  +import org.apache.ojb.broker.util.ProxyHelper;
   
   import java.lang.reflect.Constructor;
   import java.util.Map;
   import java.util.Collection;
   import java.util.Iterator;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -
   /**
    * recursively copies an object based on the ClassDescriptor
    * User: matthew.baird
  @@ -117,11 +109,11 @@
           /**
            * if this is a proxy, just copy the proxy, don't materialize it, and stop recursing
            */
  -        if (toCopy instanceof VirtualProxy)
  +        if (ProxyHelper.isVirtualOjbProxy(toCopy))
           {
               return _reflective.copy(toCopy);
           }
  -        else if (Proxy.isProxyClass(toCopy.getClass()))
  +        else if (ProxyHelper.isNormalOjbProxy(toCopy))
           {
               return _serialize.copy(toCopy);
           }
  @@ -218,7 +210,7 @@
                           /**
                           * if this is a proxy, just copy the proxy, don't materialize it, and stop recursing
                           */
  -                        if (obj instanceof Proxy)
  +                        if (ProxyHelper.isNormalOjbProxy(obj))  // tomdz: what about VirtualProxy ? 
                           {
                               newCollection.add(obj);
                           }
  
  
  
  1.79      +3 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- ClassDescriptor.java	7 Jan 2004 19:11:10 -0000	1.78
  +++ ClassDescriptor.java	8 Feb 2004 13:19:47 -0000	1.79
  @@ -81,6 +81,7 @@
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.ClassHelper;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.SqlHelper;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.Configurator;
  @@ -1402,7 +1403,7 @@
           // proxy is optional
           if (theProxyClass != null)
   	{
  -	    if (Proxy.isProxyClass(theProxyClass))
  +	    if (ProxyHelper.isNormalOjbProxy(theProxyClass))   // tomdz: What about VirtualProxy ?
               {
           	result += "    " + tags.getAttribute(CLASS_PROXY, "dynamic") + eol;
       	    }
  
  
  
  1.36      +4 -17     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- BrokerHelper.java	6 Feb 2004 13:01:53 -0000	1.35
  +++ BrokerHelper.java	8 Feb 2004 13:19:47 -0000	1.36
  @@ -62,7 +62,6 @@
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryBySQL;
  @@ -83,7 +82,6 @@
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   //#ifdef JDK13
  -import java.lang.reflect.Proxy;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
  @@ -196,22 +194,11 @@
   	 */
   	public ValueContainer[] getKeyValues(ClassDescriptor cld, Object objectOrProxy, boolean convertToSql) throws PersistenceBrokerException
   	{
  -		/*
  -		arminw
  -		TODO: Check it out. Because the isProxyClass method is costly and most objects
  -		aren't proxies, I add a instanceof check before. Is every Proxy a instance of Proxy?
  -		*/
  -		if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass()))
  +        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(objectOrProxy);
  +
  +        if (handler != null)
   		{
  -			IndirectionHandler handler;
  -			handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
   			return getKeyValues(cld, handler.getIdentity(), convertToSql);  //BRJ: convert Identity
  -		}
  -		else if (objectOrProxy instanceof VirtualProxy)
  -		{
  -			IndirectionHandler handler;
  -			handler = VirtualProxy.getIndirectionHandler((VirtualProxy) objectOrProxy);
  -            return getKeyValues(cld, handler.getIdentity(), convertToSql);  //BRJ: convert Identity
   		}
   		else
   		{
  
  
  
  1.22      +58 -48    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ProxyHelper.java	30 Jan 2004 18:34:30 -0000	1.21
  +++ ProxyHelper.java	8 Feb 2004 13:19:47 -0000	1.22
  @@ -136,23 +136,17 @@
        */
       public static final Object getRealObject(Object objectOrProxy)
       {
  -        IndirectionHandler handler;
  -        /*
  -        arminw
  -        TODO: Check it out. Because the isProxyClass method is costly and most objects
  -        aren't proxies, I add a instanceof check before. Is every Proxy a instance of Proxy?
  -        */
  -        if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass()))
  +        if (isNormalOjbProxy(objectOrProxy))
           {
               String msg;
   
               try
               {
  -                handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  -                return handler.getRealSubject();
  +                return ((IndirectionHandler)Proxy.getInvocationHandler(objectOrProxy)).getRealSubject();
               }
               catch (ClassCastException e)
               {
  +                // shouldn't happen but still ...
                   msg = "The InvocationHandler for the provided Proxy was not an instance of " + IndirectionHandler.class.getName();
                   log.error(msg);
                   throw new PersistenceBrokerException(msg, e);
  @@ -169,11 +163,11 @@
                   throw e;
               }
           }
  -        else if (objectOrProxy instanceof VirtualProxy)
  +        else if (isVirtualOjbProxy(objectOrProxy))
           {
               try
               {
  -                return ((VirtualProxy) objectOrProxy).getRealSubject();
  +                return ((VirtualProxy)objectOrProxy).getRealSubject();
               }
               catch (PersistenceBrokerException e)
               {
  @@ -195,30 +189,19 @@
        */
       public static final Object getRealObjectIfMaterialized(Object objectOrProxy)
       {
  -        IndirectionHandler handler;
  -        /*
  -        arminw
  -        TODO: Check it out. Because the isProxyClass method is costly and most objects
  -        aren't proxies, I add a instanceof check before. Is every Proxy a instance of Proxy?
  -        */
  -        if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass()))
  +        if (isNormalOjbProxy(objectOrProxy))
           {
               String msg;
   
               try
               {
  -                handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  -                if (handler.alreadyMaterialized())
  -                {
  -                    return handler.getRealSubject();
  -                }
  -                else
  -                {
  -                    return null;
  -                }
  +                IndirectionHandler handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  +
  +                return handler.alreadyMaterialized() ? handler.getRealSubject() : null;
               }
               catch (ClassCastException e)
               {
  +                // shouldn't happen but still ...
                   msg = "The InvocationHandler for the provided Proxy was not an instance of " + IndirectionHandler.class.getName();
                   log.error(msg);
                   throw new PersistenceBrokerException(msg, e);
  @@ -235,19 +218,13 @@
                   throw e;
               }
           }
  -        else if (objectOrProxy instanceof VirtualProxy)
  +        else if (isVirtualOjbProxy(objectOrProxy))
           {
               try
               {
                   VirtualProxy proxy = (VirtualProxy)objectOrProxy;
  -                if (proxy.alreadyMaterialized())
  -                {
  -                    return proxy.getRealSubject();
  -                }
  -                else
  -                {
  -                    return null;
  -                }
  +
  +                return proxy.alreadyMaterialized() ? proxy.getRealSubject() : null;
               }
               catch (PersistenceBrokerException e)
               {
  @@ -271,12 +248,7 @@
       {
           IndirectionHandler handler;
   
  -        /*
  -        arminw
  -        TODO: Check it out. Because the isProxyClass method is costly and most objects
  -        aren't proxies, I add a instanceof check before. Is every Proxy a instance of Proxy?
  -        */
  -        if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass()))
  +        if (isNormalOjbProxy(objectOrProxy))
           {
               String msg;
   
  @@ -292,6 +264,7 @@
               }
               catch (ClassCastException e)
               {
  +                // shouldn't happen but still ...
                   msg = "The InvocationHandler for the provided Proxy was not an instance of " + IndirectionHandler.class.getName();
                   log.error(msg);
                   throw new PersistenceBrokerException(msg, e);
  @@ -303,7 +276,7 @@
                   throw new PersistenceBrokerException(msg, e);
               }
           }
  -        else if (objectOrProxy instanceof VirtualProxy)
  +        else if (isVirtualOjbProxy(objectOrProxy))
           {
               handler = VirtualProxy.getIndirectionHandler((VirtualProxy) objectOrProxy);
               /*
  @@ -367,22 +340,52 @@
       }
   
       /**
  +     * Determines whether the given object is an OJB proxy.
  +     * 
  +     * @return <code>true</code> if the object is an OJB proxy
  +     */
  +    public static boolean isNormalOjbProxy(Object proxyOrObject)
  +    {
  +        /*
  +         arminw
  +         TODO: Check it out. Because the isProxyClass method is costly and most objects
  +         aren't proxies, I add a instanceof check before. Is every Proxy a instance of Proxy?
  +         */
  +        return (proxyOrObject instanceof Proxy) &&
  +               Proxy.isProxyClass(proxyOrObject.getClass()) &&
  +               (Proxy.getInvocationHandler(proxyOrObject) instanceof IndirectionHandler);
  +    }
  +
  +    /**
  +     * Determines whether the given object is an OJB virtual proxy.
  +     * 
  +     * @return <code>true</code> if the object is an OJB virtual proxy
  +     */
  +    public static boolean isVirtualOjbProxy(Object proxyOrObject)
  +    {
  +        return proxyOrObject instanceof VirtualProxy;
  +    }
  +
  +    /**
        * 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;
  +        return isNormalOjbProxy(proxyOrObject) || isVirtualOjbProxy(proxyOrObject);
       }
   
       public static IndirectionHandler getIndirectionHandler(Object obj)
       {
  -        if (Proxy.isProxyClass(obj.getClass()))
  +        if (obj == null)
  +        {
  +            return null;
  +        }
  +        else if (isNormalOjbProxy(obj))
           {
               return (IndirectionHandler) Proxy.getInvocationHandler(obj);
           }
  -        else if (obj instanceof VirtualProxy)
  +        else if (isVirtualOjbProxy(obj))
           {
               return VirtualProxy.getIndirectionHandler((VirtualProxy) obj);
           }
  @@ -390,5 +393,12 @@
           {
               return null;
           }
  +    }
  +
  +    public static boolean isMaterialized(Object object)
  +    {
  +        IndirectionHandler handler = getIndirectionHandler(object);
  +
  +        return handler == null ? true : handler.alreadyMaterialized();
       }
   }
  
  
  
  1.2       +9 -29     db-ojb/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java
  
  Index: PlainPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PlainPrefetcher.java	25 Oct 2003 23:59:26 -0000	1.1
  +++ PlainPrefetcher.java	8 Feb 2004 13:19:47 -0000	1.2
  @@ -63,17 +63,9 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.query.Query;
  -
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  +import org.apache.ojb.broker.util.ProxyHelper;
   
   /**
    * Prefetcher for plain list of objects (no relations).
  @@ -111,15 +103,9 @@
           for (Iterator it = proxies.iterator(); it.hasNext(); )
           {
               proxy = it.next();
  -            if (Proxy.isProxyClass(proxy.getClass()))
  -            {
  -                handler = (IndirectionHandler) Proxy.getInvocationHandler(proxy);
  -            }
  -            else if (proxy instanceof VirtualProxy)
  -            {
  -                handler = VirtualProxy.getIndirectionHandler((VirtualProxy) proxy);
  -            }
  -            else
  +            handler = ProxyHelper.getIndirectionHandler(proxy);
  +
  +            if (handler == null)
               {
                   continue;
               }
  @@ -160,19 +146,13 @@
           for (Iterator it = proxies.iterator(); it.hasNext(); )
           {
               proxy = it.next();
  -            if (Proxy.isProxyClass(proxy.getClass()))
  -            {
  -                handler = (IndirectionHandler) Proxy.getInvocationHandler(proxy);
  -            }
  -            else if (proxy instanceof VirtualProxy)
  -            {
  -                handler = VirtualProxy.getIndirectionHandler((VirtualProxy) proxy);
  -            }
  -            else
  +            handler = ProxyHelper.getIndirectionHandler(proxy);
  +
  +            if (handler == null)
               {
                   continue;
               }
  -
  +            
               id = handler.getIdentity();
               if (cache.lookup(id) != null)
               {
  
  
  
  1.19      +3 -10     db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
  
  Index: StatementsForClassImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- StatementsForClassImpl.java	6 Oct 2003 07:24:02 -0000	1.18
  +++ StatementsForClassImpl.java	8 Feb 2004 13:19:47 -0000	1.19
  @@ -54,14 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  @@ -77,6 +69,7 @@
   import org.apache.ojb.broker.platforms.PlatformException;
   import org.apache.ojb.broker.platforms.PlatformFactory;
   import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -374,7 +367,7 @@
           }
           try
           {
  -            if (!(result instanceof Proxy))
  +            if (!ProxyHelper.isNormalOjbProxy(result))  // tomdz: What about VirtualProxy
               {
                   platform.afterStatementCreate(result);
               }
  
  
  
  1.31      +13 -31    db-ojb/src/java/org/apache/ojb/broker/Identity.java
  
  Index: Identity.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/Identity.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Identity.java	7 Jan 2004 11:41:20 -0000	1.30
  +++ Identity.java	8 Feb 2004 13:19:47 -0000	1.31
  @@ -59,6 +59,7 @@
   import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.util.BrokerHelper;
  +import org.apache.ojb.broker.util.ProxyHelper;
   
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  @@ -69,15 +70,6 @@
   import java.util.zip.GZIPInputStream;
   import java.util.zip.GZIPOutputStream;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  -//#else
  -/*
  -import com.develop.java.lang.reflect.Proxy;
  -*/
  -//#endif
  -
  -
   /**
    * represents the identity of an object.
    * identity (it's primary keys) must be unique accross extents !
  @@ -133,26 +125,16 @@
           init(objectToIdentitify, targetBroker, cld);
       }
   
  -    private void init(Object objectToIdentitify, PersistenceBroker targetBroker, ClassDescriptor cld)
  +    private void init(Object objectToIdentify, PersistenceBroker targetBroker, ClassDescriptor cld)
       {
  -        if(objectToIdentitify == null) throw new OJBRuntimeException("Can't create Identity for 'null'-object");
  +        if(objectToIdentify == null) throw new OJBRuntimeException("Can't create Identity for 'null'-object");
           try
           {
  -            if (objectToIdentitify instanceof VirtualProxy)
  -            {
  -                VirtualProxy p = (VirtualProxy) objectToIdentitify;
  -                Identity sourceOID = p.getIdentity();
  -                m_objectsTopLevelClass = sourceOID.m_objectsTopLevelClass;
  -                m_objectsRealClass = sourceOID.m_objectsRealClass;
  -                m_pkValues = sourceOID.m_pkValues;
  -            }
  -            else if (objectToIdentitify instanceof Proxy)
  +            IndirectionHandler handler = ProxyHelper.getIndirectionHandler(objectToIdentify);
  +
  +            if (handler != null)
               {
  -                // Proxy p = (Proxy) objectToIdentitify;
  -                // InvocationHandler h = Proxy.getInvocationHandler(p);
  -                // IndirectionHandler ih = (IndirectionHandler) h;
  -                IndirectionHandler ih = (IndirectionHandler) Proxy.getInvocationHandler(objectToIdentitify);
  -                Identity sourceOID = ih.getIdentity();
  +                Identity sourceOID = handler.getIdentity();
                   m_objectsTopLevelClass = sourceOID.m_objectsTopLevelClass;
                   m_objectsRealClass = sourceOID.m_objectsRealClass;
                   m_pkValues = sourceOID.m_pkValues;
  @@ -161,17 +143,17 @@
               {
                   if (cld == null)
                   {
  -                    cld = targetBroker.getClassDescriptor(objectToIdentitify.getClass());
  +                    cld = targetBroker.getClassDescriptor(objectToIdentify.getClass());
                   }
   
                   // identities must be unique accross extents !
  -                m_objectsTopLevelClass = targetBroker.getTopLevelClass(objectToIdentitify.getClass());
  -                m_objectsRealClass = objectToIdentitify.getClass();
  +                m_objectsTopLevelClass = targetBroker.getTopLevelClass(objectToIdentify.getClass());
  +                m_objectsRealClass = objectToIdentify.getClass();
   
                   // BRJ: definitely do NOT convertToSql
                   // conversion is done when binding the sql-statement
                   BrokerHelper helper = targetBroker.serviceBrokerHelper();
  -                m_pkValues = helper.extractValueArray( helper.getKeyValues(cld, objectToIdentitify, false) );
  +                m_pkValues = helper.extractValueArray( helper.getKeyValues(cld, objectToIdentify, false) );
               }
   
               checkForPrimaryKeys();
  @@ -179,7 +161,7 @@
           catch (Exception e)
           {
               throw new ClassNotPersistenceCapableException("Can not init Identity for given object " +
  -                    objectToIdentitify, e);
  +                    objectToIdentify, e);
           }
       }
   
  
  
  

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