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 Wed, 26 Oct 2005 19:35:35 GMT
brj         2005/10/26 12:35:35

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE MtoNCollectionPrefetcher.java
               src/java/org/apache/ojb/broker/accesslayer/sql Tag:
                        OJB_1_0_RELEASE SqlQueryStatement.java
  Log:
  fix for ojb-72
  an alias is now used for the indirection table
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.12.2.5  +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.12.2.4
  retrieving revision 1.12.2.5
  diff -u -r1.12.2.4 -r1.12.2.5
  --- MtoNCollectionPrefetcher.java	27 Apr 2005 14:13:38 -0000	1.12.2.4
  +++ MtoNCollectionPrefetcher.java	26 Oct 2005 19:35:35 -0000	1.12.2.5
  @@ -304,15 +304,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;
       }
  @@ -335,7 +335,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())
  @@ -349,11 +349,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]);
                   }
   
               }
  
  
  
  No                   revision
  No                   revision
  1.75.2.11 +57 -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.75.2.10
  retrieving revision 1.75.2.11
  diff -u -r1.75.2.10 -r1.75.2.11
  --- SqlQueryStatement.java	5 Oct 2005 18:01:26 -0000	1.75.2.10
  +++ SqlQueryStatement.java	26 Oct 2005 19:35:35 -0000	1.75.2.11
  @@ -125,6 +125,14 @@
           }
   
           m_root = createTableAlias(m_baseCld, 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");
  +            m_pathToAlias.put(mnQuery.getIndirectionTable(), mnAlias);
  +        }
   
           if (m_searchCld == m_baseCld)
           {
  @@ -236,53 +244,56 @@
       {
           String result = null;
   
  -        if (translate)
  +        // no translation required, use attribute name
  +        if (!translate)
  +        {
  +            return aPathInfo.column;
  +        }
  +
  +        // BRJ: special alias for the indirection table has no ClassDescriptor 
  +        if (aTableAlias.cld == null)
  +        {
  +            return getIndirectionTableColName(aTableAlias, aPathInfo.path);
  +        }
  +
  +        // translate attribute name into column name
  +        FieldDescriptor fld = getFieldDescriptor(aTableAlias, aPathInfo);
  +
  +        if (fld != null)
           {
  -            FieldDescriptor fld;
  -            // translate attribute name into column name
  -            fld = getFieldDescriptor(aTableAlias, aPathInfo);
  +            m_attrToFld.put(aPathInfo.path, fld);
   
  -            if (fld != null)
  +            // added to suport the super reference descriptor
  +            if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
               {
  -                m_attrToFld.put(aPathInfo.path, fld);
  -                
  -                // added to suport the super reference descriptor
  -                if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
  +                Iterator itr = aTableAlias.joins.iterator();
  +                while (itr.hasNext())
                   {
  -                    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;
  -                        }
  -                    }
  -
  -                    if (result == null)
  +                    Join join = (Join) itr.next();
  +                    if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                       {
  -                        result = aPathInfo.column;
  +                        result = join.right.alias + "." + fld.getColumnName();
  +                        break;
                       }
                   }
  -                else
  +
  +                if (result == null)
                   {
  -                    result = aTableAlias.alias + "." + fld.getColumnName();
  +                    result = aPathInfo.column;
                   }
               }
  -            else if ("*".equals(aPathInfo.column))
  -            {
  -                result = aPathInfo.column;
  -            }
               else
               {
  -                // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
  -                result = aPathInfo.column;
  +                result = aTableAlias.alias + "." + fld.getColumnName();
               }
           }
  +        else if ("*".equals(aPathInfo.column))
  +        {
  +            result = aPathInfo.column;
  +        }
           else
           {
  -            // use attribute name
  +            // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
               result = aPathInfo.column;
           }
   
  @@ -726,6 +737,18 @@
               buf.append(c.getValue());
           }
       }
  +    
  +    /**
  +     * Get the column name from the indirection table.
  +     * @param mnAlias 
  +     * @param path
  +     */
  +    private String getIndirectionTableColName(TableAlias mnAlias, String path)
  +    {
  +        int dotIdx = path.lastIndexOf(".");
  +        String column = path.substring(dotIdx);
  +        return mnAlias.alias + column;
  +    }
   
       /**
        * Answer the SQL-Clause for an InCriteria
  @@ -1312,7 +1335,6 @@
           String aliasName = String.valueOf(getAliasChar()) + m_aliasCount++; // + m_pathToAlias.size();
           alias = new TableAlias(table, aliasName);
           m_pathToAlias.put(path, alias);
  -        // PAW
   		m_logger.debug("createTableAlias2: path: " + path + " tableAlias: " + alias);
   
           return alias;
  @@ -1483,8 +1505,9 @@
   
               if (getQuery() instanceof MtoNQuery)
               {
  +                MtoNQuery mnQuery = (MtoNQuery)m_query; 
                   buf.append(",");
  -                buf.append(((MtoNQuery) getQuery()).getIndirectionTable());
  +                buf.append(getTableAliasForPath(mnQuery.getIndirectionTable()).getTableAndAlias());
               }
           }
   
  
  
  

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