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 Sun, 22 May 2005 16:06:38 GMT
brj         2005/05/22 09:06:38

  Modified:    src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java
  Log:
  new testcase for outer join hint (this one fails)
  
  Revision  Changes    Path
  1.13      +977 -919  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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- InheritanceMultipleTableTest.java	18 Dec 2004 14:01:16 -0000	1.12
  +++ InheritanceMultipleTableTest.java	22 May 2005 16:06:38 -0000	1.13
  @@ -1,919 +1,977 @@
  -package org.apache.ojb.broker;
  -
  -import java.io.Serializable;
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.Iterator;
  -import java.util.List;
  -
  -import org.apache.commons.lang.SerializationUtils;
  -import org.apache.commons.lang.builder.EqualsBuilder;
  -import org.apache.commons.lang.builder.ToStringBuilder;
  -import org.apache.commons.lang.builder.ToStringStyle;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -import org.apache.ojb.broker.query.Criteria;
  -import org.apache.ojb.broker.query.Query;
  -import org.apache.ojb.broker.query.QueryFactory;
  -import org.apache.ojb.junit.PBTestCase;
  -
  -/**
  - * These tests check inheritance using multiple tables via 1:1 reference and "super" keyword in
  - * reference descriptor. The test objects use a composite PK.
  - * One autoincrement PK field - Integer. One non-autoincrement PK field with manually set PK- Long.
  - *
  - * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  - * @version $Id$
  - */
  -public class InheritanceMultipleTableTest extends PBTestCase
  -{
  -    public static void main(String[] args)
  -    {
  -        junit.textui.TestRunner.main(new String[]{InheritanceMultipleTableTest.class.getName()});
  -    }
  -
  -    public void setUp() throws Exception
  -    {
  -        super.setUp();
  -        // allow to batch statements
  -        broker.serviceConnectionManager().setBatchMode(true);
  -    }
  -
  -    public void testInheritancedObjectsInCollectionReferences()
  -    {
  -        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple joined tables only" +
  -                " return base class type instances"))
  -        {
  -            return;
  -        }
  -
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  -        Manager m_1 = new Manager(id_2, name + "_manager_1");
  -        Manager m_2 = new Manager(id_2, name + "_manager_2");
  -        Manager m_3 = new Manager(id_2, name + "_manager_3");
  -        m_3.setDepartment("none");
  -        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  -        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  -        Employee em = new Employee(id_2, name + "_employee");
  -
  -        ArrayList employees = new ArrayList();
  -        employees.add(m_1);
  -        employees.add(m_2);
  -        employees.add(m_3);
  -        employees.add(ex_1);
  -        employees.add(ex_2);
  -        employees.add(em);
  -
  -        Company company = new Company(id_2, name, employees);
  -        broker.beginTransaction();
  -        broker.store(company);
  -        broker.commitTransaction();
  -
  -        broker.clearCache();
  -        Criteria crit = new Criteria();
  -        crit.addEqualTo("id", id_2);
  -        Query query = QueryFactory.newQuery(Company.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -        Company newCompany = (Company) result.iterator().next();
  -        List newEmployees = newCompany.getEmployees();
  -        assertNotNull(newEmployees);
  -        assertEquals(employees.size(), newEmployees.size());
  -        int countEmployee = 0;
  -        int countExecutive = 0;
  -        int countManager = 0;
  -        for(int i = 0; i < newEmployees.size(); i++)
  -        {
  -            Object o =  newEmployees.get(i);
  -            if(o instanceof Employee)
  -            {
  -                ++countEmployee;
  -            }
  -            if(o instanceof Executive)
  -            {
  -                ++countExecutive;
  -            }
  -            if(o instanceof Manager)
  -            {
  -                ++countManager;
  -            }
  -        }
  -        assertEquals(6, countEmployee);
  -        /*
  -        bug:
  -        expect that the real classes will be populated
  -        currently this does not happen, only objects of
  -        type Employee will be returned.
  -        */
  -        assertEquals(5, countExecutive);
  -        assertEquals(3, countManager);
  -    }
  -
  -    public void testUpdate()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testUpdate" + timestamp;
  -        Employee em1 = new Employee(id_2, "employee_" + name);
  -        Executive ex1 = new Executive(id_2, "executive_" + name, "department_1", null);
  -        Executive ex2 = new Executive(id_2, "executive_" + name, "department_2", null);
  -        ArrayList list = new ArrayList();
  -        list.add(ex1);
  -        list.add(ex2);
  -        Manager m1 = new Manager(id_2, "manager_" + name);
  -        m1.setExecutives(list);
  -
  -        broker.beginTransaction();
  -        broker.store(em1);
  -        broker.store(m1);
  -        broker.commitTransaction();
  -
  -        Identity m1_oid = new Identity(m1, broker);
  -        Identity ex1_oid = new Identity(ex1, broker);
  -        Identity em1_oid = new Identity(em1, broker);
  -
  -        broker.clearCache();
  -
  -        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  -        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  -        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  -
  -        assertEquals(2, newM1.getExecutives().size());
  -
  -        newEm1.setName("**updated_" + name);
  -        newM1.setName("**updated_" + name);
  -        ((Executive) newM1.getExecutives().get(0)).setName("**updated_" + name);
  -
  -        broker.beginTransaction();
  -        broker.store(newEm1);
  -        broker.store(newM1);
  -        broker.store(newEx1);
  -        broker.commitTransaction();
  -
  -        broker.clearCache();
  -
  -        em1 = (Employee) broker.getObjectByIdentity(em1_oid);
  -        ex1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  -        m1 = (Manager) broker.getObjectByIdentity(m1_oid);
  -
  -        assertEquals(newEm1, em1);
  -        assertEquals(newEx1, ex1);
  -        assertEquals(newM1, m1);
  -
  -        assertEquals(2, m1.getExecutives().size());
  -    }
  -
  -    public void testStoreUpdateQuerySerialized_2()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testStoreUpdateQuerySerialized_" + timestamp;
  -        Manager m_1 = new Manager(id_2, name + "_manager_1");
  -        Manager m_2 = new Manager(id_2, name + "_manager_2");
  -        Manager m_3 = new Manager(id_2, name + "_manager_3");
  -        m_3.setDepartment("none");
  -
  -        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  -        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  -
  -        Employee em = new Employee(id_2, name + "_employee");
  -
  -        broker.beginTransaction();
  -        broker.store(em);
  -        broker.store(m_1);
  -        broker.store(m_3);
  -        broker.store(ex_1);
  -        broker.store(m_2);
  -        broker.store(ex_2);
  -        broker.commitTransaction();
  -
  -        broker.clearCache();
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "none");
  -        Query query = QueryFactory.newQuery(Manager.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Employee.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(6, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Executive.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(5, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(3, result.size());
  -
  -        em = (Employee) SerializationUtils.clone(em);
  -        m_1 = (Manager) SerializationUtils.clone(m_1);
  -        m_2 = (Manager) SerializationUtils.clone(m_2);
  -        m_3 = (Manager) SerializationUtils.clone(m_3);
  -        ex_1 = (Executive) SerializationUtils.clone(ex_1);
  -        ex_2 = (Executive) SerializationUtils.clone(ex_2);
  -
  -        em.setName(em.getName() + "_updated");
  -        m_1.setName(m_1.getName() + "_updated");
  -        m_1.setDepartment("_updated_Dep");
  -        m_2.setName(m_2.getName() + "_updated");
  -        m_3.setName(m_3.getName() + "_updated");
  -        ex_1.setName(ex_1.getName() + "_updated");
  -        ex_2.setName(ex_2.getName() + "_updated");
  -
  -        broker.clearCache();
  -        broker.beginTransaction();
  -        //========================================
  -        // update only modified fields
  -        broker.update(em, new String[]{"name"});
  -        broker.update(m_1, new String[]{"name", "department"});
  -        broker.update(m_3, new String[]{"name"});
  -        broker.update(ex_1, new String[]{"name"});
  -        broker.update(m_2, new String[]{"name"});
  -        broker.update(ex_2, new String[]{"name"});
  -        //========================================
  -        broker.commitTransaction();
  -
  -        /*
  -        after de/serialization and update we expect the same row count in
  -        each table
  -        */
  -        broker.clearCache();
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "_updated_Dep");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 1, result.size());
  -        Manager newMan = (Manager) result.iterator().next();
  -        assertEquals(m_1.getName(), newMan.getName());
  -        assertEquals(m_1.getDepartment(), newMan.getDepartment());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "none");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 1, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Employee.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 6, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Executive.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 5, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 3, result.size());
  -    }
  -
  -    public void testObjectExistence()
  -    {
  -        Manager target_1 = new Manager(new Long(1), "testObjectExistence");
  -        Manager target_2 = new Manager(new Long(System.currentTimeMillis()), "testObjectExistence");
  -
  -        Identity oid_1 = broker.serviceIdentity().buildIdentity(target_1);
  -        Identity oid_2 = broker.serviceIdentity().buildIdentity(target_2);
  -
  -        ClassDescriptor cld = broker.getClassDescriptor(Manager.class);
  -
  -        boolean b_1 = broker.serviceJdbcAccess().doesExist(cld, oid_1);
  -        boolean b_2 = broker.serviceJdbcAccess().doesExist(cld, oid_2);
  -        assertFalse(b_1);
  -        assertFalse(b_2);
  -    }
  -
  -    public void testStoreUpdateQuerySerialized()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testStoreUpdateQuerySerialized_" + timestamp;
  -        Manager m_1 = new Manager(id_2, name + "_manager_1");
  -        Manager m_2 = new Manager(id_2, name + "_manager_2");
  -        Manager m_3 = new Manager(id_2, name + "_manager_3");
  -        m_3.setDepartment("none");
  -
  -        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  -        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  -
  -        Employee em = new Employee(id_2, name + "_employee");
  -
  -        broker.beginTransaction();
  -        broker.store(em);
  -        broker.store(m_1);
  -        broker.store(m_3);
  -        broker.store(ex_1);
  -        broker.store(m_2);
  -        broker.store(ex_2);
  -        broker.commitTransaction();
  -
  -        broker.clearCache();
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "none");
  -        Query query = QueryFactory.newQuery(Manager.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Employee.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(6, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Executive.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(5, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(3, result.size());
  -
  -        em = (Employee) SerializationUtils.clone(em);
  -        m_1 = (Manager) SerializationUtils.clone(m_1);
  -        m_2 = (Manager) SerializationUtils.clone(m_2);
  -        m_3 = (Manager) SerializationUtils.clone(m_3);
  -        ex_1 = (Executive) SerializationUtils.clone(ex_1);
  -        ex_2 = (Executive) SerializationUtils.clone(ex_2);
  -
  -        em.setName(em.getName() + "_updated");
  -        m_1.setName(m_1.getName() + "_updated");
  -        m_2.setName(m_2.getName() + "_updated");
  -        m_3.setName(m_3.getName() + "_updated");
  -        ex_1.setName(ex_1.getName() + "_updated");
  -        ex_2.setName(ex_2.getName() + "_updated");
  -
  -        broker.clearCache();
  -        broker.beginTransaction();
  -        broker.store(em);
  -        broker.store(m_1);
  -        broker.store(m_3);
  -        broker.store(ex_1);
  -        broker.store(m_2);
  -        broker.store(ex_2);
  -        broker.commitTransaction();
  -
  -        /*
  -        after de/serialization and update we expect the same row count in
  -        each table
  -        */
  -        broker.clearCache();
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "none");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 1, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Employee.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 6, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Executive.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 5, result.size());
  -
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals("Expect the same number of objects as before update", 3, result.size());
  -    }
  -
  -    private void prepareForQueryTests(Long id_2, String name)
  -    {
  -        Manager m_1 = new Manager(id_2, name + "_manager_1");
  -        Manager m_2 = new Manager(id_2, name + "_manager_2");
  -        Manager m_3 = new Manager(id_2, name + "_manager_3");
  -        m_3.setDepartment("none");
  -        Address a_1 = new Address("snob allee");
  -        m_1.setAddress(a_1);
  -
  -        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  -        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  -
  -        Employee em = new Employee(id_2, name + "_employee");
  -        Address a_2 = new Address("cockroaches valley");
  -        em.setAddress(a_2);
  -
  -        broker.beginTransaction();
  -        broker.store(m_1);
  -        broker.store(m_2);
  -        broker.store(m_3);
  -        broker.store(ex_1);
  -        broker.store(ex_2);
  -        broker.store(em);
  -        broker.commitTransaction();
  -    }
  -
  -    public void testQuery_InheritedObjects()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_InheritedObjects" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        Query query = QueryFactory.newQuery(Employee.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(6, result.size());
  -        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  -        {
  -            Employee obj = (Employee) iterator.next();
  -            assertNotNull(obj.getName());
  -        }
  -
  -        broker.clearCache();
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Executive.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(5, result.size());
  -        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  -        {
  -            Executive obj = (Executive) iterator.next();
  -            assertNotNull(obj.getName());
  -        }
  -
  -        broker.clearCache();
  -        crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        query = QueryFactory.newQuery(Manager.class, crit);
  -        result = broker.getCollectionByQuery(query);
  -        assertEquals(3, result.size());
  -        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  -        {
  -            Manager obj = (Manager) iterator.next();
  -            assertNotNull(obj.getName());
  -        }
  -    }
  -
  -    public void testQuery_InheritedField()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_InheritedField" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        broker.clearCache();
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("department", "none");
  -        Query query = QueryFactory.newQuery(Manager.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -    }
  -
  -    public void testQuery_Reference()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_Reference" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addLike("address.street", "%valley");
  -        Query query = QueryFactory.newQuery(Employee.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -        Employee emp = (Employee) result.iterator().next();
  -        assertNotNull(emp.getAddress());
  -        assertEquals("cockroaches valley", emp.getAddress().getStreet());
  -    }
  -
  -    public void testQuery_InheritedReference_1()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_InheritedReference_1" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addEqualTo("address.street", "snob allee");
  -        Query query = QueryFactory.newQuery(Manager.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -        Manager retManager = (Manager) result.iterator().next();
  -        assertNotNull(retManager);
  -        assertEquals(name + "_manager_1", retManager.getName());
  -        assertNotNull(retManager.getAddress());
  -        assertEquals("snob allee", retManager.getAddress().getStreet());
  -    }
  -
  -    public void testQuery_InheritedReference_2()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_InheritedReference_2" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addEqualTo("address.street", "snob allee");
  -        Query query = QueryFactory.newQuery(Executive.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -
  -        Executive retManager = (Executive) result.iterator().next();
  -        assertNotNull(retManager);
  -        assertEquals(name + "_manager_1", retManager.getName());
  -    }
  -
  -    public void testQuery_InheritedReference_3()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testQuery_InheritedReference_3" + timestamp;
  -        prepareForQueryTests(id_2, name);
  -        broker.clearCache();
  -
  -        Criteria crit = new Criteria();
  -        crit.addLike("name", name + "%");
  -        crit.addEqualTo("address.street", "snob allee");
  -        Query query = QueryFactory.newQuery(Employee.class, crit);
  -        Collection result = broker.getCollectionByQuery(query);
  -        assertEquals(1, result.size());
  -    }
  -
  -    public void testInsertQuery()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testInsert" + timestamp;
  -        Employee em1 = new Employee(id_2, name);
  -        Executive ex1 = new Executive(id_2, name, "department_1", null);
  -        Executive ex2 = new Executive(id_2, name, "department_2", null);
  -        ArrayList list = new ArrayList();
  -        list.add(ex1);
  -        list.add(ex2);
  -        Manager m1 = new Manager(id_2, name);
  -        m1.setExecutives(list);
  -
  -        broker.beginTransaction();
  -        broker.store(em1);
  -        broker.store(m1);
  -        broker.commitTransaction();
  -
  -        Identity m1_oid = new Identity(m1, broker);
  -        Identity ex1_oid = new Identity(ex1, broker);
  -        Identity em1_oid = new Identity(em1, broker);
  -
  -        broker.clearCache();
  -
  -        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  -        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  -        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  -
  -        assertEquals(em1, newEm1);
  -        assertEquals(ex1, newEx1);
  -        assertEquals(m1, newM1);
  -        assertEquals(name, newEx1.getName());
  -        assertEquals(name, newM1.getName());
  -
  -        assertEquals(2, newM1.getExecutives().size());
  -
  -        Criteria crit = new Criteria();
  -        crit.addEqualTo("name", name);
  -        Query queryEmployee = QueryFactory.newQuery(Employee.class, crit);
  -        Query queryExecutive = QueryFactory.newQuery(Executive.class, crit);
  -        Query queryManager = QueryFactory.newQuery(Manager.class, crit);
  -
  -        Collection result = broker.getCollectionByQuery(queryEmployee);
  -        assertEquals(4, result.size());
  -
  -        result = broker.getCollectionByQuery(queryExecutive);
  -        assertEquals(3, result.size());
  -
  -        result = broker.getCollectionByQuery(queryManager);
  -        assertEquals(1, result.size());
  -    }
  -
  -    public void testDelete()
  -    {
  -        long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testUpdate" + timestamp;
  -        Employee em1 = new Employee(id_2, "employee_" + name);
  -        Executive ex1 = new Executive(id_2, "executive_" + name, "department_1", null);
  -        Executive ex2 = new Executive(id_2, "executive_" + name, "department_2", null);
  -        ArrayList list = new ArrayList();
  -        list.add(ex1);
  -        list.add(ex2);
  -        Manager m1 = new Manager(id_2, "manager_" + name);
  -        m1.setExecutives(list);
  -
  -        broker.beginTransaction();
  -        broker.store(em1);
  -        broker.store(m1);
  -        broker.commitTransaction();
  -
  -        Identity m1_oid = new Identity(m1, broker);
  -        Identity ex1_oid = new Identity(ex1, broker);
  -        Identity em1_oid = new Identity(em1, broker);
  -
  -        broker.clearCache();
  -
  -        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  -        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  -        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  -
  -        assertNotNull(newEm1);
  -        assertNotNull(newEx1);
  -        assertNotNull(newM1);
  -        assertEquals(2, newM1.getExecutives().size());
  -
  -        broker.beginTransaction();
  -        broker.delete(newEm1);
  -        broker.delete(newEx1);
  -        broker.delete(newM1);
  -        broker.commitTransaction();
  -
  -        newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  -        newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  -        newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  -
  -        assertNull(newEm1);
  -        assertNull(newEx1);
  -        assertNull(newM1);
  -    }
  -
  -    //************************************************************
  -    // inner classes used for test
  -    //************************************************************
  -    public static class Manager extends Executive
  -    {
  -        private List executives;
  -
  -        public Manager()
  -        {
  -        }
  -
  -        public Manager(Long id_2, String name)
  -        {
  -            super(id_2, name, null, null);
  -        }
  -
  -        public List getExecutives()
  -        {
  -            return executives;
  -        }
  -
  -        public void setExecutives(List executives)
  -        {
  -            this.executives = executives;
  -        }
  -    }
  -
  -    public static class Executive extends Employee
  -    {
  -        private String department;
  -        private Manager manager;
  -
  -        public Executive()
  -        {
  -        }
  -
  -        public Executive(Long id_2, String name, String department, Manager manager)
  -        {
  -            super(id_2, name);
  -            this.department = department;
  -            this.manager = manager;
  -        }
  -
  -        public String getDepartment()
  -        {
  -            return department;
  -        }
  -
  -        public void setDepartment(String department)
  -        {
  -            this.department = department;
  -        }
  -
  -        public Manager getManager()
  -        {
  -            return manager;
  -        }
  -
  -        public void setManager(Manager manager)
  -        {
  -            this.manager = manager;
  -        }
  -
  -        public boolean equals(Object obj)
  -        {
  -            if (!(obj instanceof Executive))
  -            {
  -                return false;
  -            }
  -            Executive ex = (Executive) obj;
  -            return new EqualsBuilder().append(getId(), ex.getId())
  -                    .append(getName(), ex.getName())
  -                    .append(getDepartment(), ex.getDepartment()).isEquals();
  -        }
  -    }
  -
  -    public static class Employee implements Serializable
  -    {
  -        private Integer id;
  -        private Long id_2;
  -        private String name;
  -        private AddressIF address;
  -
  -        public Employee()
  -        {
  -        }
  -
  -        public Employee(Long id_2, String name)
  -        {
  -            this.id_2 = id_2;
  -            this.name = name;
  -        }
  -
  -        public Integer getId()
  -        {
  -            return id;
  -        }
  -
  -        public Long getId_2()
  -        {
  -            return id_2;
  -        }
  -
  -        public void setId_2(Long id_2)
  -        {
  -            this.id_2 = id_2;
  -        }
  -
  -        public void setId(Integer id)
  -        {
  -            this.id = id;
  -        }
  -
  -        public AddressIF getAddress()
  -        {
  -            return address;
  -        }
  -
  -        public void setAddress(AddressIF address)
  -        {
  -            this.address = address;
  -        }
  -
  -        public String getName()
  -        {
  -            return name;
  -        }
  -
  -        public void setName(String name)
  -        {
  -            this.name = name;
  -        }
  -
  -        public boolean equals(Object obj)
  -        {
  -            if (!(obj instanceof Employee))
  -            {
  -                return false;
  -            }
  -            Employee em = (Employee) obj;
  -            return new EqualsBuilder()
  -                    .append(getId(), em.getId())
  -                    .append(getId_2(), em.getId_2())
  -                    .append(getName(), em.getName())
  -                    .isEquals();
  -        }
  -
  -        public String toString()
  -        {
  -            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Employee.class);
  -        }
  -    }
  -
  -    public static class Address implements AddressIF
  -    {
  -        private Integer id;
  -        private String street;
  -
  -        public Address()
  -        {
  -        }
  -
  -        public Address(String street)
  -        {
  -            this.street = street;
  -        }
  -
  -        public Integer getId()
  -        {
  -            return id;
  -        }
  -
  -        public void setId(Integer id)
  -        {
  -            this.id = id;
  -        }
  -
  -        public String getStreet()
  -        {
  -            return street;
  -        }
  -
  -        public void setStreet(String street)
  -        {
  -            this.street = street;
  -        }
  -    }
  -
  -    public static interface AddressIF
  -    {
  -        public Integer getId();
  -
  -        public void setId(Integer id);
  -
  -        public String getStreet();
  -
  -        public void setStreet(String street);
  -    }
  -
  -    public static class Company
  -    {
  -        private Long id;
  -        private String name;
  -        private List  employees;
  -
  -        public Company()
  -        {
  -        }
  -
  -        public Company(Long id, String name, List employees)
  -        {
  -            this.id = id;
  -            this.name = name;
  -            this.employees = employees;
  -        }
  -
  -        public Long getId()
  -        {
  -            return id;
  -        }
  -
  -        public void setId(Long id)
  -        {
  -            this.id = id;
  -        }
  -
  -        public String getName()
  -        {
  -            return name;
  -        }
  -
  -        public void setName(String name)
  -        {
  -            this.name = name;
  -        }
  -
  -        public List getEmployees()
  -        {
  -            return employees;
  -        }
  -
  -        public void setEmployees(List employees)
  -        {
  -            this.employees = employees;
  -        }
  -    }
  -}
  +package org.apache.ojb.broker;
  +
  +import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Collections;
  +import java.util.Iterator;
  +import java.util.List;
  +
  +import org.apache.commons.lang.SerializationUtils;
  +import org.apache.commons.lang.builder.EqualsBuilder;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
  +import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.query.Criteria;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByCriteria;
  +import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.PBTestCase;
  +
  +/**
  + * These tests check inheritance using multiple tables via 1:1 reference and "super" keyword in
  + * reference descriptor. The test objects use a composite PK.
  + * One autoincrement PK field - Integer. One non-autoincrement PK field with manually set PK- Long.
  + *
  + * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  + * @version $Id$
  + */
  +public class InheritanceMultipleTableTest extends PBTestCase
  +{
  +    public static void main(String[] args)
  +    {
  +        junit.textui.TestRunner.main(new String[]{InheritanceMultipleTableTest.class.getName()});
  +    }
  +
  +    public void setUp() throws Exception
  +    {
  +        super.setUp();
  +        // allow to batch statements
  +        broker.serviceConnectionManager().setBatchMode(true);
  +    }
  +
  +    public void testInheritancedObjectsInCollectionReferences()
  +    {
  +        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple joined tables only" +
  +                " return base class type instances"))
  +        {
  +            return;
  +        }
  +
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  +        Company company = prepareTestDataWithCompany(id_2, name);
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("id", id_2);
  +        Query query = QueryFactory.newQuery(Company.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +        
  +        Company newCompany = (Company) result.iterator().next();
  +        List newEmployees = newCompany.getEmployees();
  +        assertNotNull(newEmployees);
  +        assertEquals(company.getEmployees().size(), newEmployees.size());
  +        List newManagers = newCompany.getManagers();
  +        assertNotNull(newManagers);
  +        assertEquals(company.getManagers().size(), newManagers.size());
  +
  +        int countEmployee = 0;
  +        int countExecutive = 0;
  +        int countManager = 0;
  +        for(int i = 0; i < newEmployees.size(); i++)
  +        {
  +            Object o =  newEmployees.get(i);
  +            if(o instanceof Employee)
  +            {
  +                ++countEmployee;
  +            }
  +            if(o instanceof Executive)
  +            {
  +                ++countExecutive;
  +            }
  +            if(o instanceof Manager)
  +            {
  +                ++countManager;
  +            }
  +        }
  +        assertEquals(6, countEmployee);
  +        /*
  +        bug:
  +        expect that the real classes will be populated
  +        currently this does not happen, only objects of
  +        type Employee will be returned.
  +        */
  +        assertEquals(5, countExecutive);
  +        assertEquals(3, countManager);
  +    }
  +
  +	private Company prepareTestDataWithCompany(Long id_2, String name) {
  +		Manager m_1 = new Manager(id_2, name + "_manager_1");
  +        Manager m_2 = new Manager(id_2, name + "_manager_2");
  +        Manager m_3 = new Manager(id_2, name + "_manager_3");
  +        m_3.setDepartment("none");
  +        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Employee em = new Employee(id_2, name + "_employee");
  +
  +        ArrayList employees = new ArrayList();
  +        employees.add(m_1);
  +        employees.add(m_2);
  +        employees.add(m_3);
  +        employees.add(ex_1);
  +        employees.add(ex_2);
  +        employees.add(em);
  +
  +        ArrayList managers = new ArrayList();
  +        managers.add(m_1);
  +        managers.add(m_2);
  +        managers.add(m_3);
  +        
  +        Company company = new Company(id_2, name, employees, managers);
  +        broker.beginTransaction();
  +        broker.store(company);
  +        broker.commitTransaction();
  +		return company;
  +	}
  +
  +    public void testUpdate()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testUpdate" + timestamp;
  +        Employee em1 = new Employee(id_2, "employee_" + name);
  +        Executive ex1 = new Executive(id_2, "executive_" + name, "department_1", null);
  +        Executive ex2 = new Executive(id_2, "executive_" + name, "department_2", null);
  +        ArrayList list = new ArrayList();
  +        list.add(ex1);
  +        list.add(ex2);
  +        Manager m1 = new Manager(id_2, "manager_" + name);
  +        m1.setExecutives(list);
  +
  +        broker.beginTransaction();
  +        broker.store(em1);
  +        broker.store(m1);
  +        broker.commitTransaction();
  +
  +        Identity m1_oid = new Identity(m1, broker);
  +        Identity ex1_oid = new Identity(ex1, broker);
  +        Identity em1_oid = new Identity(em1, broker);
  +
  +        broker.clearCache();
  +
  +        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  +        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  +        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  +
  +        assertEquals(2, newM1.getExecutives().size());
  +
  +        newEm1.setName("**updated_" + name);
  +        newM1.setName("**updated_" + name);
  +        ((Executive) newM1.getExecutives().get(0)).setName("**updated_" + name);
  +
  +        broker.beginTransaction();
  +        broker.store(newEm1);
  +        broker.store(newM1);
  +        broker.store(newEx1);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        em1 = (Employee) broker.getObjectByIdentity(em1_oid);
  +        ex1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  +        m1 = (Manager) broker.getObjectByIdentity(m1_oid);
  +
  +        assertEquals(newEm1, em1);
  +        assertEquals(newEx1, ex1);
  +        assertEquals(newM1, m1);
  +
  +        assertEquals(2, m1.getExecutives().size());
  +    }
  +
  +    public void testStoreUpdateQuerySerialized_2()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testStoreUpdateQuerySerialized_" + timestamp;
  +        Manager m_1 = new Manager(id_2, name + "_manager_1");
  +        Manager m_2 = new Manager(id_2, name + "_manager_2");
  +        Manager m_3 = new Manager(id_2, name + "_manager_3");
  +        m_3.setDepartment("none");
  +
  +        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  +
  +        Employee em = new Employee(id_2, name + "_employee");
  +
  +        broker.beginTransaction();
  +        broker.store(em);
  +        broker.store(m_1);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(m_2);
  +        broker.store(ex_2);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Employee.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +
  +        em = (Employee) SerializationUtils.clone(em);
  +        m_1 = (Manager) SerializationUtils.clone(m_1);
  +        m_2 = (Manager) SerializationUtils.clone(m_2);
  +        m_3 = (Manager) SerializationUtils.clone(m_3);
  +        ex_1 = (Executive) SerializationUtils.clone(ex_1);
  +        ex_2 = (Executive) SerializationUtils.clone(ex_2);
  +
  +        em.setName(em.getName() + "_updated");
  +        m_1.setName(m_1.getName() + "_updated");
  +        m_1.setDepartment("_updated_Dep");
  +        m_2.setName(m_2.getName() + "_updated");
  +        m_3.setName(m_3.getName() + "_updated");
  +        ex_1.setName(ex_1.getName() + "_updated");
  +        ex_2.setName(ex_2.getName() + "_updated");
  +
  +        broker.clearCache();
  +        broker.beginTransaction();
  +        //========================================
  +        // update only modified fields
  +        broker.update(em, new String[]{"name"});
  +        broker.update(m_1, new String[]{"name", "department"});
  +        broker.update(m_3, new String[]{"name"});
  +        broker.update(ex_1, new String[]{"name"});
  +        broker.update(m_2, new String[]{"name"});
  +        broker.update(ex_2, new String[]{"name"});
  +        //========================================
  +        broker.commitTransaction();
  +
  +        /*
  +        after de/serialization and update we expect the same row count in
  +        each table
  +        */
  +        broker.clearCache();
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "_updated_Dep");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 1, result.size());
  +        Manager newMan = (Manager) result.iterator().next();
  +        assertEquals(m_1.getName(), newMan.getName());
  +        assertEquals(m_1.getDepartment(), newMan.getDepartment());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 1, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Employee.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 3, result.size());
  +    }
  +
  +    public void testObjectExistence()
  +    {
  +        Manager target_1 = new Manager(new Long(1), "testObjectExistence");
  +        Manager target_2 = new Manager(new Long(System.currentTimeMillis()), "testObjectExistence");
  +
  +        Identity oid_1 = broker.serviceIdentity().buildIdentity(target_1);
  +        Identity oid_2 = broker.serviceIdentity().buildIdentity(target_2);
  +
  +        ClassDescriptor cld = broker.getClassDescriptor(Manager.class);
  +
  +        boolean b_1 = broker.serviceJdbcAccess().doesExist(cld, oid_1);
  +        boolean b_2 = broker.serviceJdbcAccess().doesExist(cld, oid_2);
  +        assertFalse(b_1);
  +        assertFalse(b_2);
  +    }
  +
  +    public void testStoreUpdateQuerySerialized()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testStoreUpdateQuerySerialized_" + timestamp;
  +        Manager m_1 = new Manager(id_2, name + "_manager_1");
  +        Manager m_2 = new Manager(id_2, name + "_manager_2");
  +        Manager m_3 = new Manager(id_2, name + "_manager_3");
  +        m_3.setDepartment("none");
  +
  +        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  +
  +        Employee em = new Employee(id_2, name + "_employee");
  +
  +        broker.beginTransaction();
  +        broker.store(em);
  +        broker.store(m_1);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(m_2);
  +        broker.store(ex_2);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Employee.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +
  +        em = (Employee) SerializationUtils.clone(em);
  +        m_1 = (Manager) SerializationUtils.clone(m_1);
  +        m_2 = (Manager) SerializationUtils.clone(m_2);
  +        m_3 = (Manager) SerializationUtils.clone(m_3);
  +        ex_1 = (Executive) SerializationUtils.clone(ex_1);
  +        ex_2 = (Executive) SerializationUtils.clone(ex_2);
  +
  +        em.setName(em.getName() + "_updated");
  +        m_1.setName(m_1.getName() + "_updated");
  +        m_2.setName(m_2.getName() + "_updated");
  +        m_3.setName(m_3.getName() + "_updated");
  +        ex_1.setName(ex_1.getName() + "_updated");
  +        ex_2.setName(ex_2.getName() + "_updated");
  +
  +        broker.clearCache();
  +        broker.beginTransaction();
  +        broker.store(em);
  +        broker.store(m_1);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(m_2);
  +        broker.store(ex_2);
  +        broker.commitTransaction();
  +
  +        /*
  +        after de/serialization and update we expect the same row count in
  +        each table
  +        */
  +        broker.clearCache();
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 1, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Employee.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 6, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 5, result.size());
  +
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals("Expect the same number of objects as before update", 3, result.size());
  +    }
  +
  +    private void prepareForQueryTests(Long id_2, String name)
  +    {
  +        Manager m_1 = new Manager(id_2, name + "_manager_1");
  +        Manager m_2 = new Manager(id_2, name + "_manager_2");
  +        Manager m_3 = new Manager(id_2, name + "_manager_3");
  +        m_3.setDepartment("none");
  +        Address a_1 = new Address("snob allee");
  +        m_1.setAddress(a_1);
  +
  +        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  +
  +        Employee em = new Employee(id_2, name + "_employee");
  +        Address a_2 = new Address("cockroaches valley");
  +        em.setAddress(a_2);
  +
  +        broker.beginTransaction();
  +        broker.store(m_1);
  +        broker.store(m_2);
  +        broker.store(m_3);
  +        broker.store(ex_1);
  +        broker.store(ex_2);
  +        broker.store(em);
  +        broker.commitTransaction();
  +    }
  +
  +    public void testQuery_InheritedObjects()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_InheritedObjects" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(6, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Employee obj = (Employee) iterator.next();
  +            assertNotNull(obj.getName());
  +        }
  +
  +        broker.clearCache();
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Executive.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(5, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Executive obj = (Executive) iterator.next();
  +            assertNotNull(obj.getName());
  +        }
  +
  +        broker.clearCache();
  +        crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        query = QueryFactory.newQuery(Manager.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Manager obj = (Manager) iterator.next();
  +            assertNotNull(obj.getName());
  +        }
  +    }
  +
  +    public void testQuery_InheritedField()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_InheritedField" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("department", "none");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testQuery_Reference()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_Reference" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("address.street", "%valley");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +        Employee emp = (Employee) result.iterator().next();
  +        assertNotNull(emp.getAddress());
  +        assertEquals("cockroaches valley", emp.getAddress().getStreet());
  +    }
  +
  +  public void testQuery_ReferenceOuterJoin()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_ReferenceOuterJoin" + timestamp;
  +        Company comp = prepareTestDataWithCompany(id_2, name);
  +        
  +        // Store a dummy company
  +        Company dummyComp = new Company(new Long(System.currentTimeMillis()), name + "_dummy", 
  +        		Collections.EMPTY_LIST, Collections.EMPTY_LIST);
  +        broker.beginTransaction();
  +        broker.store(dummyComp);
  +        broker.commitTransaction();
  +        
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addLike("managers.name", name + "%");
  +        QueryByCriteria query = QueryFactory.newQuery(Company.class, crit, true);
  +        query.addOrderByAscending("id");
  +        query.setPathOuterJoin("managers");	
  +        
  +        SqlGenerator sqlg = broker.serviceSqlGenerator();
  +        String sql = sqlg.getPreparedSelectStatement(query, broker.getClassDescriptor(Company.class));
  +
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(2, result.size());								// should retrieve both companies
  +     }
  +  
  +    public void testQuery_InheritedReference_1()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_InheritedReference_1" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Manager.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +        Manager retManager = (Manager) result.iterator().next();
  +        assertNotNull(retManager);
  +        assertEquals(name + "_manager_1", retManager.getName());
  +        assertNotNull(retManager.getAddress());
  +        assertEquals("snob allee", retManager.getAddress().getStreet());
  +    }
  +
  +    public void testQuery_InheritedReference_2()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_InheritedReference_2" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Executive.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +
  +        Executive retManager = (Executive) result.iterator().next();
  +        assertNotNull(retManager);
  +        assertEquals(name + "_manager_1", retManager.getName());
  +    }
  +
  +    public void testQuery_InheritedReference_3()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQuery_InheritedReference_3" + timestamp;
  +        prepareForQueryTests(id_2, name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testInsertQuery()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testInsert" + timestamp;
  +        Employee em1 = new Employee(id_2, name);
  +        Executive ex1 = new Executive(id_2, name, "department_1", null);
  +        Executive ex2 = new Executive(id_2, name, "department_2", null);
  +        ArrayList list = new ArrayList();
  +        list.add(ex1);
  +        list.add(ex2);
  +        Manager m1 = new Manager(id_2, name);
  +        m1.setExecutives(list);
  +
  +        broker.beginTransaction();
  +        broker.store(em1);
  +        broker.store(m1);
  +        broker.commitTransaction();
  +
  +        Identity m1_oid = new Identity(m1, broker);
  +        Identity ex1_oid = new Identity(ex1, broker);
  +        Identity em1_oid = new Identity(em1, broker);
  +
  +        broker.clearCache();
  +
  +        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  +        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  +        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  +
  +        assertEquals(em1, newEm1);
  +        assertEquals(ex1, newEx1);
  +        assertEquals(m1, newM1);
  +        assertEquals(name, newEx1.getName());
  +        assertEquals(name, newM1.getName());
  +
  +        assertEquals(2, newM1.getExecutives().size());
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        Query queryEmployee = QueryFactory.newQuery(Employee.class, crit);
  +        Query queryExecutive = QueryFactory.newQuery(Executive.class, crit);
  +        Query queryManager = QueryFactory.newQuery(Manager.class, crit);
  +
  +        Collection result = broker.getCollectionByQuery(queryEmployee);
  +        assertEquals(4, result.size());
  +
  +        result = broker.getCollectionByQuery(queryExecutive);
  +        assertEquals(3, result.size());
  +
  +        result = broker.getCollectionByQuery(queryManager);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testDelete()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testUpdate" + timestamp;
  +        Employee em1 = new Employee(id_2, "employee_" + name);
  +        Executive ex1 = new Executive(id_2, "executive_" + name, "department_1", null);
  +        Executive ex2 = new Executive(id_2, "executive_" + name, "department_2", null);
  +        ArrayList list = new ArrayList();
  +        list.add(ex1);
  +        list.add(ex2);
  +        Manager m1 = new Manager(id_2, "manager_" + name);
  +        m1.setExecutives(list);
  +
  +        broker.beginTransaction();
  +        broker.store(em1);
  +        broker.store(m1);
  +        broker.commitTransaction();
  +
  +        Identity m1_oid = new Identity(m1, broker);
  +        Identity ex1_oid = new Identity(ex1, broker);
  +        Identity em1_oid = new Identity(em1, broker);
  +
  +        broker.clearCache();
  +
  +        Employee newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  +        Executive newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  +        Manager newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  +
  +        assertNotNull(newEm1);
  +        assertNotNull(newEx1);
  +        assertNotNull(newM1);
  +        assertEquals(2, newM1.getExecutives().size());
  +
  +        broker.beginTransaction();
  +        broker.delete(newEm1);
  +        broker.delete(newEx1);
  +        broker.delete(newM1);
  +        broker.commitTransaction();
  +
  +        newEm1 = (Employee) broker.getObjectByIdentity(em1_oid);
  +        newEx1 = (Executive) broker.getObjectByIdentity(ex1_oid);
  +        newM1 = (Manager) broker.getObjectByIdentity(m1_oid);
  +
  +        assertNull(newEm1);
  +        assertNull(newEx1);
  +        assertNull(newM1);
  +    }
  +
  +    //************************************************************
  +    // inner classes used for test
  +    //************************************************************
  +    public static class Manager extends Executive
  +    {
  +        private List executives;
  +
  +        public Manager()
  +        {
  +        }
  +
  +        public Manager(Long id_2, String name)
  +        {
  +            super(id_2, name, null, null);
  +        }
  +
  +        public List getExecutives()
  +        {
  +            return executives;
  +        }
  +
  +        public void setExecutives(List executives)
  +        {
  +            this.executives = executives;
  +        }
  +    }
  +
  +    public static class Executive extends Employee
  +    {
  +        private String department;
  +        private Manager manager;
  +
  +        public Executive()
  +        {
  +        }
  +
  +        public Executive(Long id_2, String name, String department, Manager manager)
  +        {
  +            super(id_2, name);
  +            this.department = department;
  +            this.manager = manager;
  +        }
  +
  +        public String getDepartment()
  +        {
  +            return department;
  +        }
  +
  +        public void setDepartment(String department)
  +        {
  +            this.department = department;
  +        }
  +
  +        public Manager getManager()
  +        {
  +            return manager;
  +        }
  +
  +        public void setManager(Manager manager)
  +        {
  +            this.manager = manager;
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Executive))
  +            {
  +                return false;
  +            }
  +            Executive ex = (Executive) obj;
  +            return new EqualsBuilder().append(getId(), ex.getId())
  +                    .append(getName(), ex.getName())
  +                    .append(getDepartment(), ex.getDepartment()).isEquals();
  +        }
  +    }
  +
  +    public static class Employee implements Serializable
  +    {
  +        private Integer id;
  +        private Long id_2;
  +        private String name;
  +        private AddressIF address;
  +
  +        public Employee()
  +        {
  +        }
  +
  +        public Employee(Long id_2, String name)
  +        {
  +            this.id_2 = id_2;
  +            this.name = name;
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public Long getId_2()
  +        {
  +            return id_2;
  +        }
  +
  +        public void setId_2(Long id_2)
  +        {
  +            this.id_2 = id_2;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public AddressIF getAddress()
  +        {
  +            return address;
  +        }
  +
  +        public void setAddress(AddressIF address)
  +        {
  +            this.address = address;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Employee))
  +            {
  +                return false;
  +            }
  +            Employee em = (Employee) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), em.getId())
  +                    .append(getId_2(), em.getId_2())
  +                    .append(getName(), em.getName())
  +                    .isEquals();
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Employee.class);
  +        }
  +    }
  +
  +    public static class Address implements AddressIF
  +    {
  +        private Integer id;
  +        private String street;
  +
  +        public Address()
  +        {
  +        }
  +
  +        public Address(String street)
  +        {
  +            this.street = street;
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getStreet()
  +        {
  +            return street;
  +        }
  +
  +        public void setStreet(String street)
  +        {
  +            this.street = street;
  +        }
  +    }
  +
  +    public static interface AddressIF
  +    {
  +        public Integer getId();
  +
  +        public void setId(Integer id);
  +
  +        public String getStreet();
  +
  +        public void setStreet(String street);
  +    }
  +
  +    public static class Company
  +    {
  +        private Long id;
  +        private String name;
  +        private List  employees;
  +        private List  managers;
  +
  +        public Company()
  +        {
  +        }
  +
  +        public Company(Long id, String name, List employees,List managers)
  +        {
  +            this.id = id;
  +            this.name = name;
  +            this.employees = employees;
  +            this.managers = managers;
  +        }
  +
  +        public Long getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Long id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public List getEmployees()
  +        {
  +            return employees;
  +        }
  +
  +        public void setEmployees(List employees)
  +        {
  +            this.employees = employees;
  +        }
  +
  +		public List getManagers() {
  +			return managers;
  +		}
  +
  +		public void setManagers(List managers) {
  +			this.managers = managers;
  +		}
  +    }
  +}
  
  
  

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