db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql TableAliasHandler.java
Date Sat, 03 Dec 2005 19:51:54 GMT
brj         2005/12/03 11:51:54

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        TableAliasHandler.java
  Log:
  fix problem with pathclass hints
  
  Revision  Changes    Path
  1.17      +38 -36    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java
  
  Index: TableAliasHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TableAliasHandler.java	1 Dec 2005 21:32:21 -0000	1.16
  +++ TableAliasHandler.java	3 Dec 2005 19:51:53 -0000	1.17
  @@ -17,6 +17,7 @@
   
   import java.lang.ref.WeakReference;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  @@ -234,32 +235,33 @@
   
       }
    
  -
   	/**
   	 * TODO: add super ClassDescriptor
   	 * answer the ClassDescriptor for itemClass for an ObjectReferenceDescriptor
   	 * check optional hint;
   	 */
  -	private ClassDescriptor getItemClassDescriptor(ObjectReferenceDescriptor ord, String attr,
Map pathClasses)
  +	private ClassDescriptor getItemClassDescriptor(ObjectReferenceDescriptor ord, List hintClasses)
   	{   
  -		List itemClasses = (List)pathClasses.get(attr);
  -
  -		if (itemClasses == null)
  -		{
  -			itemClasses = new ArrayList();
  -			itemClasses.add(ord.getItemClass());
  -		}
  -
  -		List classDescriptors = new ArrayList(itemClasses.size());
  -		DescriptorRepository repo = ord.getClassDescriptor().getRepository();
  -
  -		for (Iterator iter = itemClasses.iterator(); iter.hasNext();)
  +        if (hintClasses == null || hintClasses.isEmpty())
  +        {
  +            return ord.getItemClassDescriptor();
  +        }
  +        
  +        DescriptorRepository repo = ord.getClassDescriptor().getRepository();
  +		Class resultClass = (Class) hintClasses.get(0);
  +        
  +		for (Iterator iter = hintClasses.iterator(); iter.hasNext();)
   		{
   			Class clazz = (Class) iter.next();
  -			classDescriptors.add(repo.getDescriptorFor(clazz));
  +            Class superClazz = clazz.getSuperclass();
  +            
  +            if (hintClasses.contains(superClazz))
  +            {
  +                resultClass = superClazz;   // use superclass if it's in the hints
  +            }
   		}
   
  -		return (ClassDescriptor) classDescriptors.get(0);
  +		return repo.getDescriptorFor(resultClass);
   	}
   
       /**
  @@ -421,6 +423,12 @@
   				attrPath = attrPath + "." + attr;
   			}
   
  +            // use class hints for path
  +            if (pathClasses != null)
  +            {
  +                hintClasses = (List) pathClasses.get(attrPath);     
  +            }    
  +
   			// look for outer join hint
   			outer = outer || getQuery().isPathOuterJoin(attrPath);
   
  @@ -428,7 +436,7 @@
   			if (ord instanceof CollectionDescriptor)
   			{
   				cod = (CollectionDescriptor) ord;
  -				cld = getItemClassDescriptor(cod, attrPath, pathClasses);
  +				cld = getItemClassDescriptor(cod, hintClasses);
   
   				if (!cod.isMtoNRelation())
   				{
  @@ -459,7 +467,7 @@
   			else
   			{
   				// must be n:1 or 1:1
  -				cld = getItemClassDescriptor(ord, attrPath, pathClasses);
  +				cld = getItemClassDescriptor(ord, hintClasses);
   
   			    // BRJ : if ord is taken from 'super' we have to change prev accordingly
   				if (!prev.cld.equals(ord.getClassDescriptor()))
  @@ -494,7 +502,6 @@
   
   			if (curr == null)
   			{
  -//				hintClasses = (List) pathClasses.get(aPath);               
                   curr = createTableAlias(cld, attrPath, pathAlias, hintClasses);
   
   				outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
  @@ -876,19 +883,16 @@
               // BRJ : build alias for extents, only one per Table
               if (lookForExtents)
               {
  -                ClassDescriptor[] extCLDs = (ClassDescriptor[]) aCld.getRepository().getAllConcreteSubclassDescriptors(
  -                        aCld).toArray(new ClassDescriptor[0]);
  +                Collection extClds = aCld.getRepository().getAllConcreteSubclassDescriptors(aCld);
   
  -                ClassDescriptor extCd;
  -                Class extClass;
  -                String extTable;
                   Map extMap = new HashMap(); // only one Alias per Table
  -                int firstNonAbstractExtentIndex = 0;
  -
  -                for (int i = 0; i < extCLDs.length; i++)
  +                int firstNonAbstractExtentIndex = 0;               
  +                int i = 0;
  +                
  +                for (Iterator iter = extClds.iterator(); iter.hasNext(); i++)
                   {
  -                    extCd = extCLDs[i];
  -                    extClass = extCd.getClassOfObject();
  +                    ClassDescriptor extCld = (ClassDescriptor) iter.next();
  +                    Class extClass = extCld.getClassOfObject();
                       if (useHintsOnExtents && (!hints.contains(extClass)))
                       {
                           //LEANDRO: don't include this class
  @@ -896,14 +900,12 @@
                           firstNonAbstractExtentIndex++;
                           continue;
                       }
  -                    extTable = extCd.getFullTableName();
  +                    String extTable = extCld.getFullTableName();
   
  -                    // BRJ : Use the first non abstract extent
  -                    // if the main cld is abstract
  -                    //logger.debug("cld abstract["+aCld.isAbstract()+"] i["+i+"] index
["+firtsNonAbstractExtentIndex+"]");
  +                    // BRJ : Use the first non abstract extent if the main cld is abstract
                       if (aCld.isAbstract() && i == firstNonAbstractExtentIndex)
                       {
  -                        this.cld = extCd;
  +                        this.cld = extCld;
                           this.table = extTable;
                       }
                       else
  @@ -912,7 +914,7 @@
                           // does not match the table of the 'base' class.
                           if (extMap.get(extTable) == null && !extTable.equals(table))
                           {
  -                            extMap.put(extTable, new TableAlias(extCd, anAlias + "E" +
i, false, hints));
  +                            extMap.put(extTable, new TableAlias(extCld, anAlias + "E" +
i, false, hints));
                           }
                       }
                   }
  
  
  

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