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 SqlSelectStatement.java
Date Thu, 24 Apr 2003 20:09:31 GMT
brj         2003/04/24 13:09:31

  Modified:    src/java/org/apache/ojb/broker/query QueryByCriteria.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlSelectStatement.java
  Log:
  new feature to define the join type
  
  Revision  Changes    Path
  1.14      +56 -3     db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
  
  Index: QueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- QueryByCriteria.java	8 Apr 2003 20:19:30 -0000	1.13
  +++ QueryByCriteria.java	24 Apr 2003 20:09:30 -0000	1.14
  @@ -88,7 +88,7 @@
   {
       private Criteria m_criteria;
       private boolean m_distinct = false;
  -    private HashMap m_pathClasses;
  +    private Map m_pathClasses;
       private Criteria m_havingCriteria;
   
       // holding FieldHelper for orderBy and groupBy
  @@ -97,6 +97,8 @@
       
       // list of names of prefetchable relationships
       private List m_prefetchedRelationships = null;
  +    
  +    private Map m_pathOuterJoin;
   
       /**
        * Build a Query for class targetClass with criteria.
  @@ -114,6 +116,7 @@
           m_groupby = new ArrayList();
           m_orderby = new ArrayList();
           m_prefetchedRelationships = new ArrayList();
  +        m_pathOuterJoin = new HashMap();
       }
   
       /**
  @@ -206,16 +209,32 @@
        * Without this hint SqlStatment will use the base class the
        * relationship points to ie: Article instead of CdArticle.
        *
  +     * @deprecated use setPathClass
        * @param the path segment ie: allArticlesInGroup
        * @param the Class ie: CdArticle
        * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
        */
       public void addPathClass(String aPath, Class aClass)
       {
  -        getPathClasses().put(aPath, aClass);
  +        setPathClass(aPath, aClass);
       }
   
       /**
  +     * Set the Class for a path. Used for relationships to extents.<br>
  +     * SqlStatment will use this class when resolving the path.
  +     * Without this hint SqlStatment will use the base class the
  +     * relationship points to ie: Article instead of CdArticle.
  +     *
  +     * @param the path segment ie: allArticlesInGroup
  +     * @param the Class ie: CdArticle
  +     * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
  +     */
  +    public void setPathClass(String aPath, Class aClass)
  +    {
  +        getPathClasses().put(aPath, aClass);
  +    }
  +  
  +    /**
        * Get the Class for a path
        *
        * @param the path segment ie: allArticlesInGroup
  @@ -228,6 +247,35 @@
           return (Class) getPathClasses().get(aPath);
       }
   
  +    /**
  +     * Answer true if outer join for path should be used
  +     * @param aPath
  +     * @return
  +     */
  +    public boolean isPathOuterJoin(String aPath)
  +    {
  +        Boolean result = (Boolean)getPathOuterJoin().get(aPath);
  +        
  +        if (result != null)
  +        {
  +            return result.booleanValue();
  +        }
  +        else
  +        {
  +            return false;
  +        }
  +    }
  +
  +    /**
  +     * Force outer join for path
  +     *
  +     * @param aPath
  +     */
  +    public void setPathOuterJoin(String aPath)
  +    {
  +        getPathOuterJoin().put(aPath, new Boolean(true));
  +    }
  +
       /* (non-Javadoc)
        * @see org.apache.ojb.broker.query.Query#getCriteria()
        */
  @@ -460,6 +508,11 @@
           }    
           
           return temp;
  +	}
  +
  +	protected Map getPathOuterJoin()
  +	{
  +		return m_pathOuterJoin;
   	}
   
   }
  
  
  
  1.37      +9 -5      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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- SqlQueryStatement.java	16 Apr 2003 18:00:31 -0000	1.36
  +++ SqlQueryStatement.java	24 Apr 2003 20:09:30 -0000	1.37
  @@ -711,6 +711,7 @@
           Object[] keys = null;
           Join join;
           ArrayList descriptors;
  +        boolean outer = useOuterJoins;
   
   
           curr = getTableAliasForPath(aPath, aUserAlias);
  @@ -738,6 +739,9 @@
                       attrPath = attrPath + "." + attr;
                   }
   
  +                // look for outer join hint
  +                outer = outer || getQuery().isPathOuterJoin(attr);
  +       
                   // look for 1:n or m:n
                   if (ord instanceof CollectionDescriptor)
                   {
  @@ -760,7 +764,7 @@
   							// we need two Joins for m:n
   							// 1.) prev class to indirectionTable
   							prevKeys = prev.cld.getPkFields();
  -							join = new Join(prev, prevKeys, indirect, cod.getFksToThisClass(), useOuterJoins,
attr + "*");
  +							join = new Join(prev, prevKeys, indirect, cod.getFksToThisClass(), outer, attr +
"*");
   							prev.addJoin(join);
   
   							// 2.) indirectionTable to the current Class
  @@ -785,7 +789,7 @@
                       curr = createTableAlias(cld, attrPath, aUserAlias, aPath);
                       
                       // BRJ : use OUTER join for same table and existing extents
  -                    boolean outer = (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
  +                    outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
                       join = new Join(prev, prevKeys, curr, keys, outer, attr);
                       prev.addJoin(join);
                       
  @@ -1002,7 +1006,7 @@
   			{
   				buf.append(",");
   			}
  -			appendColName(cf.name, true, null, buf);
  +			appendColName(cf.name, false, null, buf);
   		}
       }
   
  @@ -1142,7 +1146,7 @@
   			if (columnNumbers[i] == -1)
   			{
   				buf.append(",");
  -				appendColName(cf.name, true, null, buf);
  +				appendColName(cf.name, false, null, buf);
   				columnNumbers[i] = existingColumns.size();
   				existingColumns.add(cf.name);
   			}
  
  
  
  1.12      +2 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SqlSelectStatement.java	14 Mar 2003 16:55:13 -0000	1.11
  +++ SqlSelectStatement.java	24 Apr 2003 20:09:30 -0000	1.12
  @@ -143,7 +143,7 @@
               {
                   buf.append(",");
               }
  -            appendColName(columns[i], true, null, buf);
  +            appendColName(columns[i], false, null, buf);
               columnList.add(columns[i]);
           }
           return columnList;
  
  
  

Mime
View raw message