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 Identity.java
Date Sat, 24 May 2003 23:58:21 GMT
arminw      2003/05/24 16:58:21

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        CollectionPrefetcher.java ReferencePrefetcher.java
                        RsIterator.java
               src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker Identity.java
  Log:
  please review these changes
  
  - fix bug: When using subclasses ('extents') as reference,
  only the top-level object was created as reference
  
  Revision  Changes    Path
  1.13      +5 -5      db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java
  
  Index: CollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CollectionPrefetcher.java	15 Mar 2003 16:24:06 -0000	1.12
  +++ CollectionPrefetcher.java	24 May 2003 23:58:20 -0000	1.13
  @@ -208,7 +208,7 @@
           {
               relatedObject = iter.next();
               fkValues = getObjectReferenceDescriptor().getForeignKeyValues(relatedObject,
cld);
  -            id = new Identity(ownerClass, fkValues);
  +            id = new Identity(getOwnerClassDescriptor().getClassOfObject(), ownerClass,
fkValues);
               owner = getBroker().getObjectByIdentity(id);
   
               if (Collection.class.isAssignableFrom(field.getType()))
  @@ -227,7 +227,7 @@
                           getLogger().error("Can't create new Collection for owner", e);
                       }
                   }
  -                
  +
                   // BRJ: do not add object if it's already in the list
                   if (!relatedData.contains(relatedObject))
                   {
  @@ -247,7 +247,7 @@
       public void prefetchRelationship(Collection owners)
       {
           PersistentField f = getObjectReferenceDescriptor().getPersistentField();
  -        
  +
           if (f.getType().isArray())
           {
               throw new PersistenceBrokerException("Prefetch does not yet work with Arrays:
'" + f.getName() + "'");
  @@ -261,7 +261,7 @@
               super.prefetchRelationship(owners);
           }
       }
  -    
  +
       protected CollectionDescriptor getCollectionDescriptor()
       {
           return (CollectionDescriptor)getObjectReferenceDescriptor();
  
  
  
  1.5       +13 -12    db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java
  
  Index: ReferencePrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReferencePrefetcher.java	29 Dec 2002 08:51:49 -0000	1.4
  +++ ReferencePrefetcher.java	24 May 2003 23:58:20 -0000	1.5
  @@ -70,7 +70,7 @@
   
   /**
    * Relationship Prefetcher for References.
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -88,8 +88,8 @@
   	}
   
   	/**
  -	 * associate the batched Children with their owner object <br>
  -	 * loop over owners
  +	 * Associate the batched Children with their owner object.
  +	 * Loop over owners
   	 */
   	protected void associateBatched(Collection owners, Collection children)
   	{
  @@ -99,13 +99,14 @@
   		Object fkValues[];
   		Identity id;
   		PersistentField field = getObjectReferenceDescriptor().getPersistentField();
  -
  +        Class topLevelClass = getBroker().getTopLevelClass(getObjectReferenceDescriptor().getItemClass());
  +        Class realClass = getObjectReferenceDescriptor().getItemClass();
   		while (iter.hasNext())
   		{
   			owner = iter.next();
   			fkValues = getObjectReferenceDescriptor().getForeignKeyValues(owner,cld);
  -			id = new Identity(getItemClassDescriptor().getClassOfObject(), fkValues);
  -
  +			// id = new Identity(getItemClassDescriptor().getClassOfObject(), fkValues);
  +            id = new Identity(realClass, topLevelClass, fkValues);
   			relatedObject = getBroker().getObjectByIdentity(id);
   			field.set(owner, relatedObject);
   		}
  @@ -123,7 +124,7 @@
           if (pkFields.length == 1)
           {
               crit = buildPrefetchCriteriaSingleKey(owners, pkFields[0]);
  -        }    
  +        }
           else
           {
               crit = buildPrefetchCriteriaMultipleKeys(owners, pkFields);
  @@ -164,7 +165,7 @@
   
           return crit;
       }
  -    
  +
       /**
        * Build the Criteria using multiple ORs
        * @param owners
  @@ -177,7 +178,7 @@
           Iterator iter = owners.iterator();
           Object[] fkVal;
           Object owner;
  -        
  +
           while (iter.hasNext())
           {
               Criteria c = new Criteria();
  @@ -190,7 +191,7 @@
                       c.addEqualTo(pkFields[i].getAttributeName(),fkVal[i]);
                   }
               }
  -            
  +
               if (!c.isEmpty())
               {
                   crit.addOrCriteria(c);
  @@ -198,6 +199,6 @@
           }
   
           return crit;
  -    }    
  +    }
   
   }
  
  
  
  1.36      +2 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- RsIterator.java	2 May 2003 12:24:31 -0000	1.35
  +++ RsIterator.java	24 May 2003 23:58:20 -0000	1.36
  @@ -376,7 +376,7 @@
           }
   
           // return identity object build up from primary keys
  -        return new Identity(getExtentClass(), pkValues);
  +        return new Identity(m_cld.getClassOfObject(), getExtentClass(), pkValues);
       }
   
       /**
  
  
  
  1.9       +41 -33    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PersistenceBrokerImpl.java	16 May 2003 20:25:02 -0000	1.8
  +++ PersistenceBrokerImpl.java	24 May 2003 23:58:20 -0000	1.9
  @@ -155,11 +155,12 @@
       private BrokerHelper brokerHelper;
       private PBKey pbKey;
   
  -    /**
  -     * The Class to be used for CollectionProxies
  -     * if null use either ListProxy or CollectionProxy
  -     */
  -    private Class m_collectionProxyClass = null;
  +// arminw: ProxyHelper now lookup collectionProxyClass
  +//    /**
  +//     * The Class to be used for CollectionProxies
  +//     * if null use either ListProxy or CollectionProxy
  +//     */
  +//    private Class m_collectionProxyClass = null;
   
   	/**
   	 * Lists for object registration during delete operations.
  @@ -1259,7 +1260,14 @@
   
           if (rds.isLazy())
           {
  -            referencedProxy = getClassDescriptor(referencedClass).getDynamicProxyClass();
  +            /*
  +            arminw:
  +            use real reference class instead of the top-level class,
  +            because we want to use a proxy representing the real class
  +            not only the top-level class - right?
  +            */
  +            // referencedProxy = getClassDescriptor(referencedClass).getDynamicProxyClass();
  +            referencedProxy = getClassDescriptor(rds.getItemClass()).getDynamicProxyClass();
           }
           else
           {
  @@ -1270,7 +1278,7 @@
           {
               try
               {
  -                return VirtualProxy.createProxy(getPBKey(), referencedProxy, new Identity(referencedClass,
pkVals));
  +                return VirtualProxy.createProxy(getPBKey(), referencedProxy, new Identity(rds.getItemClass(),referencedClass,
pkVals));
               }
               catch (Exception e)
               {
  @@ -1280,7 +1288,7 @@
           }
           else
           {
  -            return getObjectByIdentity(new Identity(referencedClass, pkVals));
  +            return getObjectByIdentity(new Identity(rds.getItemClass(), referencedClass,
pkVals));
           }
       }
   
  @@ -1318,7 +1326,7 @@
                   // BRJ : make sure endAt > startAt
                   endAt = iter.size() + 1;
               }
  -            
  +
               int numberOfObjectsToFetch = endAt - startAt;
               int retrievedCount = 0;
               /**
  @@ -1467,14 +1475,14 @@
   		}
   	}
   
  -    /**
  -     * Answer the class to be used for CollectionProxy
  -     * @return Class
  -     */
  -	public Class getCollectionProxyClass()
  -	{
  -        return m_collectionProxyClass;
  -	}
  +//    /**
  +//     * Answer the class to be used for CollectionProxy
  +//     * @return Class
  +//     */
  +//	public Class getCollectionProxyClass()
  +//	{
  +//        return m_collectionProxyClass;
  +//	}
   
       /**
        * retrieve a collection of itemClass Objects matching the Query query
  @@ -1680,7 +1688,7 @@
               // if specified in the ClassDescriptor the instance must be refreshed
               if (cld.isAlwaysRefresh())
               {
  -            	refreshInstance(obj, id, cld);	
  +            	refreshInstance(obj, id, cld);
               }
               // now refresh all references
               refreshRelationships(obj, cld);
  @@ -1701,13 +1709,13 @@
   	 * here.
   	 * @param cachedInstance the cached instance to be refreshed
   	 * @param oid the Identity of the cached instance
  -	 * @param cld the ClassDescriptor of cachedInstance 
  +	 * @param cld the ClassDescriptor of cachedInstance
   	 */
   	private void refreshInstance(Object cachedInstance, Identity oid, ClassDescriptor cld)
   	{
   		// read in fresh copy from the db
   		Object freshInstance = getDBObject(oid);
  -				
  +
   		// update all primitive typed attributes
   		FieldDescriptor[] fields = cld.getFieldDescriptions();
           FieldDescriptor fmd;
  @@ -1715,11 +1723,11 @@
           for (int i = 0; i < fields.length; i++)
           {
               fmd = fields[i];
  -            fld = fmd.getPersistentField();            
  +            fld = fmd.getPersistentField();
               fld.set(cachedInstance, fld.get(freshInstance));
           }
  -	} 
  -	
  +	}
  +
       /**
        * retrieve an Object by query
        * I.e perform a SELECT ... FROM ... WHERE ...  in an RDBMS
  @@ -2298,7 +2306,7 @@
       {
           if (query instanceof QueryBySQL)
           {
  -            logger.debug("Creating SQL-RsIterator for class ["+cld.getClassNameOfObject()+"]");
  +            if(logger.isDebugEnabled()) logger.debug("Creating SQL-RsIterator for class
["+cld.getClassNameOfObject()+"]");
               String sql = ((QueryBySQL) query).getSql();
               return factory.createRsIterator(sql, cld, this);
           }
  @@ -2306,13 +2314,13 @@
           if (!cld.isExtent())
           {
               // no extents just use the plain vanilla RsIterator
  -            logger.debug("Creating RsIterator for class ["+cld.getClassNameOfObject()+"]");
  +            if(logger.isDebugEnabled()) logger.debug("Creating RsIterator for class ["+cld.getClassNameOfObject()+"]");
               return factory.createRsIterator(query, cld, this);
           }
   
           OJBIterator iter = null;
           String lastUsedTable = cld.getFullTableName();
  -        logger.debug("Creating ChainingIterator for class ["+cld.getClassNameOfObject()+"]");
  +        if(logger.isDebugEnabled()) logger.debug("Creating ChainingIterator for class ["+cld.getClassNameOfObject()+"]");
           iter = new ChainingIterator();
           Vector extentClasses = cld.getExtentClasses();
           Class ec = null;
  @@ -2320,7 +2328,7 @@
           // BRJ: add base class iterator
           if (!cld.isInterface())
           {
  -            logger.debug("Adding RsIterator for class ["+cld.getClassNameOfObject()+"]
to ChainingIterator");
  +            if(logger.isDebugEnabled()) logger.debug("Adding RsIterator for class ["+cld.getClassNameOfObject()+"]
to ChainingIterator");
               ((ChainingIterator) iter).addIterator(factory.createRsIterator(query, cld,
this));
           }
   
  @@ -2332,14 +2340,14 @@
               // read same table only once
               if (!cld.isInterface() && cld.getFullTableName().equals(lastUsedTable))
               {
  -                logger.debug("Skipping class ["+cld.getClassNameOfObject()+"]");
  +                if(logger.isDebugEnabled()) logger.debug("Skipping class ["+cld.getClassNameOfObject()+"]");
                   continue;
               }
               lastUsedTable = cld.getFullTableName();
   
               // add the iterator to the chaining iterator.
               // BRJ: look for multilevel hierarchies
  -            logger.debug("Adding RsIterator of class ["+ec+"] to ChainingIterator");
  +            if(logger.isDebugEnabled()) logger.debug("Adding RsIterator of class ["+ec+"]
to ChainingIterator");
               ((ChainingIterator) iter).addIterator(getRsIteratorFromQuery(query, cld, factory));
           }
           return iter;
  @@ -2365,9 +2373,9 @@
   	 */
       public void configure(Configuration pConfig) throws ConfigurationException
       {
  -        PersistenceBrokerConfiguration config = (PersistenceBrokerConfiguration) pConfig;
  -
  -        m_collectionProxyClass = config.getCollectionProxyClass();
  +//        PersistenceBrokerConfiguration config = (PersistenceBrokerConfiguration) pConfig;
  +//
  +//        m_collectionProxyClass = config.getCollectionProxyClass();
       }
   
   
  
  
  
  1.18      +19 -27    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Identity.java	12 May 2003 14:01:32 -0000	1.17
  +++ Identity.java	24 May 2003 23:58:21 -0000	1.18
  @@ -120,9 +120,10 @@
        * that aClass is not a member of an extent, or that it is the base class of
        * an extent!
        *
  +     * @deprecated
  +     *
        * @param aClass java.lang.Class
        * @param pkValues List
  -     *
        */
       public Identity(Class aClass, Object[] pkValues)
       {
  @@ -131,32 +132,22 @@
           checkForPrimaryKeys();
       }
   
  -    public Identity(Object objectToIdentitify, PersistenceBroker targetBroker)
  +    /**
  +     * creates an Identity from a class and the objects primary key values.
  +     * used for the definition of proxies.
  +     *
  +     */
  +    public Identity(Class realClass, Class topLevel, Object[] pkValues)
       {
  -        init(objectToIdentitify, targetBroker, null);
  +        this.objectsClass = topLevel;
  +        this.objectsRealClass = realClass;
  +        this.pkValues = pkValues;
  +        checkForPrimaryKeys();
       }
   
  -    /**
  -     * creates an Identity from an object. Reads the objects primary key values.
  -     * @param objectToIdentitify java.lang.Object
  -     * @deprecated Identity does indirect access the sequence manager, thus
  -     * you should overgive a PB too.
  -     */
  -    public Identity(Object objectToIdentitify)
  +    public Identity(Object objectToIdentitify, PersistenceBroker targetBroker)
       {
  -        PersistenceBroker broker = null;
  -        try
  -        {
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            init(objectToIdentitify, broker, null);
  -        }
  -        finally
  -        {
  -            if (broker != null)
  -            {
  -                broker.close();
  -            }
  -        }
  +        init(objectToIdentitify, targetBroker, null);
       }
   
       public Identity(Object objectToIdentitify, PersistenceBroker targetBroker, ClassDescriptor
cld)
  @@ -179,9 +170,10 @@
               }
               else if (objectToIdentitify instanceof Proxy)
               {
  -                Proxy p = (Proxy) objectToIdentitify;
  -                InvocationHandler h = Proxy.getInvocationHandler(p);
  -                IndirectionHandler ih = (IndirectionHandler) h;
  +                // Proxy p = (Proxy) objectToIdentitify;
  +                // InvocationHandler h = Proxy.getInvocationHandler(p);
  +                // IndirectionHandler ih = (IndirectionHandler) h;
  +                IndirectionHandler ih = (IndirectionHandler) Proxy.getInvocationHandler((Proxy)
objectToIdentitify);
                   Identity sourceOID = ih.getIdentity();
                   this.objectsClass = sourceOID.objectsClass;
                   this.objectsRealClass = sourceOID.objectsRealClass;
  
  
  

Mime
View raw message