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 InheritanceMultipleTableTest.java
Date Wed, 17 Aug 2005 20:52:57 GMT
brj         2005/08/17 13:52:57

  Modified:    src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java
  Log:
  testcase for multiple joined tables when querying for base class
  
  Revision  Changes    Path
  1.15      +63 -1     db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- InheritanceMultipleTableTest.java	25 May 2005 20:02:32 -0000	1.14
  +++ InheritanceMultipleTableTest.java	17 Aug 2005 20:52:57 -0000	1.15
  @@ -41,6 +41,68 @@
           broker.serviceConnectionManager().setBatchMode(true);
       }
   
  +    public void testQueryInheritancedObjects()
  +    {
  +        if(ojbSkipKnownIssueProblem("Classes mapped to multiple joined tables will always
be instantiated " +
  +                " with the class type of the query, instead of the real type"))
  +        {
  +            return;
  +        }
  +
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  +        // store company with Employee/Executive/Manager
  +        Company company = prepareTestDataWithCompany(id_2, name);
  +        broker.beginTransaction();
  +        broker.store(company);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        // now we expect 6 objects when query for all Employee (this is the base class)
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("id_2", id_2);
  +        crit.addLike("name", "%" + name + "%");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +        int employeeCount = 0;
  +        int executiveCount = 0;
  +        int managerCount = 0;
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object obj =  iterator.next();
  +            if(obj instanceof Employee) ++employeeCount;
  +            if(obj instanceof Executive) ++executiveCount;
  +            if(obj instanceof Manager) ++managerCount;
  +        }
  +        assertEquals(6, employeeCount);
  +        assertEquals(5, executiveCount);
  +        assertEquals(3, managerCount);
  + 
  +        broker.clearCache();
  +        // now we expect 3 objects when query for all Manager
  +        crit = new Criteria();
  +        crit.addEqualTo("id_2", id_2);
  +        crit.addLike("name", "%" + name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +        employeeCount = 0;
  +        executiveCount = 0;
  +        managerCount = 0;
  +         for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object obj =  iterator.next();
  +            if(obj instanceof Employee) ++employeeCount;
  +            if(obj instanceof Executive) ++executiveCount;
  +            if(obj instanceof Manager) ++managerCount;
  +        }
  +        assertEquals(3, employeeCount);
  +        assertEquals(3, executiveCount);
  +        assertEquals(3, managerCount);
  +     }
  +
       public void testInheritancedObjectsInCollectionReferences()
       {
           if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple
joined tables only" +
  
  
  

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