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 SqlQueryStatement.java
Date Tue, 15 Jul 2003 12:21:34 GMT
brj         2003/07/15 05:21:34

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
  Log:
  fixed problem with nested queries and extents
  issue OJB189
  
  Revision  Changes    Path
  1.44      +105 -35   db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- SqlQueryStatement.java	8 Jul 2003 17:31:59 -0000	1.43
  +++ SqlQueryStatement.java	15 Jul 2003 12:21:34 -0000	1.44
  @@ -794,8 +794,8 @@
   						// we need two Joins for m:n
   						// 1.) prev class to indirectionTable
   						prevKeys = prev.cld.getPkFields();
  -						join = new Join(prev, prevKeys, indirect, cod.getFksToThisClass(), outer, attr +
"*");
  -						prev.addJoin(join);
  +                        keys = cod.getFksToThisClass();
  +	                    addJoin(prev, prevKeys, indirect, keys, outer, attr + "*");
                       }					
                       // 2.) indirectionTable to the current Class
   					prev = indirect;
  @@ -817,24 +817,10 @@
               if (curr == null)
               {
                   List hintClasses = (List) getQuery().getPathClasses().get(aPath);
  -                curr = createTableAlias(cld, attrPath, aUserAlias, aPath,hintClasses);
  -                
  -
  -                // BRJ : use OUTER join for same table and existing extents
  +                curr = createTableAlias(cld, attrPath, aUserAlias, aPath,hintClasses);
            
  +            
                   outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
  -                join = new Join(prev, prevKeys, curr, keys, outer, attr);
  -                prev.addJoin(join);
  -
  -                // BRJ : add OUTER joins for extents
  -                
  -                for (int j = 0; j < curr.extents.size(); j++)
  -                {
  -                    TableAlias extAlias = (TableAlias) curr.extents.get(j);
  -
  -                    //String extAliasClassDescriptorClassName = extAlias.getClassDescriptor().getClassNameOfObject();
  -                    Join extJoin = new Join(prev, prevKeys, extAlias, keys, true, attr);
  -                    prev.addJoin(extJoin);
  -                }
  +                addJoin(prev, prevKeys, curr, keys, outer, attr);   
               }
               prev = curr;
           }
  @@ -842,6 +828,71 @@
       }
   
       /**
  +     * add a join between two aliases
  +     * 
  +     * no extents
  +     * A1   -> A2
  +     * 
  +     * extents on the right
  +     * A1   -> A2 
  +     * A1   -> A2E0
  +     * 
  +     * extents on the left : copy alias on right, extents point to copies
  +     * A1   -> A2
  +     * A1E0 -> A2C0 
  +     * 
  +     * extents on the left and right
  +     * A1   -> A2
  +     * A1   -> A2E0
  +     * A1E0 -> A2C0
  +     * A1E0 -> A2E0C0
  +     *  
  +     * @param left
  +     * @param leftKeys
  +     * @param right
  +     * @param rightKeys
  +     * @param outer
  +     * @param name
  +     */
  +    private void addJoin(TableAlias left, Object[] leftKeys, TableAlias right, Object[]
rightKeys, boolean outer, String name)  
  +    {
  +        Join join;
  +        TableAlias extAlias, rightCopy;
  +        
  +        join = new Join(left, leftKeys, right, rightKeys, outer, name);
  +        left.addJoin(join); 
  +
  +        // build join between left and extents of right
  +        if (right.hasExtents())    
  +        {
  +            for (int i = 0; i < right.extents.size(); i++)
  +            {
  +                extAlias = (TableAlias) right.extents.get(i);
  +                join = new Join(left, leftKeys, extAlias, rightKeys, true, name);
  +                left.addJoin(join);
  +            }
  +        }
  +        
  +        // we need to copy the alias on the right for each extent on the left
  +        if (left.hasExtents())
  +        {
  +           for (int i = 0; i < left.extents.size(); i++)
  +           {
  +               extAlias = (TableAlias) left.extents.get(i);
  +               rightCopy = right.copy("C" + i);
  +               
  +               // copies are treated like normal extents 
  +               right.extents.add(rightCopy);
  +               right.extents.addAll(rightCopy.extents);
  +               
  +               addJoin(extAlias, leftKeys, rightCopy ,rightKeys, true ,name);
  +           }
  +        }
  +        
  +        
  +    }  
  +    
  +    /**
        * Create a TableAlias for path or userAlias
        * @param aCld
        * @param aPath
  @@ -1467,6 +1518,35 @@
               return extents.iterator();
           }
   
  +        /**
  +         * Copy the Alias and all it's extents adding a Postfix
  +         * Joins are not copied
  +         * @param aPostfix
  +         * @return
  +         */
  +        TableAlias copy(String aPostfix)
  +        {
  +            TableAlias result, temp;
  +            Iterator iter = iterateExtents();
  + 
  +            if (cld == null)
  +            {
  +                result = new TableAlias(table, alias + aPostfix);
  +            }
  +            else
  +            {
  +                result = new TableAlias(cld, alias + aPostfix);
  +            }
  +            
  +            while (iter.hasNext())
  +            {
  +                temp = (TableAlias)iter.next();
  +                result.extents.add(temp.copy(aPostfix));
  +            }
  +            
  +            return result;
  +        }
  +
           void addJoin(Join join)
           {
               if (joins == null)
  @@ -1529,22 +1609,7 @@
               return table.hashCode();
           }
   
  -        public Object clone()
  -        {
  -            TableAlias clone;
   
  -            if (cld == null)
  -            {
  -                clone = new TableAlias(table, alias);
  -            }
  -            else
  -            {
  -                clone = new TableAlias(cld, alias);
  -            }
  -
  -            clone.joins = joins;
  -            return clone;
  -        }
       }
   
       /**
  @@ -1638,6 +1703,11 @@
           public int hashCode()
           {
               return name.hashCode();
  +        }
  +        
  +        public String toString()
  +        {
  +            return left.alias + " -> " + right.alias;
           }
       }
   }
  
  
  

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