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/core QueryReferenceBroker.java
Date Fri, 28 Oct 2005 20:30:06 GMT
brj         2005/10/28 13:30:06

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java TableAliasHandler.java
               src/java/org/apache/ojb/broker/accesslayer
                        MtoNCollectionPrefetcher.java
               src/java/org/apache/ojb/broker/core
                        QueryReferenceBroker.java
  Log:
  fix for ojb-72
  an alias is now used for the indirection table
  
  Revision  Changes    Path
  1.102     +49 -34    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.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- SqlQueryStatement.java	18 Sep 2005 13:26:14 -0000	1.101
  +++ SqlQueryStatement.java	28 Oct 2005 20:30:06 -0000	1.102
  @@ -269,53 +269,57 @@
           FieldDescriptor fld;
           String result = null;
           String attrName = anAttrInfo.getAttribute();
  -        
  -        if (translate)
  +
  +        // no translation required, use attribute name
  +        if (!translate)
           {
  -            // translate attribute name into column name
  -            fld = getFieldDescriptor(aTableAlias, attrName);
  +            return attrName;
  +        }
   
  -            if (fld != null)
  -            {
  -                m_attrToFld.put(anAttrInfo.getParent().getAttribute(), fld);
  +        // BRJ: special alias for the indirection table has no ClassDescriptor 
  +        if (TableAliasHandler.isMNAlias(aTableAlias))
  +        {
  +            return aTableAlias.alias + "." + attrName;
  +        }
   
  -                // added to suport the super reference descriptor
  -                if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
  -                {
  -                    Iterator itr = aTableAlias.joins.iterator();
  -                    while (itr.hasNext())
  -                    {
  -                        Join join = (Join) itr.next();
  -                        if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
  -                        {
  -                            result = join.right.alias + "." + fld.getColumnName();
  -                            break;
  -                        }
  -                    }
  +        // translate attribute name into column name
  +        fld = getFieldDescriptor(aTableAlias, attrName);
  +
  +        if (fld != null)
  +        {
  +            m_attrToFld.put(anAttrInfo.getParent().getAttribute(), fld);
   
  -                    if (result == null)
  +            // added to suport the super reference descriptor
  +            if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
  +            {
  +                Iterator itr = aTableAlias.joins.iterator();
  +                while (itr.hasNext())
  +                {
  +                    Join join = (Join) itr.next();
  +                    if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                       {
  -                        result = attrName;
  +                        result = join.right.alias + "." + fld.getColumnName();
  +                        break;
                       }
                   }
  -                else
  +
  +                if (result == null)
                   {
  -                    result = aTableAlias.alias + "." + fld.getColumnName();
  +                    result = attrName;
                   }
               }
  -            else if ("*".equals(attrName))
  -            {
  -                result = attrName;
  -            }
               else
               {
  -                // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
  -                result = attrName;
  +                result = aTableAlias.alias + "." + fld.getColumnName();
               }
           }
  +        else if ("*".equals(attrName))
  +        {
  +            result = attrName;
  +        }
           else
           {
  -            // use attribute name
  +            // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
               result = attrName;
           }
   
  @@ -1165,8 +1169,9 @@
   
               if (getQuery() instanceof MtoNQuery)
               {
  -                buf.append(",");
  -                buf.append(((MtoNQuery) getQuery()).getIndirectionTable());
  +                MtoNQuery mnQuery = (MtoNQuery)m_query; 
  +                buf.append(", ");
  +                appendTableAlias(getTableAliasForPath(mnQuery.getIndirectionTable()), buf);
               }
           }
   
  @@ -1334,6 +1339,16 @@
       }
   
       /**
  +     * Answer the TableAlias for aPath
  +     * @param aPath
  +     * @return TableAlias, null if none
  +     */
  +    private TableAlias getTableAliasForPath(String aPath)
  +    {
  +        return m_tableAliasHandler.getTableAliasForPath(aPath);
  +    }
  +
  +    /**
        * Gets the search table of this query.
        * @return Returns a TableAlias
        */
  
  
  
  1.12      +28 -5     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TableAliasHandler.java	8 Oct 2005 12:07:33 -0000	1.11
  +++ TableAliasHandler.java	28 Oct 2005 20:30:06 -0000	1.12
  @@ -33,6 +33,7 @@
   import org.apache.ojb.broker.metadata.SuperReferenceDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  +import org.apache.ojb.broker.query.MtoNQuery;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.query.SqlCriteria;
  @@ -50,6 +51,7 @@
   class TableAliasHandler
   {
       private static final String ALIAS_SEPARATOR = ".";
  +    static final String M_N_ALIAS = "M_N";
       
       /** the query */
       private QueryByCriteria m_query;
  @@ -79,7 +81,16 @@
   
       private int m_aliasCount = 0;
   
  -    
  +    /**
  +     * Test if it's the special M_N_Alias.
  +     * @param aTableAlias
  +     * @return
  +     */
  +    static boolean isMNAlias(TableAlias aTableAlias)
  +    {
  +        return aTableAlias.cld == null && M_N_ALIAS.equals(aTableAlias.alias);
  +    }
  +
       TableAliasHandler(TableAliasHandler parent, QueryByCriteria aQuery, ClassDescriptor
searchCld, Logger logger)
       {      
           m_logger = logger != null ? logger : LoggerFactory.getLogger(TableAliasHandler.class);
  @@ -98,6 +109,14 @@
   
           m_rootAlias = createTableAlias(getBaseClassDescriptor(), null, "");
   
  +        // BRJ: create a special alias for the indirection table
  +        if (m_query instanceof MtoNQuery)
  +        {
  +            MtoNQuery mnQuery = (MtoNQuery)m_query; 
  +            TableAlias mnAlias = new TableAlias(mnQuery.getIndirectionTable(), M_N_ALIAS);
  +            m_pathToAlias.put(mnQuery.getIndirectionTable(), mnAlias);
  +        }
  +
           if (searchCld == getBaseClassDescriptor())
           {
               m_searchAlias = m_rootAlias;
  @@ -248,7 +267,7 @@
        * @param aPath
        * @return TableAlias, null if none
        */
  -    private TableAlias getTableAliasForPath(String aPath)
  +    TableAlias getTableAliasForPath(String aPath)
       {
           return (TableAlias) m_pathToAlias.get(aPath);
       }
  @@ -435,7 +454,11 @@
   			if (curr == null)
   			{
   				List hintClasses = (List) pathClasses.get(aPath);
  -				curr = createTableAlias(cld, attrPath, pathAlias, hintClasses);
  +                
  +//                ClassDescriptor relCld = ((FieldDescriptor)keys[0]).getClassDescriptor();
 // TEST
  +//                curr = createTableAlias(relCld, attrPath, pathAlias, hintClasses);
  +                
  +                curr = createTableAlias(cld, attrPath, pathAlias, hintClasses);
   
   				outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
   				addJoin(prev, prevKeys, curr, keys, outer, attr);
  @@ -1019,7 +1042,7 @@
               }
               return columns;
           }
  -
  +        
           public boolean equals(Object obj)
           {
               Join j = (Join) obj;
  
  
  
  1.25      +7 -7      db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
  
  Index: MtoNCollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MtoNCollectionPrefetcher.java	27 Apr 2005 14:25:31 -0000	1.24
  +++ MtoNCollectionPrefetcher.java	28 Oct 2005 20:30:06 -0000	1.25
  @@ -305,15 +305,15 @@
               case 0 :
                   break;
               case 1 :
  -                crit.addColumnEqualTo(fkCol, values.get(0));
  +                crit.addEqualTo(fkCol, values.get(0));
                   break;
               default :
                   // create IN (...) for the single key field
  -                crit.addColumnIn(fkCol, values);
  +                crit.addIn(fkCol, values);
                   break;
           }
   
  -        crit.addEqualToColumn(itemPkField.getAttributeName(), itemFkCol);
  +        crit.addEqualToField(itemPkField.getAttributeName(), itemFkCol);
   
           return crit;
       }
  @@ -336,7 +336,7 @@
   
           for (int i = 0; i < itemPkFields.length; i++)
           {
  -            crit.addEqualToColumn(itemPkFields[i].getAttributeName(), itemFkCols[i]);
  +            crit.addEqualToField(itemPkFields[i].getAttributeName(), itemFkCols[i]);
           }
           
           while (iter.hasNext())
  @@ -350,11 +350,11 @@
   
                   if (val[i] == null)
                   {
  -                    c.addColumnIsNull(fkCols[i]);
  +                    c.addIsNull(fkCols[i]);
                   }
                   else
                   {
  -                    c.addColumnEqualTo(fkCols[i], val[i]);
  +                    c.addEqualTo(fkCols[i], val[i]);
                   }
   
               }
  
  
  
  1.42      +3 -3      db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- QueryReferenceBroker.java	29 Sep 2005 23:26:31 -0000	1.41
  +++ QueryReferenceBroker.java	28 Oct 2005 20:30:06 -0000	1.42
  @@ -712,11 +712,11 @@
   
           for (int i = 0; i < thisClassFks.length; i++)
           {
  -            criteria.addColumnEqualTo(cod.getIndirectionTable() + "." + thisClassFks[i],
values[i].getValue());
  +            criteria.addEqualTo(cod.getIndirectionTable() + "." + thisClassFks[i], values[i].getValue());
           }
           for (int i = 0; i < itemClassFks.length; i++)
           {
  -            criteria.addColumnEqualToField(
  +            criteria.addEqualToField(
                   cod.getIndirectionTable() + "." + itemClassFks[i].toString(),
                   refCld.getPkFields()[i].getAttributeName());
           }
  
  
  

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