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 ClassDescriptor.java
Date Fri, 06 Dec 2002 16:28:00 GMT
brj         2002/12/06 08:28:00

  Modified:    src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
  Log:
  improved handling of Proxy and VirtualProxy in getKeyValues().
  keys are taken from embedded Identity.
  
  Revision  Changes    Path
  1.44      +75 -17    jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- ClassDescriptor.java	4 Dec 2002 21:09:27 -0000	1.43
  +++ ClassDescriptor.java	6 Dec 2002 16:28:00 -0000	1.44
  @@ -54,18 +54,10 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.ojb.broker.OJBRuntimeException;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.accesslayer.RowReader;
  -import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
  -import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
   import java.io.Serializable;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Modifier;
  +import java.lang.reflect.Proxy;
   import java.sql.Timestamp;
   import java.util.ArrayList;
   import java.util.Arrays;
  @@ -76,8 +68,16 @@
   import java.util.Map;
   import java.util.Vector;
   
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
  +import org.apache.ojb.broker.OJBRuntimeException;
  +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.accesslayer.IndirectionHandler;
  +import org.apache.ojb.broker.accesslayer.RowReader;
  +import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   //#else
   /*
   import com.develop.java.lang.reflect.Proxy;
  @@ -869,12 +869,42 @@
   
       /**
        * returns an Array with an Objects PK VALUES, with any java-to-sql
  -     * FieldConversion applied
  -     * @throws MetadataException if there is an erros accessing o field values
  +     * FieldConversion applied. If the Object is a Proxy or a VirtualProx NO
  +     * conversion is necessary.
  +     * 
  +     * @param objectOrProxy
  +     * @return Object[]
  +     * @throws PersistenceBrokerException
        */
  -    public Object[] getKeyValues(Object o) throws PersistenceBrokerException
  +    public Object[] getKeyValues(Object objectOrProxy) throws PersistenceBrokerException
       {
  -        return getKeyValues(o, true);
  +        return getKeyValues(objectOrProxy, true);
  +    }
  +
  +    /**
  +     * returns an Array with an Objects PK VALUES if convertToSql is true, any
  +     * associated java-to-sql conversions are applied. If the Object is a Proxy
  +     * or a VirtualProx NO conversion is necessary.
  +     * 
  +     * @param objectOrProxy
  +     * @param convertToSql
  +     * @return Object[]
  +     * @throws PersistenceBrokerException
  +     */
  +    public Object[] getKeyValues(Object objectOrProxy, boolean convertToSql) throws PersistenceBrokerException
  +    {
  +        if (objectOrProxy instanceof Proxy)
  +        {
  +            return getKeyValuesForProxy((Proxy)objectOrProxy);
  +        }
  +        else if (objectOrProxy instanceof VirtualProxy)
  +        {
  +            return getKeyValuesForProxy((VirtualProxy)objectOrProxy);
  +        }
  +        else
  +        {
  +            return getKeyValuesForObject(objectOrProxy,convertToSql);
  +        }    
       }
   
       /**
  @@ -882,7 +912,7 @@
        * if convertToSql is true, any associated java-to-sql conversions are applied
        * @throws MetadataException if there is an erros accessing o field values
        */
  -    public Object[] getKeyValues(Object o, boolean convertToSql) throws PersistenceBrokerException
  +    protected Object[] getKeyValuesForObject(Object o, boolean convertToSql) throws PersistenceBrokerException
       {
           FieldDescriptor[] pkFields = getPkFields();
           Object[] result = new Object[pkFields.length];
  @@ -907,6 +937,34 @@
               result[i] = cv;
           }
           return result;
  +    }
  +
  +    /**
  +     * returns an Array with the Proxy's PK VALUES
  +     * @param aProxy
  +     * @return Object[]
  +     * @throws PersistenceBrokerException
  +     */
  +    protected Object[] getKeyValuesForProxy(Proxy aProxy) throws PersistenceBrokerException
  +    {
  +        IndirectionHandler handler;
  +
  +        handler = (IndirectionHandler) Proxy.getInvocationHandler(aProxy);
  +        return handler.getIdentity().getPrimaryKeyValues();
  +    }
  +
  +    /**
  +     * returns an Array with the VirtualProxy's PK VALUES
  +     * @param aProxy
  +     * @return Object[]
  +     * @throws PersistenceBrokerException
  +     */
  +    protected Object[] getKeyValuesForProxy (VirtualProxy aProxy) throws PersistenceBrokerException
  +    {
  +        IndirectionHandler handler;
  +
  +        handler = (IndirectionHandler) VirtualProxy.getIndirectionHandler(aProxy);
  +        return handler.getIdentity().getPrimaryKeyValues();
       }
   
       /**
  
  
  

Mime
View raw message