db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm OtmExamples.java
Date Mon, 16 Jun 2003 22:48:50 GMT
olegnitz    2003/06/16 15:48:50

  Modified:    src/test/org/apache/ojb/otm OtmExamples.java
  Log:
  Added tests for getIteratorByQuery() and invalidate() in OTMConnection
  
  Revision  Changes    Path
  1.11      +50 -3     db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java
  
  Index: OtmExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- OtmExamples.java	12 Jun 2003 23:42:34 -0000	1.10
  +++ OtmExamples.java	16 Jun 2003 22:48:50 -0000	1.11
  @@ -2,10 +2,15 @@
   
   import junit.framework.TestCase;
   
  +import java.util.Iterator;
   import org.apache.ojb.broker.Article;
  +import org.apache.ojb.broker.InterfaceArticle;
   import org.apache.ojb.broker.ProductGroup;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +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.otm.core.BaseConnection;
   import org.apache.ojb.otm.core.Transaction;
   import org.apache.ojb.otm.lock.LockType;
  @@ -43,6 +48,9 @@
       public void testOtmSession() throws Throwable
       {
           Transaction tx = null;
  +        Criteria crit;
  +        Query q;
  +        Iterator it;
   
           //perform transaction
           try
  @@ -54,6 +62,7 @@
               example.setArticleId(77777);
               example.setProductGroupId(7);
               example.setStock(333);
  +            example.setArticleName("333");
               _conn.makePersistent(example);
   
               tx.commit();
  @@ -66,15 +75,51 @@
               example = (Article) _conn.getObjectByIdentity(oid);
               assertEquals("should be equal", 7, example.getProductGroupId());
               assertEquals("should be equal", 333, example.getStock());
  +            assertEquals("should be equal", "333", example.getArticleName());
               tx.commit();
   
               // get from the database
               tx = _kit.getTransaction(_conn);
  -            ((BaseConnection) _conn).getKernelBroker().clearCache();
               tx.begin();
  +            _conn.invalidate(oid);
               example = (Article) _conn.getObjectByIdentity(oid);
               assertEquals("should be equal", 7, example.getProductGroupId());
  -            assertEquals("should be equal", 333, example.getStock());
  +            assertEquals("should be equal", "333", example.getArticleName());
  +            example.setArticleName("334"); // test update
  +            tx.commit();
  +
  +            // get from the database via Query
  +            tx = _kit.getTransaction(_conn);
  +            _conn.invalidate(oid);
  +            tx.begin();
  +            crit = new Criteria();
  +            crit.addEqualTo("articleId", new Integer(77777));
  +            crit.addEqualTo("articleName", "334");
  +            q = QueryFactory.newQuery(Article.class, crit);
  +            it = _conn.getIteratorByQuery(q);
  +            if (it.hasNext())
  +            {
  +                InterfaceArticle article = (InterfaceArticle) it.next();
  +                assertEquals("should be equal", 77777, article.getArticleId());
  +                assertEquals("should be equal", "334", article.getArticleName());
  +                article.setArticleName("335"); // test update
  +                if (it.hasNext())
  +                {
  +                    fail("Query returned more than 1 object");
  +                }
  +            }
  +            else
  +            {
  +                fail("Query returned empty result set");
  +            }
  +            tx.commit();
  +
  +            // get from the database
  +            tx = _kit.getTransaction(_conn);
  +            tx.begin();
  +            _conn.invalidate(oid);
  +            example = (Article) _conn.getObjectByIdentity(oid);
  +            assertEquals("should be equal", "335", example.getArticleName());
               tx.commit();
   
               try
  @@ -445,8 +490,10 @@
               tx.commit();
   
               tx = _kit.getTransaction(_conn);
  -            ((BaseConnection) _conn).getKernelBroker().clearCache();
               tx.begin();
  +            _conn.invalidate(aOid);
  +            _conn.invalidate(aOid2);
  +            _conn.invalidate(pgOid);
               article = (Article) _conn.getObjectByIdentity(aOid);
               article2 = (Article) _conn.getObjectByIdentity(aOid2);
               assertEquals("should be equal", "2", article.getProductGroup().getName());
  
  
  

Mime
View raw message