db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/schema ojbtest-schema.xml
Date Fri, 12 Dec 2003 21:58:17 GMT
arminw      2003/12/12 13:58:17

  Modified:    src/test/org/apache/ojb repository_junit_reference.xml
               src/test/org/apache/ojb/broker CollectionTest.java
               src/schema ojbtest-schema.xml
  Log:
  add test case posted by Andy Malakov
  show a bug in PB.queryByCollection(...)
  
  Revision  Changes    Path
  1.2       +100 -1    db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml
  
  Index: repository_junit_reference.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- repository_junit_reference.xml	9 Dec 2003 13:46:46 -0000	1.1
  +++ repository_junit_reference.xml	12 Dec 2003 21:58:16 -0000	1.2
  @@ -727,4 +727,103 @@
      </class-descriptor>
   
   
  +
  +
  +
  +    <!-- ************************************************* -->
  +    <!--      broker.CollectionTest                        -->
  +    <!-- ************************************************* -->
  +    <class-descriptor class="org.apache.ojb.broker.CollectionTest$BookShelfItem">
  +       <extent-class class-ref="org.apache.ojb.broker.CollectionTest$Book"/>
  +       <extent-class class-ref="org.apache.ojb.broker.CollectionTest$DVD"/>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +       class="org.apache.ojb.broker.CollectionTest$BookShelf"
  +       table="COL_BOOKSHELFS"
  +    >
  +       <field-descriptor
  +          name="pk"
  +          column="PK"
  +          jdbc-type="INTEGER"
  +          primarykey="true"
  +          autoincrement="true"
  +       />
  +       <field-descriptor
  +          name="name"
  +          column="NAME"
  +          jdbc-type="VARCHAR"
  +       />
  +
  +       <collection-descriptor
  +          name="items"
  +          element-class-ref="org.apache.ojb.broker.CollectionTest$BookShelfItem"
  +          auto-retrieve="true"
  +       >
  +          <inverse-foreignkey field-ref="shelfFk"/>
  +       </collection-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +       class="org.apache.ojb.broker.CollectionTest$Book"
  +       table="COL_BOOKS"
  +    >
  +       <field-descriptor
  +          name="pk"
  +          column="PK"
  +          jdbc-type="INTEGER"
  +          primarykey="true"
  +          autoincrement="true"
  +       />
  +
  +      <field-descriptor
  +          name="shelfFk"
  +          column="BOOKSHELF_FK"
  +          jdbc-type="INTEGER"
  +          access="anonymous"
  +       />
  +       <reference-descriptor
  +          name="shelf"
  +          class-ref="org.apache.ojb.broker.CollectionTest$BookShelf"
  +          auto-retrieve="true"
  +          auto-update="false"
  +          auto-delete="false"
  +          proxy="true"
  +       >
  +          <foreignkey field-ref="shelfFk"/>
  +       </reference-descriptor>
  +
  +    </class-descriptor>
  +
  +    <class-descriptor
  +       class="org.apache.ojb.broker.CollectionTest$DVD"
  +       table="COL_DVDS"
  +    >
  +       <field-descriptor
  +          name="pk"
  +          column="PK"
  +          jdbc-type="INTEGER"
  +          primarykey="true"
  +          autoincrement="true"
  +       />
  +
  +      <field-descriptor
  +          name="shelfFk"
  +          column="BOOKSHELF_FK"
  +          jdbc-type="INTEGER"
  +          access="anonymous"
  +       />
  +       <reference-descriptor
  +          name="shelf"
  +          class-ref="org.apache.ojb.broker.CollectionTest$BookShelf"
  +          auto-retrieve="true"
  +          auto-update="false"
  +          auto-delete="false"
  +          proxy="true"
  +       >
  +          <foreignkey field-ref="shelfFk"/>
  +       </reference-descriptor>
  +
  +    </class-descriptor>
  +
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.5       +196 -3    db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CollectionTest.java	9 Dec 2003 13:46:46 -0000	1.4
  +++ CollectionTest.java	12 Dec 2003 21:58:17 -0000	1.5
  @@ -12,6 +12,7 @@
   import java.util.Collection;
   import java.util.List;
   import java.util.Iterator;
  +import java.util.ArrayList;
   
   /**
    * Test case for collection handling.
  @@ -314,7 +315,7 @@
   
           assertNotNull(gatherer.getCollectiblesCCC());
           assertEquals(5, gatherer.getCollectiblesCCC().size());
  -        assertEquals(gatherer.getGatId(), ((CollectibleCCC)gatherer.getCollectiblesCCC().get(0)).getGathererId());
  +        assertEquals(gatherer.getGatId(), ((CollectibleCCC) gatherer.getCollectiblesCCC().get(0)).getGathererId());
   
           broker.clearCache();
           Identity oid = new Identity(gatherer, broker);
  @@ -488,7 +489,7 @@
           assertNotNull(new_gatherer.getCollectiblesB());
           assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
           assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
  -        Integer gatId = ((CollectibleBaseIF)new_gatherer.getCollectiblesBase().get(0)).getGathererId();
  +        Integer gatId = ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId();
           assertNotNull(gatId);
           assertEquals(new_gatherer.gatId, gatId);
           broker.clearCache();
  @@ -572,6 +573,84 @@
           assertEquals("Wrong number of queried objects", 5, result.size());
       }
   
  +    public void testOneBookShelfQueryByCollection() throws Exception
  +    {
  +        String prefix = "testOneBookShelfQueryByCollection_" + System.currentTimeMillis();
  +
  +        BookShelf bookShelf = new BookShelf(prefix);
  +        BookShelfItem ev1 = new DVD(bookShelf);
  +        bookShelf.addItem(ev1);
  +        BookShelfItem ev2 = new Book(bookShelf);
  +        bookShelf.addItem(ev2);
  +
  +        broker.beginTransaction();
  +        broker.store(bookShelf);
  +        broker.store(ev1);
  +        broker.store(ev2);
  +        broker.commitTransaction();
  +        assertTrue(bookShelf.getPK() != null);
  +
  +        broker.clearCache();
  +        BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
  +                new Identity(BookShelf.class, BookShelf.class, new Object[]{bookShelf.getPK()}));
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getItems());
  +        assertEquals(2, loadedCopy.getItems().size());
  +
  +        broker.clearCache();
  +        Criteria criteria = new Criteria();
  +        criteria.addLike("name", prefix);
  +        Query q = new QueryByCriteria(BookShelf.class, criteria);
  +        Collection books = broker.getCollectionByQuery(q);
  +        assertNotNull(books);
  +        assertEquals(1, books.size());
  +        bookShelf = (BookShelf) books.iterator().next();
  +        assertNotNull(bookShelf.getItems());
  +        assertEquals("wrong number of items found", 2, bookShelf.getItems().size());
  +    }
  +
  +    public void testOneBookShelfQueryByIterator() throws Exception
  +    {
  +        String prefix = "testOneBookShelfQueryByIterator_" + System.currentTimeMillis();
  +
  +        BookShelf bookShelf = new BookShelf(prefix);
  +        BookShelfItem ev1 = new DVD(bookShelf);
  +        bookShelf.addItem(ev1);
  +        BookShelfItem ev2 = new Book(bookShelf);
  +        bookShelf.addItem(ev2);
  +
  +        broker.beginTransaction();
  +        broker.store(bookShelf);
  +        broker.store(ev1);
  +        broker.store(ev2);
  +        broker.commitTransaction();
  +
  +        assertTrue(bookShelf.getPK() != null);
  +
  +        broker.clearCache();
  +        BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
  +                new Identity(BookShelf.class, BookShelf.class, new Object[]{bookShelf.getPK()}));
  +        assertNotNull(loadedCopy);
  +        assertNotNull(loadedCopy.getItems());
  +        assertEquals(2, loadedCopy.getItems().size());
  +
  +        broker.clearCache();
  +        Criteria criteria = new Criteria();
  +        criteria.addLike("name", prefix);
  +        Query q = new QueryByCriteria(BookShelf.class, criteria);
  +        Iterator books = broker.getIteratorByQuery(q);
  +        assertTrue(books.hasNext());
  +        loadedCopy = (BookShelf) books.next();
  +        assertNotNull(loadedCopy.getItems());
  +        assertEquals("wrong number of items found", 2, loadedCopy.getItems().size());
  +    }
  +
  +
  +
  +    //************************************************************
  +    // helper methods
  +    //************************************************************
  +
       private CollectibleBase[] prepareCollectibleBase(String namePrefix)
       {
           CollectibleBase[] colA = new CollectibleBase[]{
  @@ -999,6 +1078,120 @@
           {
               super(name);
               ojbConcreteClass = CollectibleDD.class.getName();
  +        }
  +    }
  +
  +
  +    public static class BookShelf
  +    {
  +        private Integer pk;
  +        private String name;
  +        private List items;
  +
  +        public BookShelf()
  +        {
  +        }
  +
  +        public BookShelf(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public Integer getPK()
  +        {
  +            return pk;
  +        }
  +
  +        public void addItem(BookShelfItem event)
  +        {
  +            if (items == null)
  +                items = new ArrayList();
  +
  +            items.add(event);
  +        }
  +
  +        public List getItems()
  +        {
  +            return items;
  +        }
  +
  +        public Integer getPk()
  +        {
  +            return pk;
  +        }
  +
  +        public void setPk(Integer pk)
  +        {
  +            this.pk = pk;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static abstract class BookShelfItem
  +    {
  +        private Integer pk;
  +        private BookShelf shelf;
  +
  +        public BookShelfItem()
  +        {
  +        }
  +
  +        public BookShelfItem(BookShelf shelf)
  +        {
  +            this.shelf = shelf;
  +        }
  +
  +        public Integer getPk()
  +        {
  +            return pk;
  +        }
  +
  +        public void setPk(Integer pk)
  +        {
  +            this.pk = pk;
  +        }
  +
  +        public BookShelf getShelf()
  +        {
  +            return shelf;
  +        }
  +
  +        public void setShelf(BookShelf shelf)
  +        {
  +            this.shelf = shelf;
  +        }
  +    }
  +
  +    public static class DVD extends BookShelfItem
  +    {
  +        public DVD()
  +        {
  +        }
  +
  +        public DVD(BookShelf shelf)
  +        {
  +            super(shelf);
  +        }
  +    }
  +
  +    public static class Book extends BookShelfItem
  +    {
  +        public Book()
  +        {
  +        }
  +
  +        public Book(BookShelf shelf)
  +        {
  +            super(shelf);
           }
       }
   }
  
  
  
  1.59      +20 -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.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- ojbtest-schema.xml	11 Dec 2003 20:13:23 -0000	1.58
  +++ ojbtest-schema.xml	12 Dec 2003 21:58:17 -0000	1.59
  @@ -716,8 +716,10 @@
           <column name="LENGTH_" type="DOUBLE"/>
       </table>
   
  +
  +
       <!-- =================================================== -->
  -    <!-- ODMG collection test tables                         -->
  +    <!-- ODMG/PB collection test tables                         -->
       <!-- =================================================== -->
       <!--
           private Integer gatId;
  @@ -882,6 +884,23 @@
      <table name="XCONTAINER">
        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
      </table>
  +
  +
  +    <table name="COL_BOOKSHELFS">
  +        <column name="PK" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="100"/>
  +    </table>
  +
  +    <table name="COL_BOOKS">
  +        <column name="PK" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="BOOKSHELF_FK" required="true" primaryKey="true" type="INTEGER"/>
  +    </table>
  +
  +    <table name="COL_DVDS">
  +        <column name="PK" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="BOOKSHELF_FK" required="true" primaryKey="true" type="INTEGER"/>
  +    </table>
  +
   
       <!-- =================================================== -->
       <!-- PB nested fields test                               -->
  
  
  

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