db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From baser...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker Area.java ExtentAwarePathExpressionsTest.java
Date Tue, 13 May 2003 15:23:31 GMT
baserose    2003/05/13 08:23:31

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
               src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
               src/java/org/apache/ojb/broker/query QueryByCriteria.java
               src/schema ojbtest-data.dtd ojbtest-data.xml
                        ojbtest-schema.xml
               src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker
                        ExtentAwarePathExpressionsTest.java
  Added:       src/test/org/apache/ojb/broker Area.java
  Log:
  Some changes to support addPathClass to QueryByCriteria. One can now use
  more than one hint class to be used on the Select stmt, as long as the hint
  class belong to the class extent. query.setPathClass now uses addPathClass
  
  Using private loggers and added some tests/test data
  
  Revision  Changes    Path
  1.38      +145 -96   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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- SqlQueryStatement.java	24 Apr 2003 20:09:30 -0000	1.37
  +++ SqlQueryStatement.java	13 May 2003 15:23:29 -0000	1.38
  @@ -66,6 +66,7 @@
   import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  +import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  @@ -74,6 +75,7 @@
   import org.apache.ojb.broker.util.SqlHelper;
   import org.apache.ojb.broker.util.SqlHelper.PathInfo;
   import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   /**
    * Model a Statement based on Query.
  @@ -84,7 +86,7 @@
   public abstract class SqlQueryStatement implements SqlStatement, JoinSyntaxTypes
   {
       /** the logger */
  -    private Logger m_logger;
  +    Logger m_logger = LoggerFactory.getLogger(SqlQueryStatement.class);
       /** the target table of the query */
       private TableAlias m_root;
       /** the query */
  @@ -104,8 +106,7 @@
        */
       public SqlQueryStatement(Platform pf, ClassDescriptor cld, String[] columns, Query
query, Logger logger)
       {
  -        this.m_logger = logger;
  -        this.m_root = createTableAlias(cld, "");
  +        this.m_root = createTableAlias(cld, null,"");
           this.m_query = (QueryByCriteria)query;
           this.m_columns = columns;
           this.pf = pf;
  @@ -655,8 +656,9 @@
               Iterator iter = alias.iterateExtents();
               while (iter.hasNext())
               {
  +                TableAlias tableAlias = (TableAlias) iter.next();
                   buf.append(" OR ");
  -                appendCriteria((TableAlias) iter.next(), attrInfo.pathInfo, c, buf);
  +                appendCriteria(tableAlias, attrInfo.pathInfo, c, buf);
               }
           }
   
  @@ -715,97 +717,105 @@
   
   
           curr = getTableAliasForPath(aPath, aUserAlias);
  -        if (curr == null)
  +        
  +        
  +        if(curr != null)
           {
  -            descriptors = getRoot().cld.getAttributeDescriptorsForPath(aPath, getQuery().getPathClasses());
  -            prev = getRoot();
  +            return curr;
  +        }
  +        
  +        descriptors = getRoot().cld.getAttributeDescriptorsForPath(aPath, getQuery().getPathClasses());
  +        prev = getRoot();
   
  -            for (int i = 0; i < descriptors.size(); i++)
  +        for (int i = 0; i < descriptors.size(); i++)
  +        {
  +            if (!(descriptors.get(i) instanceof ObjectReferenceDescriptor))
               {
  -                if (!(descriptors.get(i) instanceof ObjectReferenceDescriptor))
  -                {
  -                    // only use Collection- and ObjectReferenceDescriptor
  -                    continue;
  -                }
  +                // only use Collection- and ObjectReferenceDescriptor
  +                continue;
  +            }
  +
  +            ord = (ObjectReferenceDescriptor) descriptors.get(i);
  +            attr = ord.getAttributeName();
  +            if (attrPath == null)
  +            {
  +                attrPath = attr;
  +            }
  +            else
  +            {
  +                attrPath = attrPath + "." + attr;
  +            }
  +
  +            // look for outer join hint
  +            outer = outer || getQuery().isPathOuterJoin(attr);
  +
  +            // look for 1:n or m:n
  +            if (ord instanceof CollectionDescriptor)
  +            {
  +                cod = (CollectionDescriptor) ord;
  +                cld = getItemClassDescriptor(cod, attr);
   
  -                ord = (ObjectReferenceDescriptor) descriptors.get(i);
  -                attr = ord.getAttributeName();
  -                if (attrPath == null)
  +                if (!cod.isMtoNRelation())
                   {
  -                    attrPath = attr;
  +                    prevKeys = prev.cld.getPkFields();
  +                    keys = cod.getForeignKeyFieldDescriptors(cld);
                   }
                   else
                   {
  -                    attrPath = attrPath + "." + attr;
  -                }
  -
  -                // look for outer join hint
  -                outer = outer || getQuery().isPathOuterJoin(attr);
  -       
  -                // look for 1:n or m:n
  -                if (ord instanceof CollectionDescriptor)
  -                {
  -                    cod = (CollectionDescriptor) ord;
  -                    cld = getItemClassDescriptor(cod, attr);
  -
  -                    if (!cod.isMtoNRelation())
  +                    String mnAttrPath = attrPath + "*";
  +                    indirect = getTableAliasForPath(mnAttrPath, aUserAlias, aPath);
  +                    if (indirect == null)
                       {
  +                        indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath,
aUserAlias, aPath);
  +
  +                        // we need two Joins for m:n
  +                        // 1.) prev class to indirectionTable
                           prevKeys = prev.cld.getPkFields();
  -                        keys = cod.getForeignKeyFieldDescriptors(cld);
  -                    }
  -                    else
  -					{
  -						String mnAttrPath = attrPath + "*";
  -						indirect = getTableAliasForPath(mnAttrPath, aUserAlias, aPath);
  -						if (indirect == null)
  -						{
  -							indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath, aUserAlias, aPath);
  +                        join = new Join(prev, prevKeys, indirect, cod.getFksToThisClass(),
outer, attr + "*");
  +                        prev.addJoin(join);
   
  -							// 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);
  -
  -							// 2.) indirectionTable to the current Class
  -							prev = indirect;
  -							prevKeys = cod.getFksToItemClass();
  -							keys = cld.getPkFields();
  -						}
  -					}
  +                        // 2.) indirectionTable to the current Class
  +                        prev = indirect;
  +                        prevKeys = cod.getFksToItemClass();
  +                        keys = cld.getPkFields();
  +                    }
                   }
  -                else
  -                {
  -                    // must be n:1 or 1:1
  -                    cld = getItemClassDescriptor(ord, attr);
  +            }
  +            else
  +            {
  +                // must be n:1 or 1:1
  +                cld = getItemClassDescriptor(ord, attr);
   
  -                    prevKeys = ord.getForeignKeyFieldDescriptors(prev.cld);
  -                    keys = cld.getPkFields();
  -                }
  +                prevKeys = ord.getForeignKeyFieldDescriptors(prev.cld);
  +                keys = cld.getPkFields();
  +            }
  +
  +            curr = getTableAliasForPath(attrPath, aUserAlias, aPath);
  +            
  +            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
  +                outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
  +                join = new Join(prev, prevKeys, curr, keys, outer, attr);
  +                prev.addJoin(join);
   
  -                curr = getTableAliasForPath(attrPath, aUserAlias, aPath);
  -                if (curr == null)
  +                // BRJ : add OUTER joins for extents
  +                
  +                for (int j = 0; j < curr.extents.size(); j++)
                   {
  -                    curr = createTableAlias(cld, attrPath, aUserAlias, aPath);
  -                    
  -                    // BRJ : use OUTER join for same table and existing extents
  -                    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);
  -                        Join extJoin = new Join(prev, prevKeys, extAlias, keys, true, attr);
  -                        prev.addJoin(extJoin);
  -                    }
  -                }
  +                    TableAlias extAlias = (TableAlias) curr.extents.get(j);
   
  -                prev = curr;
  +                    //String extAliasClassDescriptorClassName = extAlias.getClassDescriptor().getClassNameOfObject();
  +                    Join extJoin = new Join(prev, prevKeys, extAlias, keys, true, attr);
  +                    prev.addJoin(extJoin);
  +                }
               }
  +            prev = curr;
           }
  -
           return curr;
       }
   
  @@ -815,17 +825,19 @@
        * @param aPath
        * @param aUserAlias
        * @param anOriginalPath
  +     * @param hints a List os Class objects to be used as hints for path expressions
        * @return TableAlias
  +     * 
        */
  -    private TableAlias createTableAlias(ClassDescriptor aCld, String aPath, String aUserAlias,
String anOriginalPath)
  +    private TableAlias createTableAlias(ClassDescriptor aCld, String aPath, String aUserAlias,
String anOriginalPath,List hints)
       {
           if (aUserAlias == null || !anOriginalPath.equals(aPath))
           {
  -            return createTableAlias(aCld, aPath);           
  +            return createTableAlias(aCld, hints, aPath);           
           }
           else
           {
  -            return createTableAlias(aCld, aUserAlias);
  +            return createTableAlias(aCld, hints,aUserAlias);
           }
       }
   
  @@ -833,8 +845,9 @@
        * Create new TableAlias for path
        * @param cld the class descriptor for the TableAlias
        * @param path the path from the target table of the query to this TableAlias.
  +     * @@param hints a List of Class objects to be used on path expressions
        */
  -    private TableAlias createTableAlias(ClassDescriptor cld, String path)
  +    private TableAlias createTableAlias(ClassDescriptor cld, List hints, String path)
       {
           TableAlias alias;
           boolean lookForExtents = false;
  @@ -843,8 +856,8 @@
           {
               lookForExtents = true;
           } 
  -
  -        alias = new TableAlias(cld, "A" + m_pathToAlias.size(), lookForExtents);
  +        
  +        alias = new TableAlias(cld, "A" + m_pathToAlias.size(), lookForExtents,hints);
           m_pathToAlias.put(path, alias);
           return alias;
       }
  @@ -937,25 +950,36 @@
       }
   
       /**
  +     * TODO: add super ClassDescriptor
        * answer the ClassDescriptor for itemClass for an ObjectReferenceDescriptor
        * check optional hint;
        */
       private ClassDescriptor getItemClassDescriptor(ObjectReferenceDescriptor ord, String
attr)
       {
  -        Class itemClass = null;
  +        List itemClasses = null;
           Query q = getQuery();
   
  -        // BRJ look for hint
           if (q instanceof QueryByCriteria)
           {
  -            itemClass = ((QueryByCriteria) q).getClassForPath(attr);
  +            itemClasses = ((QueryByCriteria) q).getClassesForPath(attr); 
           }
   
  -        if (itemClass == null)
  +        if (itemClasses == null)
  +        {
  +            itemClasses = new ArrayList();
  +            itemClasses.add(ord.getItemClass());
  +        }
  +        
  +        List classDescriptors = new ArrayList(itemClasses.size());
  +        DescriptorRepository repo = ord.getClassDescriptor().getRepository();
  +        
  +        for (Iterator iter = itemClasses.iterator(); iter.hasNext();)
           {
  -            itemClass = ord.getItemClass();
  +            Class clazz = (Class) iter.next();
  +            classDescriptors.add(repo.getDescriptorFor(clazz));
           }
  -        return ord.getClassDescriptor().getRepository().getDescriptorFor(itemClass);
  +        return (ClassDescriptor) classDescriptors.get(0); 
  +
       }
   
       /**
  @@ -1317,10 +1341,12 @@
        */
       static final class TableAlias
       {
  +        Logger logger = LoggerFactory.getLogger(TableAlias.class);
           ClassDescriptor cld; // Is null for indirection table of M:N relation
           String table;
           final String alias;
           private List extents = new ArrayList();
  +        private List hints = new ArrayList();
           private List joins;
   
           TableAlias(String aTable, String anAlias)
  @@ -1332,14 +1358,23 @@
   
           TableAlias(ClassDescriptor aCld, String anAlias)
           {
  -            this(aCld, anAlias, false);
  +            this(aCld, anAlias, false,null);
           }
   
  -		TableAlias(ClassDescriptor aCld, String anAlias, boolean lookForExtents)
  +		TableAlias(ClassDescriptor aCld, String anAlias, boolean lookForExtents,List hints)
   		{          
   			this.cld = aCld;
   			this.table = aCld.getFullTableName();
   			this.alias = anAlias;
  +            boolean useHintsOnExtents = false;
  +
  +            //LEANDRO: use hints
  +            if(hints != null && hints.size() > 0)
  +            {
  +                useHintsOnExtents = true;
  +            }
  +
  +            logger.debug("TableAlias(): using hints ? " + useHintsOnExtents);
   
               // BRJ : build alias for extents, only one per Table
   			if (lookForExtents)
  @@ -1348,15 +1383,25 @@
   				ClassDescriptor extCd;
   				String extTable;
   				Map extMap = new HashMap(); // only one Alias per Table
  +                int firtsNonAbstractExtentIndex = 0;
   
   				for (int i = 0; i < extClasses.size(); i++)
   				{
  -					extCd = aCld.getRepository().getDescriptorFor((Class) extClasses.get(i));
  +                    Class extClass = (Class) extClasses.get(i);
  +                    if(useHintsOnExtents &&  (!hints.contains(extClass)))
  +                    {
  +                        //LEANDRO: don't include this class
  +                        logger.debug("Skipping class ["+extClass+"] from extents List");
  +                        firtsNonAbstractExtentIndex++;
  +                        continue;
  +                    }
  +					extCd = aCld.getRepository().getDescriptorFor(extClass);
   					extTable = extCd.getFullTableName();
   
   					// BRJ : Use the first non abstract extent
                       // if the main cld is abstract       
  -					if (aCld.isAbstract() && i == 0)
  +                    //logger.debug("cld abstract["+aCld.isAbstract()+"] i["+i+"] index
["+firtsNonAbstractExtentIndex+"]");
  +					if (aCld.isAbstract() && i == firtsNonAbstractExtentIndex)
   					{
                           this.cld = extCd;
   						this.table = extTable;
  @@ -1367,11 +1412,10 @@
   						// does not match the table of the 'base' class.
   						if (extMap.get(extTable) == null && !extTable.equals(table))
   						{
  -							extMap.put(extTable, new TableAlias(extCd, anAlias + "E" + i, false));
  +							extMap.put(extTable, new TableAlias(extCd, anAlias + "E" + i, false,hints));
   						}
   					}
   				}
  -
   				extents.addAll(extMap.values());
   			}
               
  @@ -1380,6 +1424,11 @@
                   throw new PersistenceBrokerSQLException("Table is NULL for alias: " + alias);
               }
   		}
  +
  +        ClassDescriptor getClassDescriptor()
  +        {
  +            return cld;
  +        }
   
           String getTableAndAlias()
           {
  
  
  
  1.62      +8 -3      db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- ClassDescriptor.java	12 May 2003 10:01:57 -0000	1.61
  +++ ClassDescriptor.java	13 May 2003 15:23:29 -0000	1.62
  @@ -66,6 +66,7 @@
   import java.util.Date;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   import java.util.Vector;
   
  @@ -1112,8 +1113,12 @@
   			if (ord != null)
   			{
   				// BRJ : look for hint
  -				itemClass = (Class) pathHints.get(segment);
  -				if (itemClass == null)
  +                List hintClasses = (List) pathHints.get(segment);
  +				if(hintClasses != null &&  hintClasses.get(0) != null)
  +                {
  +                    itemClass = (Class)hintClasses.get(0);
  +                }
  +                else
   				{
   					itemClass = ord.getItemClass();
   				}
  
  
  
  1.15      +24 -11    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- QueryByCriteria.java	24 Apr 2003 20:09:30 -0000	1.14
  +++ QueryByCriteria.java	13 May 2003 15:23:29 -0000	1.15
  @@ -204,19 +204,28 @@
       }
   
       /**
  -     * 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
  +     * Add a hint Class for a path. Used for relationships to extents.<br>
  +     * SqlStatment will use these hint classes when resolving the path.
  +     * Without these hints 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)
       {
  -        setPathClass(aPath, aClass);
  +        Object pathClasses = m_pathClasses.get(aPath);
  +        if(pathClasses == null)
  +        {
  +            setPathClass(aPath,aClass);
  +        }
  +        else
  +        {
  +            List hints = (List)pathClasses;
  +            hints.add(aClass);
  +            m_pathClasses.put(aPath, hints);
  +        }
       }
   
       /**
  @@ -224,27 +233,31 @@
        * 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.
  +     * Using this method is the same as adding just one hint 
        *
        * @param the path segment ie: allArticlesInGroup
        * @param the Class ie: CdArticle
        * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
  +     * @see addPathClass()
        */
       public void setPathClass(String aPath, Class aClass)
       {
  -        getPathClasses().put(aPath, aClass);
  +        List pathClasses = new ArrayList(1);
  +        pathClasses.add(aClass);
  +        m_pathClasses.put(aPath, pathClasses);
       }
     
       /**
  -     * Get the Class for a path
  +     * Get the a List of Class objects used as hints for a path
        *
        * @param the path segment ie: allArticlesInGroup
  -     * @return the class to be used in SqlStatment
  +     * @return a List o Class objects to be used in SqlStatment
        * @see addPathClass()
        * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
        */
  -    public Class getClassForPath(String aPath)
  +    public List getClassesForPath(String aPath)
       {
  -        return (Class) getPathClasses().get(aPath);
  +        return (List)m_pathClasses.get(aPath);
       }
   
       /**
  
  
  
  1.10      +8 -1      db-ojb/src/schema/ojbtest-data.dtd
  
  Index: ojbtest-data.dtd
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.dtd,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ojbtest-data.dtd	14 Apr 2003 16:44:50 -0000	1.9
  +++ ojbtest-data.dtd	13 May 2003 15:23:30 -0000	1.10
  @@ -34,6 +34,7 @@
       Paper*,
       Category*,
       Topic*,
  +    Area*,
       ContentQualifier*
   )>
   <!ATTLIST dataset
  @@ -304,8 +305,14 @@
     Name CDATA #IMPLIED
   >
   
  +<!ELEMENT Area EMPTY>
  +<!ATTLIST Area
  +  Id CDATA #REQUIRED
  +  Name CDATA #IMPLIED
  +>
  +
   <!ELEMENT ContentQualifier EMPTY>
   <!ATTLIST ContentQualifier
       ContentId CDATA #REQUIRED
       QualifierId CDATA #REQUIRED
  ->
  \ No newline at end of file
  +>
  
  
  
  1.10      +6 -2      db-ojb/src/schema/ojbtest-data.xml
  
  Index: ojbtest-data.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ojbtest-data.xml	14 Apr 2003 16:44:50 -0000	1.9
  +++ ojbtest-data.xml	13 May 2003 15:23:30 -0000	1.10
  @@ -168,8 +168,12 @@
       <Topic Id="10" Name="Buyers" />
       <Topic Id="11" Name="Sellers" />
   
  +    <Area Id="20" Name="Human"/>
  +    <Area Id="21" Name="NotHuman"/>
  +
       <ContentQualifier ContentId="2" QualifierId="1"/>
       <ContentQualifier ContentId="2" QualifierId="10"/>
       <ContentQualifier ContentId="3" QualifierId="2"/>
  -    <ContentQualifier ContentId="11" QualifierId="11"/>
  -</dataset>
  \ No newline at end of file
  +    <ContentQualifier ContentId="10" QualifierId="20"/>
  +    <ContentQualifier ContentId="11" QualifierId="11"/>    
  +</dataset>
  
  
  
  1.33      +7 -1      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ojbtest-schema.xml	10 May 2003 08:53:15 -0000	1.32
  +++ ojbtest-schema.xml	13 May 2003 15:23:30 -0000	1.33
  @@ -427,6 +427,12 @@
       <column name="NAME" type="VARCHAR" size="50"/>
     </table>
   
  +  <!-- Qualifier -->
  +  <table name="AREA">
  +    <column name="ID" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="NAME" type="VARCHAR" size="50"/>
  +  </table>
  +
     <!-- Cant have foreign keys -->
     <table name="CONTENT_QUALIFIER">
       <column name="CONTENT_ID" required="true" primaryKey="true" type="INTEGER"/>
  @@ -682,4 +688,4 @@
           <column name="GAT_ID" type="INTEGER"/>
           <column name="EXTENT_NAME" type="VARCHAR" size="150"/>
       </table>
  -</database>
  \ No newline at end of file
  +</database>
  
  
  
  1.65      +6 -0      db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- repository_junit.xml	9 May 2003 23:58:18 -0000	1.64
  +++ repository_junit.xml	13 May 2003 15:23:30 -0000	1.65
  @@ -3681,6 +3681,7 @@
   	<class-descriptor class="org.apache.ojb.broker.BaseQualifierImpl">
   	   <extent-class class-ref="org.apache.ojb.broker.Topic"/>
   	   <extent-class class-ref="org.apache.ojb.broker.Category"/>
  +	   <extent-class class-ref="org.apache.ojb.broker.Area"/>	   
   	   <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true"/>
   	</class-descriptor>
   
  @@ -3690,6 +3691,11 @@
   	</class-descriptor>
   
   	<class-descriptor class="org.apache.ojb.broker.Category" table="CATEGORY">
  +	   <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true"/>
  +	   <field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR"/>
  +	</class-descriptor>
  +
  +	<class-descriptor class="org.apache.ojb.broker.Area" table="AREA">
   	   <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true"/>
   	   <field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR"/>
   	</class-descriptor>
  
  
  
  1.4       +39 -15    db-ojb/src/test/org/apache/ojb/broker/ExtentAwarePathExpressionsTest.java
  
  Index: ExtentAwarePathExpressionsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ExtentAwarePathExpressionsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExtentAwarePathExpressionsTest.java	11 Apr 2003 19:05:49 -0000	1.3
  +++ ExtentAwarePathExpressionsTest.java	13 May 2003 15:23:31 -0000	1.4
  @@ -1,5 +1,6 @@
   package org.apache.ojb.broker;
   
  +import java.util.Iterator;
   import java.util.List;
   
   import junit.framework.TestCase;
  @@ -9,6 +10,8 @@
   /**
    * 
    * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
  + * 
  + * $Id$
    */
   public class ExtentAwarePathExpressionsTest extends TestCase
   {
  @@ -23,11 +26,6 @@
   		super();
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (23.12.2000 18:30:38)
  -	 * @param args java.lang.String[]
  -	 */
   	public static void main(String[] args)
   	{
   		String[] arr = { CLASS.getName()};
  @@ -47,18 +45,11 @@
   		broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   	}
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:59:14)
  -	 */
   	public void tearDown()
   	{
   		broker.close();
   	}
   
  -    /**
  -     * Querying News.qualifierNmaes 
  -     */
   	public void testWithoutHintClass1() throws Exception
   	{
   		Criteria criteria = new Criteria();
  @@ -70,9 +61,6 @@
   		assertEquals(1, content.size());
   	}
   
  -    /**
  -     * Querying News/Paper.qualifierNmaes 
  -     */
   	public void testWithoutHintClass2() throws Exception
   	{
   		Criteria criteria = new Criteria();
  @@ -84,4 +72,40 @@
   		assertEquals(2, content.size());
   	}
   
  +    public void testNotNullPathElement()
  +    {
  +        Criteria criteria = new Criteria();
  +        criteria.addNotNull("qualifiers.name");
  +        QueryByCriteria query = new QueryByCriteria(BaseContentImpl.class, criteria, true);
  +        List content = (List) broker.getCollectionByQuery(query);
  +        assertEquals(4,content.size());
  +    }
  +    
  +    public void testSetPathClass()
  +    {
  +        Criteria criteria = new Criteria();
  +        criteria.addNotNull("qualifiers.name");
  +        QueryByCriteria query = new QueryByCriteria(BaseContentImpl.class, criteria, true);
  +        query.setPathClass("qualifiers",Category.class);
  +        List content = (List) broker.getCollectionByQuery(query);
  +        assertEquals(2,content.size());
  +        for (Iterator iter = content.iterator(); iter.hasNext();)
  +        {
  +            BaseContentImpl element = (BaseContentImpl) iter.next();
  +            assertTrue(element.getId() <=3 && element.getId() >=2);
  +        }
  +
  +    }
  +    
  +    public void testAddPathClass()
  +    {
  +        Criteria criteria = new Criteria();
  +        criteria.addNotNull("qualifiers.name");
  +        QueryByCriteria query = new QueryByCriteria(BaseContentImpl.class, criteria, true);
  +        query.addPathClass("qualifiers",Qualifier.class);
  +        query.addPathClass("qualifiers",Area.class);
  +        List content = (List) broker.getCollectionByQuery(query);
  +        assertEquals(1,content.size());
  +        assertEquals(10,((Paper)content.get(0)).getId());
  +    }
   }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/Area.java
  
  Index: Area.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /**
   * 
   * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
   */
  public class Area 
      extends BaseQualifierImpl
  {
  
  }
  
  
  

Mime
View raw message