db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess PersistentFieldDefaultImpl.java PersistentFieldMaxPerformanceImpl.java
Date Fri, 29 Nov 2002 19:42:46 GMT
brj         2002/11/29 11:42:46

  Modified:    src/java/org/apache/ojb/broker/metadata/fieldaccess
                        PersistentFieldDefaultImpl.java
                        PersistentFieldMaxPerformanceImpl.java
  Log:
  support field access for proxies
  
  Revision  Changes    Path
  1.8       +25 -2     jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java
  
  Index: PersistentFieldDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PersistentFieldDefaultImpl.java	29 Nov 2002 19:35:07 -0000	1.7
  +++ PersistentFieldDefaultImpl.java	29 Nov 2002 19:42:46 -0000	1.8
  @@ -56,9 +56,11 @@
   
   import java.io.Serializable;
   import java.lang.reflect.Field;
  +import java.lang.reflect.Proxy;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
   
  +import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -134,7 +136,7 @@
   			 */
   			if ((value != null) || !type.isPrimitive())
   			{
  -				f.set(obj, value);
  +				f.set(ensureRealObject(obj), value);
   			}	
   		}
           catch (NullPointerException ignored)
  @@ -176,7 +178,7 @@
   		try
   		{
   			Field field = getField();
  -			Object result = field.get(obj);
  +			Object result = field.get(ensureRealObject(obj));
   
   			return result;
   		}
  @@ -197,6 +199,27 @@
               field.setAccessible(before);
           }
   	}
  +
  +    /**
  +     * get the real object for objectOrProxy
  +     * @param objectOrProxy
  +     * @return Object
  +     */
  +    protected Object ensureRealObject(Object objectOrProxy)
  +    {
  +        IndirectionHandler handler;
  +
  +        if (objectOrProxy instanceof Proxy)
  +        {
  +            handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  +            return handler.getRealSubject();
  +        }
  +        else
  +        {
  +            return objectOrProxy;
  +        }
  +    }
  +
   
   	/**
   	 * Tries to compute a Field object using getFieldRecursive.
  
  
  
  1.7       +26 -4     jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java
  
  Index: PersistentFieldMaxPerformanceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PersistentFieldMaxPerformanceImpl.java	24 Nov 2002 09:38:20 -0000	1.6
  +++ PersistentFieldMaxPerformanceImpl.java	29 Nov 2002 19:42:46 -0000	1.7
  @@ -55,7 +55,9 @@
    */
   
   import java.lang.reflect.Field;
  +import java.lang.reflect.Proxy;
   
  +import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -122,7 +124,7 @@
   			// thanks to Tomasz Wysocki for this trick
   			if ((value != null) || !type.isPrimitive())
   			{
  -				f.set(obj, value);
  +				f.set(ensureRealObject(obj), value);
   			}
   		}
   		catch (NullPointerException ignored)
  @@ -152,7 +154,7 @@
   		try
   		{
   			Field field = getField();
  -			Object result = field.get(obj);
  +			Object result = field.get(ensureRealObject(obj));
   			return result;
   		}
   		catch (IllegalAccessException e)
  @@ -167,6 +169,26 @@
   		}
   	}
   
  +    /**
  +     * get the real object for objectOrProxy
  +     * @param objectOrProxy
  +     * @return Object
  +     */
  +    protected Object ensureRealObject(Object objectOrProxy)
  +    {
  +        IndirectionHandler handler;
  +
  +        if (objectOrProxy instanceof Proxy)
  +        {
  +            handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  +            return handler.getRealSubject();
  +        }
  +        else
  +        {
  +            return objectOrProxy;
  +        }
  +    }
  +
   	/**
   	 * Tries to compute a Field object using getFieldRecursive.
   	 *
  @@ -219,7 +241,7 @@
   	 *
   	 * @throws MetadataException if there is an error computing the field ( No Field was found
into the class hierarchy)
   	 */
  -	Field getField()
  +	protected Field getField()
   	{
   		if (field == null)
   		{
  
  
  

Mime
View raw message