You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/04/19 18:31:15 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/junit ODMGTestCase.java

arminw      2004/04/19 09:31:15

  Modified:    src/test/org/apache/ojb repository_junit_odmg.xml
               src/test/org/apache/ojb/odmg ManyToManyTest.java
                        AllTests.java
               src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java AllTests.java
  Added:       src/test/org/apache/ojb/odmg M2NTest.java
               src/test/org/apache/ojb/broker/sequence
                        AutoIncrementTest.java
               src/test/org/apache/ojb/junit ODMGTestCase.java
  Log:
  add new tests
  update tests
  
  Revision  Changes    Path
  1.8       +150 -1    db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml
  
  Index: repository_junit_odmg.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- repository_junit_odmg.xml	5 Apr 2004 13:58:59 -0000	1.7
  +++ repository_junit_odmg.xml	19 Apr 2004 16:31:14 -0000	1.8
  @@ -1071,5 +1071,154 @@
         </collection-descriptor>
       </class-descriptor>
   
  +<!-- ==============================================
  + m:n test
  + ==================================================-->
  +
  +    <class-descriptor class="org.apache.ojb.odmg.M2NTest$Movie">
  +      <extent-class class-ref="org.apache.ojb.odmg.M2NTest$MovieImpl" />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +   	  class="org.apache.ojb.odmg.M2NTest$MovieImpl"
  +   	  table="M2N_TEST_MOVIE"
  +    >
  +        <field-descriptor
  +            name="idInt"
  +            column="OBJ_ID_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="idInt2"
  +            column="OBJ_ID2_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="idStr"
  +            column="OBJ_ID_STR"
  +            jdbc-type="VARCHAR"
  +            primarykey="true"
  +            autoincrement="false"
  +        />
  +
  +        <field-descriptor
  +            name="title"
  +            column="TITLE"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="description"
  +            column="DESCRIPTION"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <collection-descriptor
  +            name="actors"
  +            element-class-ref="org.apache.ojb.odmg.M2NTest$Actor"
  +            auto-retrieve="false"
  +            auto-update="false"
  +            auto-delete="false"
  +            indirection-table="M2N_TEST_ROLE"
  +        >
  +            <fk-pointing-to-this-class column="MOVIE_ID_INT"/>
  +            <fk-pointing-to-this-class column="MOVIE_ID2_INT"/>
  +            <fk-pointing-to-this-class column="MOVIE_ID_STR"/>
  +            <fk-pointing-to-element-class column="ACTOR_ID"/>
  +            <fk-pointing-to-element-class column="ACTOR_ID2"/>
  +        </collection-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +   	  class="org.apache.ojb.odmg.M2NTest$Actor"
  +   	  table="M2N_TEST_ACTOR"
  +    >
  +        <field-descriptor
  +            name="id"
  +            column="OBJ_ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="id2"
  +            column="OBJ_ID2"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="name"
  +            column="NAME"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <collection-descriptor
  +            name="movies"
  +            collection-class="org.apache.ojb.odmg.M2NTest$MovieManageableCollection"
  +            element-class-ref="org.apache.ojb.odmg.M2NTest$MovieImpl"
  +            auto-retrieve="false"
  +            auto-update="false"
  +            auto-delete="false"
  +            indirection-table="M2N_TEST_ROLE"
  +        >
  +            <fk-pointing-to-this-class column="ACTOR_ID"/>
  +            <fk-pointing-to-this-class column="ACTOR_ID2"/>
  +            <fk-pointing-to-element-class column="MOVIE_ID_INT"/>
  +            <fk-pointing-to-element-class column="MOVIE_ID2_INT"/>
  +            <fk-pointing-to-element-class column="MOVIE_ID_STR"/>
  +        </collection-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +   	  class="org.apache.ojb.odmg.M2NTest$Role"
  +   	  table="M2N_TEST_ROLE"
  +    >
  +        <field-descriptor
  +            name="actorId"
  +            column="ACTOR_ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +        />
  +
  +        <field-descriptor
  +            name="actorId2"
  +            column="ACTOR_ID2"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +        />
  +
  +        <field-descriptor
  +            name="movieIntId"
  +            column="MOVIE_ID_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="movieIntId2"
  +            column="MOVIE_ID2_INT"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="movieStrId"
  +            column="MOVIE_ID_STR"
  +            jdbc-type="VARCHAR"
  +            primarykey="true"
  +        />
  +    </class-descriptor>
  +
   
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.10      +5 -3      db-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java
  
  Index: ManyToManyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ManyToManyTest.java	7 Jun 2003 10:20:40 -0000	1.9
  +++ ManyToManyTest.java	19 Apr 2004 16:31:14 -0000	1.10
  @@ -88,7 +88,7 @@
           doris.addFavoriteFood(trout);
           doris.addFavoriteFood(lolloverde);
   
  -        Transaction tx = m_odmg.newTransaction();
  +        TransactionExt tx = (TransactionExt) m_odmg.newTransaction();
           tx.begin();
           m_db.makePersistent(james);
           m_db.makePersistent(doris);
  @@ -97,8 +97,10 @@
           int dorisId = doris.getGourmetId();
           int jamesId = james.getGourmetId();
   
  -        tx = m_odmg.newTransaction();
  +        tx = (TransactionExt) m_odmg.newTransaction();
           tx.begin();
  +        tx.getBroker().clearCache();
  +        
           OQLQuery query = m_odmg.newOQLQuery();
           query.create("select gourmets from " + ODMGGourmet.class.getName() +
                   " where gourmetId=$1");
  @@ -378,7 +380,7 @@
           */
           tx.lock(gourmet_doris, Transaction.WRITE);
           List foodList = gourmet_doris.getFavoriteFood();
  -        foodList.remove(0);        
  +        foodList.remove(0);
           //gourmet_doris.setFavoriteFood(foodList);
           tx.commit();
   
  
  
  
  1.17      +1 -0      db-ojb/src/test/org/apache/ojb/odmg/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/AllTests.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AllTests.java	11 Dec 2003 20:13:23 -0000	1.16
  +++ AllTests.java	19 Apr 2004 16:31:15 -0000	1.17
  @@ -51,6 +51,7 @@
           suite.addTestSuite(BatchModeTest.class);
           suite.addTestSuite(CollectionsTest.class);
   		suite.addTestSuite(PersonWithArrayTest.class);
  +		suite.addTestSuite(M2NTest.class);
           return suite;
       }
   }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  package org.apache.ojb.odmg;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.ojb.broker.ManageableCollection;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerException;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.CollectionDescriptor;
  import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  import org.apache.ojb.junit.ODMGTestCase;
  import org.odmg.OQLQuery;
  import org.odmg.QueryException;
  import org.odmg.Transaction;
  
  /**
   * Test m:n relation handling with the odmg-api. The mandatory auto-update/auto-delete
   * setting are 'false' in that case equals to 'LINK'.
   *
   * TODO: we need more tests doing delete/update operations on M:N relations
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: M2NTest.java,v 1.1 2004/04/19 16:31:15 arminw Exp $
   */
  public class M2NTest extends ODMGTestCase
  {
      static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
      static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
      static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.main(new String[] {M2NTest.class.getName()});
      }
  
      protected void tearDown() throws Exception
      {
          changeActorCollectionDescriptorTo(false, NONE, NONE, false);
          changeMovieCollectionDescriptorTo(false, NONE, NONE, false);
          super.tearDown();
      }
  
      public void testStore() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(false);
          doTestStore();
      }
  
      public void testStoreWithProxy() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(true);
          doTestStore();
      }
  
      public void doTestStore() throws Exception
      {
          String postfix = "doTestStore_" + System.currentTimeMillis();
          Movie movie = buildMovieWithActors(postfix);
  
          Transaction tx = odmg.newTransaction();
          tx.begin();
          database.makePersistent(movie);
          tx.commit();
  
          OQLQuery queryMovie = movieQuery(postfix);
          Collection resultMovie = (Collection) queryMovie.execute();
          assertEquals(1, resultMovie.size());
          Movie newMovie = (Movie) resultMovie.iterator().next();
          assertNotNull(newMovie.getActors());
          assertEquals(3, newMovie.getActors().size());
  
          OQLQuery queryActor = actorQuery(postfix);
          Collection resultActor = (Collection) queryActor.execute();
          assertEquals(3, resultActor.size());
  
          OQLQuery queryRole = roleQuery(null, movie);
          Collection resultRole = (Collection) queryRole.execute();
          assertEquals(3, resultRole.size());
      }
  
      public void testStore_2() throws Exception
      {
          prepareAutoUpdateDeleteSettings(false);
          doTestStore_2();
      }
  
      public void testStore_2WithProxy() throws Exception
      {
          prepareAutoUpdateDeleteSettings(true);
          doTestStore_2();
      }
  
      public void doTestStore_2() throws Exception
      {
          String postfix = "doTestStore_2_" + System.currentTimeMillis();
          Movie movie = buildMovieWithActors(postfix);
  
          Transaction tx = odmg.newTransaction();
          tx.begin();
          Iterator it = movie.getActors().iterator();
          while(it.hasNext())
          {
              database.makePersistent(it.next());
          }
          database.makePersistent(movie);
          tx.commit();
  
          OQLQuery queryMovie = movieQuery(postfix);
          Collection resultMovie = (Collection) queryMovie.execute();
          assertEquals(1, resultMovie.size());
          Movie newMovie = (Movie) resultMovie.iterator().next();
          assertNotNull(newMovie.getActors());
          assertEquals(3, newMovie.getActors().size());
  
          OQLQuery queryActor = actorQuery(postfix);
          Collection resultActor = (Collection) queryActor.execute();
          assertEquals(3, resultActor.size());
  
          OQLQuery queryRole = roleQuery(null, movie);
          Collection resultRole = (Collection) queryRole.execute();
          assertEquals(3, resultRole.size());
      }
  
      public void testStoreComplex() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(false);
          doTestStoreComplex();
      }
  
      public void testStoreComplexWithProxy() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(true);
          doTestStoreComplex();
      }
  
  
      public void doTestStoreComplex() throws Exception
      {
          String postfix = "doTestStoreComplex_" + System.currentTimeMillis();
          Movie movie = buildMovieWithActorsAndBackReferences(postfix);
  
          Transaction tx = odmg.newTransaction();
          tx.begin();
          database.makePersistent(movie);
          tx.commit();
  
          OQLQuery queryMovie = movieQuery(postfix);
          Collection resultMovie = (Collection) queryMovie.execute();
          assertEquals(3, resultMovie.size());
          Iterator it = resultMovie.iterator();
          boolean matchActors  = false;
          while(it.hasNext())
          {
              Movie m = (Movie) it.next();
              if(m.getActors() != null)
              {
                  boolean expectedSize = m.getActors().size() == 3;
                  if(matchActors && expectedSize)
                  {
                      fail("Expect only one movie with 3 actors, but found another one");
                  }
                  matchActors = expectedSize;
              }
          }
          assertTrue(matchActors);
  
          OQLQuery queryActor = actorQuery(postfix);
          Collection resultActor = (Collection) queryActor.execute();
          assertEquals(3, resultActor.size());
          it = resultActor.iterator();
          boolean matchMovies  = false;
          while(it.hasNext())
          {
              Actor a = (Actor) it.next();
              if(a.getMovies() != null)
              {
                  boolean expectedSize = a.getMovies().size() == 3;
                  if(matchMovies && expectedSize)
                  {
                      fail("Expect only one actor with 3 movies, but found another one");
                  }
                  matchMovies = expectedSize;
              }
          }
          assertTrue(matchMovies);
  
          OQLQuery queryRole = roleQuery(null, movie);
          Collection resultRole = (Collection) queryRole.execute();
          assertEquals(5, resultRole.size());
      }
  
      public void testStoreComplex_2() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(false);
          doTestStoreComplex_2();
      }
  
      public void testStoreComplex_2_WithProxy() throws Exception
      {
          // TODO: Seems that the order of objects is not valid to insert M:N
          if(ojbSkipKnownIssueProblem()) return;
          prepareAutoUpdateDeleteSettings(true);
          doTestStoreComplex_2();
      }
  
      public void doTestStoreComplex_2() throws Exception
      {
          String postfix = "doTestStoreComplex_2_" + System.currentTimeMillis();
          Movie movie = buildMovieWithActorsAndBackReferences(postfix);
  
          Transaction tx = odmg.newTransaction();
          tx.begin();
          Iterator it = movie.getActors().iterator();
          while(it.hasNext())
          {
              database.makePersistent(it.next());
          }
          database.makePersistent(movie);
          tx.commit();
  
          OQLQuery queryMovie = movieQuery(postfix);
          Collection resultMovie = (Collection) queryMovie.execute();
          assertEquals(3, resultMovie.size());
          it = resultMovie.iterator();
          boolean matchActors  = false;
          while(it.hasNext())
          {
              Movie m = (Movie) it.next();
              if(m.getActors() != null)
              {
                  boolean expectedSize = m.getActors().size() == 3;
                  if(matchActors && expectedSize)
                  {
                      fail("Expect only one movie with 3 actors, but found another one");
                  }
                  matchActors = expectedSize;
              }
          }
          assertTrue(matchActors);
  
          OQLQuery queryActor = actorQuery(postfix);
          Collection resultActor = (Collection) queryActor.execute();
          assertEquals(3, resultActor.size());
          it = resultActor.iterator();
          boolean matchMovies  = false;
          while(it.hasNext())
          {
              Actor a = (Actor) it.next();
              if(a.getMovies() != null)
              {
                  boolean expectedSize = a.getMovies().size() == 3;
                  if(matchMovies && expectedSize)
                  {
                      fail("Expect only one actor with 3 movies, but found another one");
                  }
                  matchMovies = expectedSize;
              }
          }
          assertTrue(matchMovies);
  
          OQLQuery queryRole = roleQuery(null, movie);
          Collection resultRole = (Collection) queryRole.execute();
          assertEquals(5, resultRole.size());
      }
  
  
      public void testStoreDelete() throws Exception
      {
          prepareAutoUpdateDeleteSettings(false);
          doTestStoreDelete();
      }
  
      public void testStoreDeleteWithProxy() throws Exception
      {
          changeMovieCollectionDescriptorTo(true, LINK, LINK, true);
          changeActorCollectionDescriptorTo(true, LINK, LINK, false);
          doTestStoreDelete();
      }
  
      public void doTestStoreDelete() throws Exception
      {
          String postfix = "doTestStoreDelete_" + System.currentTimeMillis();
          Movie movie = buildMovieWithActors(postfix);
  
          TransactionExt tx = (TransactionExt) odmg.newTransaction();
          tx.begin();
          Iterator it = movie.getActors().iterator();
          while(it.hasNext())
          {
              database.makePersistent(it.next());
          }
          database.makePersistent(movie);
          tx.commit();
  
          OQLQuery queryMovie = movieQuery(postfix);
          Collection resultMovie = (Collection) queryMovie.execute();
          assertEquals(1, resultMovie.size());
          Movie newMovie = (Movie) resultMovie.iterator().next();
          assertNotNull(newMovie.getActors());
          assertEquals(3, newMovie.getActors().size());
  
          OQLQuery queryActor = actorQuery(postfix);
          Collection resultActor = (Collection) queryActor.execute();
          assertEquals(3, resultActor.size());
  
          OQLQuery queryRole = roleQuery(null, movie);
          Collection resultRole = (Collection) queryRole.execute();
          assertEquals(3, resultRole.size());
  
          tx.begin();
          queryMovie = movieQuery(postfix);
          resultMovie = (Collection) queryMovie.execute();
          Movie m = (Movie) resultMovie.iterator().next();
          assertNotNull(m);
  
          tx.lock(m, Transaction.WRITE);
          it = m.getActors().iterator();
          database.deletePersistent(it.next());
  
          tx.commit();
  
          tx.begin();
          tx.getBroker().clearCache();
          //tx.commit();
  
          queryMovie = movieQuery(postfix);
          resultMovie = (Collection) queryMovie.execute();
          assertEquals(1, resultMovie.size());
          newMovie = (Movie) resultMovie.iterator().next();
          assertNotNull(newMovie.getActors());
          assertEquals(2, newMovie.getActors().size());
  
          queryActor = actorQuery(postfix);
          resultActor = (Collection) queryActor.execute();
          assertEquals(2, resultActor.size());
  
          queryRole = roleQuery(null, movie);
          resultRole = (Collection) queryRole.execute();
          assertEquals(2, resultRole.size());
  
          tx.commit();
      }
  
      //=======================================================================
      // helper methods
      //=======================================================================
  
      OQLQuery movieQuery(String postfix) throws QueryException
      {
          OQLQuery query = odmg.newOQLQuery();
          query.create("select obj from " + Movie.class.getName() + " where idStr like $1");
          query.bind("%" + postfix + "%");
          return query;
      }
  
      OQLQuery actorQuery(String postfix) throws QueryException
      {
          OQLQuery query = odmg.newOQLQuery();
          query.create("select obj from " + Actor.class.getName() + " where name like $1");
          query.bind("%" + postfix + "%");
          return query;
      }
  
      OQLQuery roleQuery(Actor actor, Movie movie) throws QueryException
      {
          OQLQuery query = odmg.newOQLQuery();
          String select = "select obj from " + Role.class.getName() + " where";
          boolean needsAnd = false;
          if(actor != null)
          {
              select = select + " actorId=$1 and actorId2=$2";
              needsAnd = true;
          }
          if(movie != null)
          {
              if(needsAnd) select = select + " and";
              select = select + " movieIntId=$3 and movieIntId2=$4 and movieStrId=$5";
          }
          query.create(select);
          if(actor != null)
          {
              query.bind(actor.getId());
              query.bind(actor.getId2());
  
          }
          if(movie != null)
          {
              query.bind(movie.getIdInt());
              query.bind(movie.getIdInt2());
              query.bind(movie.getIdStr());
          }
          return query;
      }
  
      /**
       * Returns 1 movie object with 3 actor objects
       */
      Movie buildMovieWithActors(String postfixId)
      {
          Movie m = new MovieImpl(postfixId,
                  "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb " + postfixId,
                  "An insane general starts a process to nuclear holocaust that a war" +
                  " room of politicians and generals frantically try to stop. " + postfixId);
          Actor a1 = new Actor("Peter Sellers " + postfixId);
          Actor a2 = new Actor("George C. Scott " + postfixId);
          Actor a3 = new Actor("Sterling Hayden " + postfixId);
          ArrayList list = new ArrayList();
          list.add(a1);
          list.add(a2);
          list.add(a3);
          m.setActors(list);
          return m;
      }
  
      /**
       * Returns 1 movie object m1 with 3 actor objects and one actor object with
       * back-reference to movie object m1 + 2 new movies
       */
      Movie buildMovieWithActorsAndBackReferences(String postfixId)
      {
          Movie m = new MovieImpl(postfixId,
                  "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb " + postfixId,
                  "An insane general starts a process to nuclear holocaust that a war" +
                  " room of politicians and generals frantically try to stop. " + postfixId);
          Actor a1 = new Actor("Peter Sellers " + postfixId);
          Actor a2 = new Actor("George C. Scott " + postfixId);
          Actor a3 = new Actor("Sterling Hayden " + postfixId);
          ArrayList list = new ArrayList();
          list.add(a1);
          list.add(a2);
          list.add(a3);
          m.setActors(list);
  
          Movie m1 = new MovieImpl(postfixId + "", "A Shot in the Dark",
                  "As murder follows murder, beautiful Maria is the obvious suspect...");
          Movie m2 = new MovieImpl(postfixId + "", "The Pink Panther",
                  " In the first movie starring Peter Sellers as the bumbling Inspector Clouseau...");
  
          MovieManageableCollection mlist1 = new MovieManageableCollection();
          mlist1.add(m);
          mlist1.add(m1);
          mlist1.add(m2);
          MovieManageableCollection mlist2 = new MovieManageableCollection();
          MovieManageableCollection mlist3 = new MovieManageableCollection();
          a1.setMovies(mlist1);
          a2.setMovies(mlist2);
          a3.setMovies(mlist3);
  
          return m;
      }
  
      Actor buildActorWithMovies(String postfixId)
      {
          Actor a = new Actor("John Cusack" + postfixId);
          MovieManageableCollection list = new MovieManageableCollection();
          list.add(new MovieImpl("a_" + postfixId, "High Fidelity", "A comedy about fear of commitment, hating your job..." + postfixId));
          list.add(new MovieImpl("b_" + postfixId, "Identity", "When a nasty storm hits a hotel, ten strangers are stranded within ..." + postfixId));
          list.add(new MovieImpl("c_" + postfixId, "Grosse Pointe Blank", "Martin Blank is a professional assassin. He is sent on a mission to a small Detroit ..." + postfixId));
          a.setMovies(list);
          return a;
      }
  
      void prepareAutoUpdateDeleteSettings(boolean useProxy)
      {
          changeMovieCollectionDescriptorTo(true, LINK, LINK, useProxy);
          changeActorCollectionDescriptorTo(true, LINK, LINK, useProxy);
      }
  
      void changeActorCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
      {
          PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
          ClassDescriptor cld = broker.getClassDescriptor(Actor.class);
          CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
          cod.setLazy(proxy);
          cod.setCascadeRetrieve(autoRetrieve);
          cod.setCascadingStore(autoUpdate);
          cod.setCascadingDelete(autoDelete);
          broker.close();
      }
  
      void changeMovieCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
      {
          PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
          ClassDescriptor cld = broker.getClassDescriptor(MovieImpl.class);
          CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
          cod.setLazy(proxy);
          cod.setCascadeRetrieve(autoRetrieve);
          cod.setCascadingStore(autoUpdate);
          cod.setCascadingDelete(autoDelete);
          broker.close();
      }
  
  
      //=======================================================================
      // Inner classes, persistence capable  test classes
      //=======================================================================
      public static class MovieManageableCollection implements ManageableCollection
      {
          private ArrayList list = new ArrayList();
  
          public void ojbAdd(Object anObject)
          {
              list.add(anObject);
          }
  
          public void ojbAddAll(ManageableCollection otherCollection)
          {
              Iterator it = otherCollection.ojbIterator();
              while(it.hasNext())
              {
                  list.add(it.next());
              }
          }
  
          public Iterator ojbIterator()
          {
              return list.iterator();
          }
  
          public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
          {
          }
  
          public Iterator iterator()
          {
              return list.iterator();
          }
  
          public int size()
          {
              return list.size();
          }
  
          public boolean isEmpty()
          {
              return list.isEmpty();
          }
  
          public void clear()
          {
              list.clear();
          }
  
          public boolean add(Movie movie)
          {
              return list.add(movie);
          }
  
          public boolean remove(Movie movie)
          {
              return list.remove(movie);
          }
  
          public boolean contains(Movie movie)
          {
              return list.contains(movie);
          }
  
          public Movie get(int index)
          {
              return (Movie) list.get(index);
          }
      }
  
      public static class Actor
      {
          private Integer id;
          private Integer id2;
          private String name;
          private MovieManageableCollection movies;
  
          public Actor()
          {
          }
  
          public Actor(String name)
          {
              this.name = name;
          }
  
          public MovieManageableCollection getMovies()
          {
              return movies;
          }
  
          public void setMovies(MovieManageableCollection movies)
          {
              this.movies = movies;
          }
  
          public Integer getId()
          {
              return id;
          }
  
          public void setId(Integer id)
          {
              this.id = id;
          }
  
          public Integer getId2()
          {
              return id2;
          }
  
          public void setId2(Integer id2)
          {
              this.id2 = id2;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
  
          public String toString()
          {
              return ToStringBuilder.reflectionToString(this).toString();
          }
      }
  
      public static interface Movie
      {
          public Collection getActors();
  
          public void setActors(Collection actors);
  
          public Integer getIdInt2();
          public Integer getIdInt();
  
          public void setIdInt2(Integer id2Int);
          public void setIdInt(Integer idInt);
  
          public String getIdStr();
  
          public void setIdStr(String idStr);
  
          public String getTitle();
  
          public void setTitle(String title);
  
          public String getDescription();
  
          public void setDescription(String description);
      }
  
      public static class MovieImpl implements Movie
      {
          private Integer idInt;
          private Integer idInt2;
          private String idStr;
          private String title;
          private String description;
          private Collection actors;
  
          public MovieImpl()
          {
          }
  
          public MovieImpl(String idStr, String title, String description)
          {
              this.idStr = idStr;
              this.title = title;
              this.description = description;
          }
  
          public Collection getActors()
          {
              return actors;
          }
  
          public void setActors(Collection actors)
          {
              this.actors = actors;
          }
  
          public Integer getIdInt()
          {
              return idInt;
          }
  
          public void setIdInt(Integer idInt)
          {
              this.idInt = idInt;
          }
  
          public Integer getIdInt2()
          {
              return idInt2;
          }
  
          public void setIdInt2(Integer idInt2)
          {
              this.idInt2 = idInt2;
          }
  
          public String getIdStr()
          {
              return idStr;
          }
  
          public void setIdStr(String idStr)
          {
              this.idStr = idStr;
          }
  
          public String getTitle()
          {
              return title;
          }
  
          public void setTitle(String title)
          {
              this.title = title;
          }
  
          public String getDescription()
          {
              return description;
          }
  
          public void setDescription(String description)
          {
              this.description = description;
          }
  
          public String toString()
          {
              return ToStringBuilder.reflectionToString(this).toString();
          }
      }
  
      public static class Role
      {
          private Integer actorId;
          private Integer actorId2;
          private Integer movieIntId;
          private Integer movieIntId2;
          private String movieStrId;
  
          public Role()
          {
          }
  
          public Integer getActorId()
          {
              return actorId;
          }
  
          public void setActorId(Integer actorId)
          {
              this.actorId = actorId;
          }
  
          public Integer getMovieIntId()
          {
              return movieIntId;
          }
  
          public Integer getMovieIntId2()
          {
              return movieIntId2;
          }
  
          public void setMovieIntId2(Integer movieIntId2)
          {
              this.movieIntId2 = movieIntId2;
          }
  
          public Integer getActorId2()
          {
              return actorId2;
          }
  
          public void setActorId2(Integer actorId2)
          {
              this.actorId2 = actorId2;
          }
  
          public void setMovieIntId(Integer movieIntId)
          {
              this.movieIntId = movieIntId;
          }
  
          public String getMovieStrId()
          {
              return movieStrId;
          }
  
          public void setMovieStrId(String movieStrId)
          {
              this.movieStrId = movieStrId;
          }
  
          public String toString()
          {
              return ToStringBuilder.reflectionToString(this).toString();
          }
      }
  }
  
  
  
  1.4       +18 -10    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InheritanceMultipleTableTest.java	6 Apr 2004 15:29:21 -0000	1.3
  +++ InheritanceMultipleTableTest.java	19 Apr 2004 16:31:15 -0000	1.4
  @@ -168,12 +168,12 @@
           assertEquals(1, result.size());
       }
   
  -    public void testQuery_InheritedReference()
  +    public void testQuery_InheritedReference_1()
       {
           // TODO: skip this test, we have to fix this after 1.0
           if(ojbSkipKnownIssueProblem()) return;
   
  -        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        String name = "testQuery_InheritedReference_1" + System.currentTimeMillis();
           prepareForQueryTests(name);
           broker.clearCache();
   
  @@ -190,12 +190,12 @@
           assertEquals("snob allee", retManager.getAddress().getStreet());
       }
   
  -    public void testQuery_InheritedReference_1()
  +    public void testQuery_InheritedReference_2()
       {
           // TODO: skip this test, we have to fix this after 1.0
           if(ojbSkipKnownIssueProblem()) return;
   
  -        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        String name = "testQuery_InheritedReference_2" + System.currentTimeMillis();
           prepareForQueryTests(name);
           broker.clearCache();
   
  @@ -209,7 +209,7 @@
   
       public void testQuery_InheritedReference_3()
       {
  -        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        String name = "testQuery_InheritedReference_3" + System.currentTimeMillis();
           prepareForQueryTests(name);
           broker.clearCache();
   
  @@ -451,7 +451,7 @@
       {
           private Integer id;
           private String name;
  -        private Address address;
  +        private AddressIF address;
   
           public Employee()
           {
  @@ -472,12 +472,12 @@
               this.id = id;
           }
   
  -        public Address getAddress()
  +        public AddressIF getAddress()
           {
               return address;
           }
   
  -        public void setAddress(Address address)
  +        public void setAddress(AddressIF address)
           {
               this.address = address;
           }
  @@ -508,7 +508,7 @@
           }
       }
   
  -    public static class Address
  +    public static class Address implements AddressIF
       {
           private Integer id;
           private String street;
  @@ -541,5 +541,13 @@
           {
               this.street = street;
           }
  +    }
  +
  +    public static interface AddressIF
  +    {
  +        public Integer getId();
  +        public void setId(Integer id);
  +        public String getStreet();
  +        public void setStreet(String street);
       }
   }
  
  
  
  1.44      +2 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- AllTests.java	6 Apr 2004 15:29:21 -0000	1.43
  +++ AllTests.java	19 Apr 2004 16:31:15 -0000	1.44
  @@ -12,6 +12,7 @@
   import org.apache.ojb.broker.sequence.SequenceManagerTest;
   import org.apache.ojb.broker.sequence.NativeIdentifierTest;
   import org.apache.ojb.broker.sequence.SMMultiThreadedTest;
  +import org.apache.ojb.broker.sequence.AutoIncrementTest;
   
   /**
    * the facade to all TestCases in this package.
  @@ -89,6 +90,7 @@
           suite.addTestSuite(M2NTest.class);
           suite.addTestSuite(CollectionTest2.class);
           suite.addTestSuite(NumberAccuracyTest.class);
  +        suite.addTestSuite(AutoIncrementTest.class);
           return suite;
       }
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/sequence/AutoIncrementTest.java
  
  Index: AutoIncrementTest.java
  ===================================================================
  package org.apache.ojb.broker.sequence;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.junit.PBTestCase;
  import org.apache.commons.lang.builder.ToStringBuilder;
  
  /**
   * Test autoincrement behaviour of PK and non PK fields.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: AutoIncrementTest.java,v 1.1 2004/04/19 16:31:15 arminw Exp $
   */
  public class AutoIncrementTest extends PBTestCase
  {
     public static void main(String[] args)
      {
          String[] arr = {AutoIncrementTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void testAutoIncrement()
      {
          IncrementObject obj_1 = new IncrementObject();
          IncrementObject obj_2 = new IncrementObject();
          broker.beginTransaction();
          broker.store(obj_1);
          broker.store(obj_2);
          broker.commitTransaction();
          // we assume different autogenerated values > 0
          assertTrue(obj_1.getIntId() < obj_2.getIntId());
          assertTrue(obj_1.getIntegerId().intValue() < obj_2.getIntegerId().intValue());
          assertTrue(!obj_1.getStr().equals(obj_2.getStr()));
          assertTrue(obj_2.getIntId() > 0);
          assertTrue(obj_2.getIntegerId().intValue() > 0);
          assertTrue((new Integer(obj_2.getStr())).intValue() > 0);
  
          Identity oid = new Identity(obj_2, broker);
          IncrementObject newObj_2 = (IncrementObject) broker.getObjectByIdentity(oid);
          broker.beginTransaction();
          broker.store(obj_1);
          broker.store(obj_2);
          broker.commitTransaction();
          assertEquals(obj_2.getIntId(), newObj_2.getIntId());
          assertEquals(obj_2.getIntegerId(), newObj_2.getIntegerId());
          assertEquals(obj_2.getStr(), newObj_2.getStr());
      }
  
      private void changePrimaryKeyStatus(boolean integerIdField, boolean intIdField, boolean strIdField)
      {
          ClassDescriptor cld = broker.getClassDescriptor(IncrementObject.class);
          cld.getFieldDescriptorByName("integerId").setPrimaryKey(integerIdField);
          cld.getFieldDescriptorByName("intId").setPrimaryKey(intIdField);
          cld.getFieldDescriptorByName("str").setPrimaryKey(strIdField);
      }
  
      public static class IncrementObject
      {
          int intId;
          Integer integerId;
          String str;
  
          public IncrementObject()
          {
          }
  
          public Integer getIntegerId()
          {
              return integerId;
          }
  
          public void setIntegerId(Integer integerId)
          {
              this.integerId = integerId;
          }
  
          public int getIntId()
          {
              return intId;
          }
  
          public void setIntId(int intId)
          {
              this.intId = intId;
          }
  
          public String getStr()
          {
              return str;
          }
  
          public void setStr(String str)
          {
              this.str = str;
          }
  
          public String toString()
          {
              return ToStringBuilder.reflectionToString(this);
          }
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/junit/ODMGTestCase.java
  
  Index: ODMGTestCase.java
  ===================================================================
  package org.apache.ojb.junit;
  
  import org.odmg.Implementation;
  import org.odmg.Database;
  import org.odmg.Transaction;
  import org.apache.ojb.odmg.OJB;
  import org.apache.ojb.broker.TestHelper;
  
  /**
   *
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: ODMGTestCase.java,v 1.1 2004/04/19 16:31:15 arminw Exp $
   */
  public class ODMGTestCase extends OJBTestCase
  {
      public Implementation odmg;
      public Database database;
  
      public ODMGTestCase()
      {
      }
  
      public ODMGTestCase(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          odmg = OJB.getInstance();
          database = odmg.newDatabase();
          database.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
      }
  
      protected void tearDown() throws Exception
      {
          super.tearDown();
          try
          {
              Transaction currentTx = odmg.currentTransaction();
              if(currentTx != null && currentTx.isOpen())
              {
                  currentTx.abort();
              }
          }
          catch(Exception e)
          {
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org