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/test/org/apache/ojb/broker MultipleTableExtentAwareQueryTest.java
Date Sat, 07 Aug 2004 20:00:27 GMT
brj         2004/08/07 13:00:26

  Modified:    src/schema ojbtest-schema.xml
               src/java/org/apache/ojb/broker/util BrokerHelper.java
               src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker
                        MultipleTableExtentAwareQueryTest.java
  Log:
  - testcase by Charles Anthony
  - improved BrokerHelper, do not use IN for a single concreteClass
  
  Revision  Changes    Path
  1.85      +5 -0      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.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- ojbtest-schema.xml	27 Jul 2004 23:38:49 -0000	1.84
  +++ ojbtest-schema.xml	7 Aug 2004 20:00:26 -0000	1.85
  @@ -324,21 +324,25 @@
   
       <table name="EXTENT_TEST_A">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="CLASS_NAME" required="true" primaryKey="true" type="VARCHAR" size="128"/>
           <column name="NAME" required="false" type="VARCHAR" size="100"/>
       </table>
   
       <table name="EXTENT_TEST_B">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="CLASS_NAME" required="true" primaryKey="true" type="VARCHAR" size="128"/>
           <column name="NAME" required="false" type="VARCHAR" size="100"/>
       </table>
   
       <table name="EXTENT_TEST_C">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +         <column name="CLASS_NAME" required="true" primaryKey="true" type="VARCHAR"
size="128"/>
           <column name="NAME" required="false" type="VARCHAR" size="100"/>
       </table>
   
       <table name="EXTENT_TEST_D">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +         <column name="CLASS_NAME" required="true" primaryKey="true" type="VARCHAR"
size="128"/>
           <column name="NAME" required="false" type="VARCHAR" size="100"/>
           <column name="D_FIELD" required="false" type="VARCHAR" size="100"/>
       </table>
  @@ -1448,5 +1452,6 @@
       <column name="ID" required="true" primaryKey="true" type="BIGINT"/>
       <column name="D_ATTRIB" type="INTEGER" required="false"/>
     </table>
  +
   
   </database>
  
  
  
  1.60      +31 -9     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- BrokerHelper.java	24 Jul 2004 19:26:40 -0000	1.59
  +++ BrokerHelper.java	7 Aug 2004 20:00:26 -0000	1.60
  @@ -837,10 +837,10 @@
       }
   
       /**
  -     * Add a Criteria for Concrete Class to the copied Query
  +     * Add a Criteria for Concrete Class to the copied Query.
        * @param aQuery
        * @param aCld
  -     * @return
  +     * @return a copy of the Query
        */
       public Query setConcreteClassCriteria(QueryByCriteria aQuery, ClassDescriptor aCld)
       {
  @@ -858,19 +858,29 @@
       }
   
       /**
  -     * Add a Criteria for Concrete Classes to the copied Query
  +     * Add a Criteria for Concrete Classes to the copied Query.<br>
  +     * use addEqualTo() if the List contains only 1 element, addIn() if it contains more
elements  
        * @param aQuery
        * @param concreteClasses
  -     * @return
  +     * @return a copy of the Query
        */
  -    public Query setConcreteClassCriteria(QueryByCriteria aQuery, Collection concreteClasses)
  +    public Query setConcreteClassCriteria(QueryByCriteria aQuery, List concreteClasses)
       {
           Query result = aQuery;
           
           if (concreteClasses != null)
           {
               QueryByCriteria copyQuery = QueryFactory.copyQuery(aQuery);
  -            copyQuery.getCriteria().addIn(ClassDescriptor.OJB_CONCRETE_CLASS, concreteClasses);
  +            
  +            if (concreteClasses.size() > 1)
  +            {
  +                copyQuery.getCriteria().addIn(ClassDescriptor.OJB_CONCRETE_CLASS, concreteClasses);
  +            }
  +            else
  +            {
  +                copyQuery.getCriteria().addEqualTo(ClassDescriptor.OJB_CONCRETE_CLASS,
concreteClasses.get(0));                
  +            }
  +            
               result = copyQuery;
           }
           
  @@ -907,12 +917,24 @@
       }
   
       /**
  -     * Holder for ClassDescriptor and it's concreteClasses 
  +     * Holder for ClassDescriptor and it's concreteClasses (a List of Strings)
        */
       public static class CldInfo
       {
  +        /**
  +         * the ClassDescriptor
  +         */
           public ClassDescriptor cld;
  -        public Collection concreteClasses;
  +        
  +        /**
  +         * a List of Strings
  +         */
  +        public List concreteClasses; 
  +        
  +        public String toString()
  +        {
  +            return cld.getFullTableName() + " " + concreteClasses;
  +        }
       }
   
       /**
  
  
  
  1.119     +70 -1     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.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- repository_junit.xml	4 Aug 2004 21:05:19 -0000	1.118
  +++ repository_junit.xml	7 Aug 2004 20:00:26 -0000	1.119
  @@ -2579,6 +2579,12 @@
          column="NAME"
          jdbc-type="VARCHAR"
        />
  +
  +    <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
   </class-descriptor>
   
   <class-descriptor
  @@ -2586,6 +2592,8 @@
   	table="EXTENT_TEST_B"
    >
       <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentC"
/>
  +    <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentE"
/>
  +    <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentF"
/>
   
       <field-descriptor
           name="objId"
  @@ -2599,6 +2607,11 @@
          column="NAME"
          jdbc-type="VARCHAR"
        />
  +    <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
   </class-descriptor>
   
   <class-descriptor
  @@ -2618,6 +2631,11 @@
          column="NAME"
          jdbc-type="VARCHAR"
        />
  +    <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
   </class-descriptor>
   
   <class-descriptor
  @@ -2638,6 +2656,11 @@
        />
   
        <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
  +     <field-descriptor
          name="dClassField"
          column="D_FIELD"
          jdbc-type="VARCHAR"
  @@ -2645,7 +2668,53 @@
        />
   </class-descriptor>
   
  +<class-descriptor
  +	class="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentE"
  +	table="EXTENT_TEST_B"
  + >
   
  +    <field-descriptor
  +        name="objId"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +     />
  +     <field-descriptor
  +       name="name"
  +       column="NAME"
  +       jdbc-type="VARCHAR"
  +     />
  +    <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
  +</class-descriptor>
  +
  +<class-descriptor
  +	class="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentF"
  +	table="EXTENT_TEST_B"
  + >
  +
  +    <field-descriptor
  +        name="objId"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"
  +     />
  +     <field-descriptor
  +       name="name"
  +       column="NAME"
  +       jdbc-type="VARCHAR"
  +     />
  +    <field-descriptor
  +         name="ojbConcreteClass"
  +         column="CLASS_NAME"
  +         jdbc-type="VARCHAR"
  +      />
  +</class-descriptor>
   
   
   
  
  
  
  1.4       +18 -4     db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java
  
  Index: MultipleTableExtentAwareQueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultipleTableExtentAwareQueryTest.java	27 Jul 2004 23:38:49 -0000	1.3
  +++ MultipleTableExtentAwareQueryTest.java	7 Aug 2004 20:00:26 -0000	1.4
  @@ -54,8 +54,14 @@
               a.setName(name);
               ExtentB b = new ExtentB();
               b.setName(name);
  +            ExtentE e = new ExtentE();
  +            e.setName(name);
  +            ExtentF f = new ExtentF();
  +            f.setName(name);
               broker.store(a);
               broker.store(b);
  +            broker.store(e);
  +            broker.store(f);
           }
           broker.commitTransaction();
   
  @@ -64,10 +70,10 @@
           QueryByCriteria query = QueryFactory.newQuery(BaseClass.class, crit);
           Collection result = broker.getCollectionByQuery(query);
           assertNotNull(result);
  -        assertEquals("Expect all objects extending 'BaseClass'", 2*objCount, result.size());
  +        assertEquals("Expect all objects extending 'BaseClass'", 4*objCount, result.size());
   
           int count = broker.getCount(query);
  -        assertEquals("Expect all objects extending 'BaseClass'", 2*objCount, count);
  +        assertEquals("Expect all objects extending 'BaseClass'", 4*objCount, count);
       }
   
       public void testQueryForExtentsOfAbstractClass()
  @@ -199,7 +205,6 @@
           QueryByCriteria queryC = QueryFactory.newQuery(ExtentC.class, crit);
           QueryByCriteria queryD = QueryFactory.newQuery(ExtentD.class, crit);
   
  -
           Collection result = broker.getCollectionByQuery(queryBaseClassIF);
           assertNotNull(result);
           assertEquals("Wrong number of objects", 6, result.size());
  @@ -308,6 +313,7 @@
       {
       }
   
  +
       public static class ExtentC extends ExtentB
       {
       }
  @@ -327,6 +333,13 @@
           }
       }
   
  +    public static class ExtentE extends ExtentB
  +    {
  +    }
  +
  +    public static class ExtentF extends ExtentB
  +    {
  +    }
       public static interface BaseClassIF extends Serializable
       {
           public int getObjId();
  @@ -339,6 +352,7 @@
       {
           private int objId;
           private String name;
  +        private String ojbConcreteClass = this.getClass().getName();
   
           public int getObjId()
           {
  
  
  

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