db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r524318 - in /db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount: AbstractCountTest.java CollectionCountTest.java EmptyCacheCountTest.java SimpleCountTest.java TwoLevelSimpleTest.java
Date Fri, 30 Mar 2007 23:11:08 GMT
Author: arminw
Date: Fri Mar 30 16:11:07 2007
New Revision: 524318

URL: http://svn.apache.org/viewvc?view=rev&rev=524318
Log:
update, adapt tests

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
    db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
    db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java
    db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java
    db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java?view=diff&rev=524318&r1=524317&r2=524318
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java Fri Mar 30
16:11:07 2007
@@ -9,6 +9,7 @@
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.junit.OJBTestCase;
+import org.apache.ojb.junit.PBTestCase;
 import org.apache.ojb.p6spy.CountLogger;
 
 /**
@@ -17,7 +18,7 @@
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
  * @version $Id$
  */
-public abstract class AbstractCountTest extends OJBTestCase
+public abstract class AbstractCountTest extends PBTestCase
 {
     private int stmtCount;
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -26,10 +27,10 @@
     /**
      * sets the spy.properties file name.
      */
-    protected void setUp() throws Exception
+    public void setUp() throws Exception
     {
         super.setUp();
-        if (!SPY_PROPS_FILE.exists())
+        if(!SPY_PROPS_FILE.exists())
             fail("Missing file: " + SPY_PROPS_FILE.getAbsolutePath());
         P6SpyProperties.setSpyProperties(SPY_PROPS_FILE.getName());
         checkP6spyEnabled(ojb.getDefaultConfiguration());
@@ -52,11 +53,11 @@
     protected final void assertStmtCount(String msg, int minExpected, int maxExpected)
     {
         int stmtNum = CountLogger.getSQLStatementCount() - stmtCount;
-        if (stmtNum > maxExpected)
+        if(stmtNum > maxExpected)
             fail(msg + ": more SQL statements than expected. Expected: " + maxExpected +
", was: " + stmtNum);
-        else if (minExpected > 0 && stmtNum == 0)
+        else if(minExpected > 0 && stmtNum == 0)
             fail("No SQL statements, maybe CountLogger not enabled?");
-        else if (stmtNum < minExpected)
+        else if(stmtNum < minExpected)
             fail(msg + ": less SQL statements than expected (Performance improvement? Please
correct test limit)."
                     + " Expected: " + minExpected + ", was: " + stmtNum);
         else
@@ -93,7 +94,7 @@
     {
         JdbcConnectionDescriptor conDesc = persistenceConf.getJdbcConnectionDescriptor();
 
-        if (!P6SpyDriver.class.getName().equals(conDesc.getDriver()))
+        if(!P6SpyDriver.class.getName().equals(conDesc.getDriver()))
         {
             fail("this test works only with p6spy.\n" +
                     "Please set 'driver=" + P6SpyDriver.class.getName() + "' in file repository_database.xml"
+

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java?view=diff&rev=524318&r1=524317&r2=524318
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java Fri Mar
30 16:11:07 2007
@@ -12,10 +12,8 @@
 import java.util.List;
 
 import org.apache.ojb.broker.Article;
-import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.InterfaceArticle;
 import org.apache.ojb.broker.InterfaceProductGroup;
-import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.Person;
 import org.apache.ojb.broker.ProductGroup;
 import org.apache.ojb.broker.Project;
@@ -32,259 +30,265 @@
  */
 public class CollectionCountTest extends AbstractCountTest
 {
-  protected PersistenceBroker myPB;
+    public void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    /**
+     * retrieve all product groups.
+     */
+    public void testAllProductGroups()
+    {
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        Query qry = QueryFactory.newQuery(ProductGroup.class, new Criteria());
+        assertStmtCount("preparation", 0);
+        Iterator iter = broker.getIteratorByQuery(qry);
+        assertStmtCount("getIteratorByQuery", 1);
+        while(iter.hasNext())
+        {
+            resetStmtCount();
+            InterfaceProductGroup next = (InterfaceProductGroup) iter.next();
+            assertStmtCount("next", 0);
+            List articles = next.getAllArticles();
+            // SELECT ... FROM Kategorien
+            // SELECT ... FROM Artikel
+            // SELECT ... FROM BOOKS
+            // SELECT ... FROM CDS
+            assertStmtCount("getAllArticles", 4);
+        }
+        broker.commitTransaction();
+    }
 
-  protected void setUp() throws Exception
-  {
-    super.setUp();
-    myPB = ojb.lookupBroker();
-  }
-
-  protected void tearDown() throws Exception
-  {
-    if ((myPB != null) && !myPB.isClosed())
+    /**
+     * retrieve Product group number 5 and its 12 articles
+     */
+    public void testProductGroup5()
     {
-      myPB.close();
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        ProductGroup pg = (ProductGroup) broker.getObjectByIdentity(
+                broker.serviceIdentity().buildIdentity(null, ProductGroup.class, new Object[]{new
Integer(5)}));
+        assertStmtCount("getObjectByIdentity", 4);
+        resetStmtCount();
+        List articles = pg.getAllArticles();
+        assertEquals(12, articles.size());
+        assertStmtCount("getAllArticles", 0);
+        resetStmtCount();
+        for(Iterator articleIterator = articles.iterator(); articleIterator.hasNext();)
+        {
+            InterfaceArticle article = (InterfaceArticle) articleIterator.next();
+            logger.info("articleId " + article.getArticleId());
+            // SELECT ... FROM Artikel WHERE Artikel_Nr = ...
+        }
+        assertStmtCount("collect ids: ", 1);  // batch retrieval!
+        resetStmtCount();
+        String str = pg.toString();
+        // SELECT ... FROM Kategorien WHERE Kategorie_Nr = '5'
+        // SELECT ... FROM Artikel A0 WHERE Kategorie_Nr =  '5'
+        // SELECT ... FROM BOOKS A0   WHERE Kategorie_Nr =  '5'
+        // SELECT ... FROM CDS A0     WHERE Kategorie_Nr =  '5'
+        assertStmtCount("toString", 4);
+        logger.info(str);
+        broker.commitTransaction();
     }
-    super.tearDown();
-  }
 
-  /**
-   * retrieve all product groups.
-   */
-  public void testAllProductGroups()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    myPB.beginTransaction();
-    Query qry = QueryFactory.newQuery(ProductGroup.class, (Criteria) null);
-    assertStmtCount("preparation", 0);
-    Iterator iter = myPB.getIteratorByQuery(qry);
-    assertStmtCount("getIteratorByQuery", 1);
-    while (iter.hasNext())
+    /*
+    * insert a person with an empty project collection.
+    * note: the <em>first</em> Person and Project require extra lookups
+    * in the table OJB_HL_SEQ.
+    */
+    public void testPersonEmptyProjectsInsert()
     {
-      resetStmtCount();
-      InterfaceProductGroup next = (InterfaceProductGroup) iter.next();
-      assertStmtCount("next", 0);
-      List articles = next.getAllArticles();
-      // SELECT ... FROM Kategorien
-      // SELECT ... FROM Artikel
-      // SELECT ... FROM BOOKS
-      // SELECT ... FROM CDS
-      assertStmtCount("getAllArticles", 4);
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        Person pers = new Person();
+        broker.store(pers);
+        //SELECT A0.VERSION,A0.GRAB_SIZE,A0.MAX_KEY,A0.FIELDNAME,A0.TABLENAME FROM OJB_HL_SEQ
A0 WHERE (A0.TABLENAME LIKE  'SEQ_PERSON' ) AND A0.FIELDNAME LIKE  'ID'
+        //SELECT VERSION,GRAB_SIZE,MAX_KEY,FIELDNAME,TABLENAME FROM OJB_HL_SEQ WHERE TABLENAME
= 'SEQ_PERSON'  AND FIELDNAME = 'ID'
+        //UPDATE OJB_HL_SEQ SET MAX_KEY='150',GRAB_SIZE='20',VERSION='7' WHERE TABLENAME
= 'SEQ_PERSON'  AND FIELDNAME = 'ID'  AND VERSION = '6'
+        // commit|
+        //SELECT LASTNAME,FIRSTNAME,ID FROM PERSON WHERE ID = '131'
+        //INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('131','','')
+        logStmtCount("Storing first person");  // 6. oma: why so many? double lookup in OJB_HL_SEQ
!
+        resetStmtCount();
+        pers = new Person();
+        broker.store(pers, ObjectModification.INSERT);
+        broker.commitTransaction();
+        // INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('172','','')
+        // commit
+        assertStmtCount("insert second Person with empty collection.", 2);
     }
-    myPB.commitTransaction();
-  }
 
-  /**
-   * retrieve Product group number 5 and its 12 articles
-   */
-  public void testProductGroup5()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    myPB.beginTransaction();
-    ProductGroup pg =
-            (ProductGroup)myPB.getObjectByIdentity(myPB.serviceIdentity().buildIdentity(null,
ProductGroup.class, new Object[] {new Integer(5)}));
-    assertStmtCount("getObjectByIdentity", 4);
-    resetStmtCount();
-    List articles = pg.getAllArticles();
-    assertEquals(12, articles.size());
-    assertStmtCount("getAllArticles", 0);
-    resetStmtCount();
-    for (Iterator articleIterator = articles.iterator(); articleIterator.hasNext(); )
+    /**
+     * insert a person with a project collection with one fresh element.
+     * note: the <em>first</em> Person and Project require extra lookups
+     * in the table OJB_HL_SEQ.
+     */
+    public void testPersonSingleProjectInsert()
     {
-      InterfaceArticle article = (InterfaceArticle)articleIterator.next();
-      logger.info("articleId " + article.getArticleId());
-      // SELECT ... FROM Artikel WHERE Artikel_Nr = ...
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        Person pers = new Person();
+        pers.setFirstname("testPersonSingleProjectInsert(1)");
+        Project proj = new Project();
+        proj.setTitle("testPersonSingleProjectInsert(1)");
+        broker.store(pers);
+        broker.store(proj);
+        logStmtCount("Storing first person and first project");
+        // 12. oma: why so many? double lookup in OJB_HL_SEQ !
+        resetStmtCount();
+        pers = new Person();
+        Project proj2 = new Project();
+        proj2.setTitle("proj2");
+        Collection projects = Arrays.asList(new Project[]{proj2});
+        pers.setProjects(projects);
+        broker.store(pers, ObjectModification.INSERT);
+        broker.commitTransaction();
+        /*
+        new:
+        INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('200001','testPersonSingleProjectInsert(1)','')
+        INSERT INTO PROJECT (ID,TITLE,DESCRIPTION) VALUES ('200001','testPersonSingleProjectInsert(1)','')
+        INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('200002','','')
+        INSERT INTO PROJECT (ID,TITLE,DESCRIPTION) VALUES ('200002','proj2','')
+        INSERT INTO PERSON_PROJECT (PERSON_ID,PROJECT_ID) VALUES ('200002','200002')
+        */
+        // old:
+        // INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('292','','')
+        // SELECT TITLE,DESCRIPTION,ID FROM PROJECT WHERE ID = '88'
+        // INSERT INTO PROJECT (ID,TITLE,DESCRIPTION) VALUES ('88','proj2','')
+        // SELECT PROJECT_ID FROM PERSON_PROJECT WHERE PERSON_ID='292'      // BRJ: check
mn-implementor
+        // INSERT INTO PERSON_PROJECT (PERSON_ID,PROJECT_ID) VALUES ('292','88')
+        // commit|
+        assertStmtCount("insert second Person, singleton collection.", 4);
     }
-    assertStmtCount("collect ids: ", 1);  // batch retrieval!
-    resetStmtCount();
-    String str = pg.toString();
-    // SELECT ... FROM Kategorien WHERE Kategorie_Nr = '5'
-    // SELECT ... FROM Artikel A0 WHERE Kategorie_Nr =  '5'
-    // SELECT ... FROM BOOKS A0   WHERE Kategorie_Nr =  '5'
-    // SELECT ... FROM CDS A0     WHERE Kategorie_Nr =  '5'
-    assertStmtCount("toString", 4);
-    logger.info(str);
-    myPB.commitTransaction();
-  }
-
-  /*
-  * insert a person with an empty project collection.
-  * note: the <em>first</em> Person and Project require extra lookups
-  * in the table OJB_HL_SEQ.
-  */
-  public void testPersonEmptyProjectsInsert()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    myPB.beginTransaction();
-    Person pers = new Person();
-    myPB.store(pers);
-    //SELECT A0.VERSION,A0.GRAB_SIZE,A0.MAX_KEY,A0.FIELDNAME,A0.TABLENAME FROM OJB_HL_SEQ
A0 WHERE (A0.TABLENAME LIKE  'SEQ_PERSON' ) AND A0.FIELDNAME LIKE  'ID'
-    //SELECT VERSION,GRAB_SIZE,MAX_KEY,FIELDNAME,TABLENAME FROM OJB_HL_SEQ WHERE TABLENAME
= 'SEQ_PERSON'  AND FIELDNAME = 'ID'
-    //UPDATE OJB_HL_SEQ SET MAX_KEY='150',GRAB_SIZE='20',VERSION='7' WHERE TABLENAME = 'SEQ_PERSON'
 AND FIELDNAME = 'ID'  AND VERSION = '6'
-    // commit|
-    //SELECT LASTNAME,FIRSTNAME,ID FROM PERSON WHERE ID = '131'
-    //INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('131','','')
-    logStmtCount("Storing first person");  // 6. oma: why so many? double lookup in OJB_HL_SEQ
!
-    resetStmtCount();
-    pers = new Person();
-    myPB.store(pers, ObjectModification.INSERT);
-    myPB.commitTransaction();
-    // INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('172','','')
-    // commit
-    assertStmtCount("insert second Person with empty collection.", 2);
-  }
-
-  /**
-   * insert a person with a project collection with one fresh element.
-   * note: the <em>first</em> Person and Project require extra lookups
-   * in the table OJB_HL_SEQ.
-   */
-  public void testPersonSingleProjectInsert()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    myPB.beginTransaction();
-    Person pers = new Person();
-    pers.setFirstname("testPersonSingleProjectInsert(1)");
-    Project proj = new Project();
-    proj.setTitle("testPersonSingleProjectInsert(1)");
-    myPB.store(pers);
-    myPB.store(proj);
-    logStmtCount("Storing first person and first project");
-    // 12. oma: why so many? double lookup in OJB_HL_SEQ !
-    resetStmtCount();
-    pers = new Person();
-    Project proj2 = new Project();
-    proj2.setTitle("proj2");
-    Collection projects = Arrays.asList(new Project[] {proj2});
-    pers.setProjects(projects);
-    myPB.store(pers, ObjectModification.INSERT);
-    myPB.commitTransaction();
-    // INSERT INTO PERSON (ID,FIRSTNAME,LASTNAME) VALUES ('292','','')
-    // SELECT TITLE,DESCRIPTION,ID FROM PROJECT WHERE ID = '88'
-    // INSERT INTO PROJECT (ID,TITLE,DESCRIPTION) VALUES ('88','proj2','')
-    // SELECT PROJECT_ID FROM PERSON_PROJECT WHERE PERSON_ID='292'      // BRJ: check mn-implementor
-    // INSERT INTO PERSON_PROJECT (PERSON_ID,PROJECT_ID) VALUES ('292','88')
-    // commit|
-    assertStmtCount("insert second Person, singleton collection.", 6);
-  }
-  
-  
-  public void testPrefetched()
-  {  
-      ClassDescriptor cldProductGroup = myPB.getClassDescriptor(ProductGroup.class);
-      ClassDescriptor cldArticle = myPB.getClassDescriptor(Article.class);
-      Class productGroupProxy = cldProductGroup.getProxyClass();
-      Class articleProxy = cldArticle.getProxyClass();
-
-      //
-      // use ProductGroup and Articles with disabled Proxy
-      //
-      cldProductGroup.setProxyClass(null);
-      cldProductGroup.setProxyClassName(null);
-      cldArticle.setProxyClass(null);
-      cldArticle.setProxyClassName(null);
-      
-      resetStmtCount();
-      myPB.clearCache();
-      
-     
-      myPB.beginTransaction();
-      
-      Criteria crit = new Criteria();
-      crit.addLessOrEqualThan("groupId", new Integer(5));
-      QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
-      q.addOrderByDescending("groupId");
-      q.addPrefetchedRelationship("allArticlesInGroup");
-      
-      Collection results = myPB.getCollectionByQuery(q);
-      assertEquals("Number of ProductGroups", 5, results.size());
-      Collection articles = new ArrayList();
-      for (Iterator it = results.iterator();it.hasNext();)
-      {
-          ProductGroup p = (ProductGroup) it.next();
-          articles.addAll(p.getAllArticles());
-      }
-      assertEquals("Total number of Articles", 59, articles.size());
-      
-      //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0 WHERE
A0.Kategorie_Nr <=  '5' 
-      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3' ) 
-      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3'
) 
-      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3' )

-      assertStmtCount("Read Prefetched.", 4);
-      myPB.commitTransaction();
-      
-      //
-      // Reset original Proxy settings
-      //
-      cldProductGroup.setProxyClass(productGroupProxy);
-      cldProductGroup.setProxyClassName(productGroupProxy.getName());
-      cldArticle.setProxyClass(articleProxy);
-      cldArticle.setProxyClassName(articleProxy.getName());
-      
-  }
-  
-  public void testNonPrefetched()
-  {
-      ClassDescriptor cldProductGroup = myPB.getClassDescriptor(ProductGroup.class);
-      ClassDescriptor cldArticle = myPB.getClassDescriptor(Article.class);
-      Class productGroupProxy = cldProductGroup.getProxyClass();
-      Class articleProxy = cldArticle.getProxyClass();
-
-      //
-      // use ProductGroup and Articles with disabled Proxy
-      //
-      cldProductGroup.setProxyClass(null);
-      cldProductGroup.setProxyClassName(null);
-      cldArticle.setProxyClass(null);
-      cldArticle.setProxyClassName(null);
-      
-      resetStmtCount();
-      myPB.clearCache();
-
-      myPB.beginTransaction();
-      
-      Criteria crit = new Criteria();
-      crit.addLessOrEqualThan("groupId", new Integer(5));
-      QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
-      q.addOrderByDescending("groupId");
-      
-      Collection results = myPB.getCollectionByQuery(q);
-      assertEquals("Number of ProductGroups", 5, results.size());
-      Collection articles = new ArrayList();
-      for (Iterator it = results.iterator();it.hasNext();)
-      {
-          ProductGroup p = (ProductGroup) it.next();
-          articles.addAll(p.getAllArticles());
-      }
-      assertEquals("Total number of Articles", 59, articles.size());
-      
-      //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0 WHERE
A0.Kategorie_Nr <=  '5' 
-      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '5' 
-      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '5'  
-      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '5'  
-      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '4' 
-      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '4'  
-      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '4'
-      //...
-      //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '1' 
-      //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '1'  
-      //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '1'  
-      assertStmtCount("Read Non-Prefetched.", 16);
-      myPB.commitTransaction();
-      
-      //
-      // Reset original Proxy settings
-      //
-      cldProductGroup.setProxyClass(productGroupProxy);
-      cldProductGroup.setProxyClassName(productGroupProxy.getName());
-      cldArticle.setProxyClass(articleProxy);
-      cldArticle.setProxyClassName(articleProxy.getName());
-      
-  }  
-  
+
+
+    public void testPrefetched()
+    {
+        ClassDescriptor cldProductGroup = broker.getClassDescriptor(ProductGroup.class);
+        ClassDescriptor cldArticle = broker.getClassDescriptor(Article.class);
+        Class productGroupProxy = cldProductGroup.getProxyClass();
+        Class articleProxy = cldArticle.getProxyClass();
+
+        //
+        // use ProductGroup and Articles with disabled Proxy
+        //
+        cldProductGroup.setProxyClass(null);
+        cldProductGroup.setProxyClassName(null);
+        cldArticle.setProxyClass(null);
+        cldArticle.setProxyClassName(null);
+
+        try
+        {
+            resetStmtCount();
+            broker.clearCache();
+
+
+            broker.beginTransaction();
+
+            Criteria crit = new Criteria();
+            crit.addLessOrEqualThan("groupId", new Integer(5));
+            QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
+            q.addOrderByDescending("groupId");
+            q.addPrefetchedRelationship("allArticlesInGroup");
+
+            Collection results = broker.getCollectionByQuery(q);
+            assertEquals("Number of ProductGroups", 5, results.size());
+            Collection articles = new ArrayList();
+            for(Iterator it = results.iterator(); it.hasNext();)
+            {
+                ProductGroup p = (ProductGroup) it.next();
+                articles.addAll(p.getAllArticles());
+            }
+            assertEquals("Total number of Articles", 59, articles.size());
+
+            //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0
WHERE A0.Kategorie_Nr <=  '5'
+            //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' , '3'
)
+            //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5'
, '3' )
+            //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr IN ( '1' , '4' , '2' , '5' ,
'3' )
+            assertStmtCount("Read Prefetched.", 4);
+            broker.commitTransaction();
+        }
+        finally
+        {
+            //
+            // Reset original Proxy settings
+            //
+            cldProductGroup.setProxyClass(productGroupProxy);
+            cldProductGroup.setProxyClassName(productGroupProxy.getName());
+            cldArticle.setProxyClass(articleProxy);
+            cldArticle.setProxyClassName(articleProxy.getName());
+        }
+    }
+
+    public void testNonPrefetched()
+    {
+        ClassDescriptor cldProductGroup = broker.getClassDescriptor(ProductGroup.class);
+        ClassDescriptor cldArticle = broker.getClassDescriptor(Article.class);
+        Class productGroupProxy = cldProductGroup.getProxyClass();
+        Class articleProxy = cldArticle.getProxyClass();
+
+        //
+        // use ProductGroup and Articles with disabled Proxy
+        //
+        cldProductGroup.setProxyClass(null);
+        cldProductGroup.setProxyClassName(null);
+        cldArticle.setProxyClass(null);
+        cldArticle.setProxyClassName(null);
+
+        resetStmtCount();
+        broker.clearCache();
+
+        broker.beginTransaction();
+
+        Criteria crit = new Criteria();
+        crit.addLessOrEqualThan("groupId", new Integer(5));
+        QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
+        q.addOrderByDescending("groupId");
+
+        Collection results = broker.getCollectionByQuery(q);
+        assertEquals("Number of ProductGroups", 5, results.size());
+        Collection articles = new ArrayList();
+        for(Iterator it = results.iterator(); it.hasNext();)
+        {
+            ProductGroup p = (ProductGroup) it.next();
+            articles.addAll(p.getAllArticles());
+        }
+        assertEquals("Total number of Articles", 59, articles.size());
+
+        //SELECT A0.KategorieName,A0.Kategorie_Nr,A0.Beschreibung FROM Kategorien A0 WHERE
A0.Kategorie_Nr <=  '5'
+        //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '5'
+        //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '5'
+        //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '5'
+        //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '4'
+        //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '4'
+        //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '4'
+        //...
+        //SELECT ... FROM CDS A0 WHERE A0.Kategorie_Nr =  '1'
+        //SELECT ... FROM Artikel A0 WHERE A0.Kategorie_Nr =  '1'
+        //SELECT ... FROM BOOKS A0 WHERE A0.Kategorie_Nr =  '1'
+        assertStmtCount("Read Non-Prefetched.", 16);
+        broker.commitTransaction();
+
+        //
+        // Reset original Proxy settings
+        //
+        cldProductGroup.setProxyClass(productGroupProxy);
+        cldProductGroup.setProxyClassName(productGroupProxy.getName());
+        cldArticle.setProxyClass(articleProxy);
+        cldArticle.setProxyClassName(articleProxy.getName());
+
+    }
+
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java?view=diff&rev=524318&r1=524317&r2=524318
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java Fri Mar
30 16:11:07 2007
@@ -8,8 +8,6 @@
 import org.apache.ojb.broker.CdArticle;
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.InterfaceArticle;
-import org.apache.ojb.broker.PersistenceBroker;
-import org.apache.ojb.broker.cache.ObjectCacheEmptyImpl;
 
 /**
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
@@ -17,53 +15,21 @@
  */
 public class EmptyCacheCountTest extends AbstractCountTest
 {
-  protected PersistenceBroker myPB;
-
-  private Class old_ObjectCache;
-  private String[] old_CacheFilter;
-
-  /**
-   * switch cache to {@link ObjectCacheEmptyImpl}.
-   * @throws Exception
-   */
-  protected void setUp() throws Exception
-  {
-    // TODO: fix test to support OJB 1.1
-      // ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheEmptyImpl.class);
-    super.setUp();
-    myPB = ojb.lookupBroker();
-    //old_CacheFilter = getConfig().getCacheFilters();
-    //old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
-  }
-
-  /**
-   * undo Cache change.
-   * @throws Exception
-   */
-  protected void tearDown() throws Exception
-  {
-    //getConfig().setCacheFilters(old_CacheFilter);
-    //ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
-    super.tearDown();
-  }
-
-  /**
-   * retrieve one CdArticle twice.
-   */
-  public void testAccessArticleTwice()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    myPB.beginTransaction();
-    Identity id = myPB.serviceIdentity().buildIdentity(null, InterfaceArticle.class, new
Object[] {new Integer(200)});
-    logger.info(id.toString());
-    assertNull(id.getObjectsRealClass());
-    myPB.getObjectByIdentity(id);
-    assertEquals(CdArticle.class, id.getObjectsRealClass());
-    assertStmtCount("access one cd", 1, 3); // 3 tables: Artikel, BOOKS, CDS
-    resetStmtCount();
-    myPB.getObjectByIdentity(id);
-    assertStmtCount("access one cd again", 1); // lookup again, but exploit objectsRealClass
-    myPB.commitTransaction();
-  }
+    /**
+     * retrieve one CdArticle twice.
+     */
+    public void testAccessArticleTwice()
+    {
+        resetStmtCount();
+        broker.clearCache();
+        broker.beginTransaction();
+        Identity id = broker.serviceIdentity().buildIdentity(InterfaceArticle.class, new
Integer(200));
+        InterfaceArticle result = (InterfaceArticle) broker.getObjectByIdentity(id);
+        assertTrue(result instanceof CdArticle);
+        assertStmtCount("access one cd", 1, 3); // 3 tables: Artikel, BOOKS, CDS
+        resetStmtCount();
+        broker.getObjectByIdentity(id);
+        assertStmtCount("access one cd again", 0, 1); // lookup from session cache expected
+        broker.commitTransaction();
+    }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java?view=diff&rev=524318&r1=524317&r2=524318
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java Fri Mar 30 16:11:07
2007
@@ -1,11 +1,10 @@
 package org.apache.ojb.broker.sqlcount;
 
+import java.util.Collection;
+
 import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.Person;
 
-import java.util.Collection;
-
 /**
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
  * @version $Id$
@@ -13,75 +12,77 @@
 public class SimpleCountTest
         extends org.apache.ojb.broker.sqlcount.AbstractCountTest
 {
-  private Identity aId;
-
-  protected PersistenceBroker myPB;
+    private Identity oid;
 
-  protected void setUp() throws Exception
-  {
-    super.setUp();
-    resetStmtCount();
-    myPB = ojb.lookupBroker();
-    myPB.beginTransaction();
-    Person a = new Person();
-    a.setFirstname("A");
-    myPB.store(a);
-    aId = myPB.serviceIdentity().buildIdentity(a);
-    myPB.commitTransaction();
-    logStmtCount("Wrote test data");
-  }
-
-  /**
-   * very simple test: retrieve a person from the database
-   */
-  public void testRetrievePerson()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    logger.info("begin txn");
-    myPB.beginTransaction();
-    logger.info("retrieving person");
-    Person a = (Person)myPB.getObjectByIdentity(aId);
-    // SELECT ... FROM PERSON WHERE ID = ..
-    // SELECT ... FROM PERSON_PROJECT WHERE PERSON_ID = ..
-    // SELECT ... FROM PROJECT, PERSON_PROJECT WHERE ...
-    logger.info("comitting txn");
-    // COMMIT
-    myPB.commitTransaction();
-    assertStmtCount("retrieve Person by Identity", 4);
-  }
-
-  public void testRetrievePersonTwice()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    logger.info("begin txn");
-    myPB.beginTransaction();
-    Person a = (Person)myPB.getObjectByIdentity(aId);   // see above
-    assertStmtCount("retrieve Person by Identity", 3);
-    resetStmtCount();
-    Person b = (Person)myPB.getObjectByIdentity(aId);   // should use cache
-    assertSame(a, b);
-    assertStmtCount("retrieve Person 2nd time", 0);
-    myPB.commitTransaction();
-  }
-
-  public void testRetrieveEmptyProjects()
-  {
-    resetStmtCount();
-    myPB.clearCache();
-    logger.info("begin txn");
-    myPB.beginTransaction();
-    Person a = (Person)myPB.getObjectByIdentity(aId);   // see above
-    assertStmtCount("retrieve Person by Identity", 3);
-    resetStmtCount();
-    logger.info("accessing projects");
-    Collection c = a.getProjects();
-    assertEquals(0, c.size());
-    assertStmtCount("accessing non-proxy collection", 0);
-    Collection d = a.getRoles();
-    assertStmtCount("accessing proxy-collection", 0);
-    assertEquals(0, d.size());
-    myPB.commitTransaction();
-  }
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        resetStmtCount();
+        prepareTest();
+    }
+
+    private void prepareTest()
+    {
+        broker.beginTransaction();
+        Person a = new Person();
+        a.setFirstname("A");
+        broker.store(a);
+        oid = broker.serviceIdentity().buildIdentity(a);
+        broker.commitTransaction();
+        logStmtCount("Wrote test data");
+    }
+
+    /**
+     * very simple test: retrieve a person from the database
+     */
+    public void testRetrievePerson()
+    {
+        resetStmtCount();
+        broker.clearCache();
+        logger.info("begin txn");
+        broker.beginTransaction();
+        logger.info("retrieving person");
+        Person a = (Person) broker.getObjectByIdentity(oid);
+        // SELECT ... FROM PERSON WHERE ID = ..
+        // SELECT ... FROM PERSON_PROJECT WHERE PERSON_ID = ..
+        // SELECT ... FROM PROJECT, PERSON_PROJECT WHERE ...
+        logger.info("comitting txn");
+        // COMMIT
+        broker.commitTransaction();
+        assertStmtCount("retrieve Person by Identity", 4);
+    }
+
+    public void testRetrievePersonTwice()
+    {
+        resetStmtCount();
+        broker.clearCache();
+        logger.info("begin txn");
+        broker.beginTransaction();
+        Person a = (Person) broker.getObjectByIdentity(oid);   // see above
+        assertStmtCount("retrieve Person by Identity", 3);
+        resetStmtCount();
+        Person b = (Person) broker.getObjectByIdentity(oid);   // should use cache
+        assertSame(a, b);
+        assertStmtCount("retrieve Person 2nd time", 0);
+        broker.commitTransaction();
+    }
+
+    public void testRetrieveEmptyProjects()
+    {
+        resetStmtCount();
+        broker.clearCache();
+        logger.info("begin txn");
+        broker.beginTransaction();
+        Person a = (Person) broker.getObjectByIdentity(oid);   // see above
+        assertStmtCount("retrieve Person by Identity", 3);
+        resetStmtCount();
+        logger.info("accessing projects");
+        Collection c = a.getProjects();
+        assertEquals(0, c.size());
+        assertStmtCount("accessing non-proxy collection", 0);
+        Collection d = a.getRoles();
+        assertStmtCount("accessing proxy-collection", 0);
+        assertEquals(0, d.size());
+        broker.commitTransaction();
+    }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java?view=diff&rev=524318&r1=524317&r2=524318
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java Fri Mar 30
16:11:07 2007
@@ -15,35 +15,6 @@
  */
 public class TwoLevelSimpleTest extends AbstractCountTest
 {
-    private Class old_ObjectCache;
-    private String[] old_CacheFilter;
-
-    /**
-     * switch cache to {@link org.apache.ojb.broker.cache.TwoLevelCache}.
-     *
-     * @throws Exception
-     */
-    protected void setUp() throws Exception
-    {
-        // TODO: update test case for use in OJB 1.1
-        // ObjectCacheFactory.getInstance().setClassToServe(TwoLevelCache.class);
-        //ObjectCacheFactory.getInstance().setClassToServe(org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl.class);
-        super.setUp();
-        //old_CacheFilter = getConfig().getCacheFilters();
-        // old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
-    }
-
-    /**
-     * undo Cache change.
-     *
-     * @throws Exception
-     */
-    protected void tearDown() throws Exception
-    {
-        //getConfig().setCacheFilters(old_CacheFilter);
-        //ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
-        super.tearDown();
-    }
 
     /**
      * retrieve one CdArticle twice.
@@ -58,7 +29,7 @@
         resetStmtCount();
         pb0.clearCache();
         pb0.beginTransaction();
-        Identity id = pb0.serviceIdentity().buildIdentity(null, CloneableGroup.class, new
Object[] {new Integer(1)});
+        Identity id = pb0.serviceIdentity().buildIdentity(null, CloneableGroup.class, new
Object[]{new Integer(1)});
         logger.info(id.toString());
         assertNull(id.getObjectsRealClass());
         Object group0 = pb0.getObjectByIdentity(id);



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