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 TableAliasHandler.java
Date Sat, 12 Nov 2005 17:59:45 GMT
brj         2005/11/12 09:59:45

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java TableAliasHandler.java
  Log:
  fix for ojb-50.
  path class hints are part of the key when looking for an alias
  
  Revision  Changes    Path
  1.105     +5 -4      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.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- SqlQueryStatement.java	3 Nov 2005 19:59:04 -0000	1.104
  +++ SqlQueryStatement.java	12 Nov 2005 17:59:43 -0000	1.105
  @@ -1169,7 +1169,7 @@
               if (getQuery() instanceof MtoNQuery)
               {
                   MtoNQuery mnQuery = (MtoNQuery)m_query; 
  -                appendTableAlias(getTableAliasForPath(mnQuery.getIndirectionTable()), buf);
  +                appendTableAlias(getTableAliasForPath(mnQuery.getIndirectionTable(), null),
buf);
                   buf.append(", ");
               }           
               appendTableAlias(alias, buf);
  @@ -1345,11 +1345,12 @@
       /**
        * Answer the TableAlias for aPath
        * @param aPath
  +     * @param hintClasses
        * @return TableAlias, null if none
        */
  -    private TableAlias getTableAliasForPath(String aPath)
  +    private TableAlias getTableAliasForPath(String aPath, List hintClasses)
       {
  -        return m_tableAliasHandler.getTableAliasForPath(aPath);
  +        return m_tableAliasHandler.getTableAliasForPath(aPath, hintClasses);
       }
   
       /**
  
  
  
  1.14      +51 -19    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TableAliasHandler.java	10 Nov 2005 21:10:18 -0000	1.13
  +++ TableAliasHandler.java	12 Nov 2005 17:59:44 -0000	1.14
  @@ -59,7 +59,7 @@
       private TableAlias m_rootAlias;
       /** the search table of the query */
       private TableAlias m_searchAlias;
  -    /** the mapping of paths to TableAliases */
  +    /** the mapping of paths to TableAliases. the key is built using the path and the path
class hints. */
       private Map m_pathToAlias = new HashMap();
       /** the mapping of ClassDescriptor to TableAliases */
       private Map m_cldToAlias = new HashMap();
  @@ -114,7 +114,7 @@
           {
               MtoNQuery mnQuery = (MtoNQuery)m_query; 
               TableAlias mnAlias = new TableAlias(mnQuery.getIndirectionTable(), M_N_ALIAS);
  -            m_pathToAlias.put(mnQuery.getIndirectionTable(), mnAlias);
  +            setTableAliasForPath(mnQuery.getIndirectionTable(), null, mnAlias);
           }
   
           if (searchCld == getBaseClassDescriptor())
  @@ -265,11 +265,46 @@
       /**
        * Answer the TableAlias for aPath
        * @param aPath
  +     * @param hintClasses 
        * @return TableAlias, null if none
        */
  -    TableAlias getTableAliasForPath(String aPath)
  +    TableAlias getTableAliasForPath(String aPath, List hintClasses)
       {
  -        return (TableAlias) m_pathToAlias.get(aPath);
  +        return (TableAlias) m_pathToAlias.get(buildAliasKey(aPath, hintClasses));
  +    }
  +
  +    /**
  +     * Set the TableAlias for aPath
  +     * @param aPath
  +     * @param hintClasses 
  +     * @param TableAlias
  +     */
  +    private void setTableAliasForPath(String aPath, List hintClasses, TableAlias anAlias)
  +    {
  +        m_pathToAlias.put(buildAliasKey(aPath, hintClasses), anAlias);
  +    }
  +    
  +    /**
  +     * Build the key for the TableAlias based on the path and the hints
  +     * @param aPath
  +     * @param hintClasses
  +     * @return the key for the TableAlias
  +     */
  +    private String buildAliasKey(String aPath, List hintClasses)
  +    {
  +        if (hintClasses == null || hintClasses.isEmpty())
  +        {
  +            return aPath;
  +        }
  +        
  +        StringBuffer buf = new StringBuffer(aPath);
  +        for (Iterator iter = hintClasses.iterator(); iter.hasNext();)
  +        {
  +            Class hint = (Class) iter.next();
  +            buf.append(" ");
  +            buf.append(hint.getName());
  +        }
  +        return buf.toString();
       }
   
       /**
  @@ -295,17 +330,18 @@
        * Answer the TableAlias for aPath or aUserAlias
        * @param aPath
        * @param aUserAlias
  +     * @param hintClasses
        * @return TableAlias, null if none
        */
  -    private TableAlias getTableAliasForPath(String aPath, String aUserAlias)
  +    private TableAlias getTableAliasForPath(String aPath, String aUserAlias, List hintClasses)
       {
           if (aUserAlias == null)
           {
  -            return getTableAliasForPath(aPath);
  +            return getTableAliasForPath(aPath, hintClasses);
           }
           else
           {
  -			return getTableAliasForPath(aUserAlias + ALIAS_SEPARATOR + aPath);
  +			return getTableAliasForPath(aUserAlias + ALIAS_SEPARATOR + aPath, hintClasses);
           }
       }
       
  @@ -333,8 +369,9 @@
   		boolean outer = useOuterJoins;
   		int pathLength;
   
  +        List hintClasses = (List) pathClasses.get(aPath);
   		String pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(aPath); 
  -		curr = getTableAliasForPath(aPath, pathAlias);
  +		curr = getTableAliasForPath(aPath, pathAlias, hintClasses);
   
   		if (curr != null)
   		{
  @@ -398,7 +435,7 @@
   				{
   					String mnAttrPath = attrPath + "*";
   					String mnUserAlias = (aUserAlias == null ? null : aUserAlias + "*");
  -					indirect = getTableAliasForPath(mnAttrPath, mnUserAlias);
  +					indirect = getTableAliasForPath(mnAttrPath, mnUserAlias, null);
   					if (indirect == null)
   					{
   						indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath, mnUserAlias);
  @@ -449,15 +486,11 @@
   			}
   
   			pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(attrPath); 
  -			curr = getTableAliasForPath(attrPath, pathAlias);
  +			curr = getTableAliasForPath(attrPath, pathAlias, hintClasses);
   
   			if (curr == null)
   			{
  -				List hintClasses = (List) pathClasses.get(aPath);
  -                
  -//              ClassDescriptor relCld = ((FieldDescriptor)keys[0]).getClassDescriptor();
 // TEST
  -//              curr = createTableAlias(relCld, attrPath, pathAlias, hintClasses);
  -                
  +//				hintClasses = (List) pathClasses.get(aPath);               
                   curr = createTableAlias(cld, attrPath, pathAlias, hintClasses);
   
   				outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
  @@ -607,8 +640,7 @@
   
           String aliasName = String.valueOf(getAliasChar()) + m_aliasCount++; // m_pathToAlias.size();
           alias = new TableAlias(cld, aliasName, lookForExtents, hints);
  -
  -        m_pathToAlias.put(path, alias);
  +        setTableAliasForPath(path, hints, alias);
           
           return alias;
       }
  @@ -648,7 +680,7 @@
   
           String aliasName = String.valueOf(getAliasChar()) + m_aliasCount++; // + m_pathToAlias.size();
           alias = new TableAlias(table, aliasName);
  -        m_pathToAlias.put(path, alias);
  +        setTableAliasForPath(path, null, alias);
   
           m_logger.debug("createTableAlias2: path: " + path + " tableAlias: " + 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