db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r524317 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount: AbstractCountTest.java CollectionCountTest.java EmptyCacheCountTest.java SimpleCountTest.java TwoLevelSimpleTest.java
Date Fri, 30 Mar 2007 23:10:40 GMT
Author: arminw
Date: Fri Mar 30 16:10:39 2007
New Revision: 524317

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

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

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java?view=diff&rev=524317&r1=524316&r2=524317
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/AbstractCountTest.java
Fri Mar 30 16:10:39 2007
@@ -10,6 +10,9 @@
 import org.apache.ojb.broker.metadata.MetadataManager;
 import org.apache.ojb.broker.PBKey;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.junit.OJBTestCase;
+import org.apache.ojb.junit.PBTestCase;
 
 import java.io.File;
 
@@ -19,86 +22,86 @@
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
  * @version $Id$
  */
-public abstract class AbstractCountTest extends TestCase
+public abstract class AbstractCountTest extends PBTestCase
 {
-  private int stmtCount;
-  protected final Logger logger = LoggerFactory.getLogger(this.getClass());
-  private static final File SPY_PROPS_FILE = new File("testsuite-spy.properties");
-
-  /**
-   * sets the spy.properties file name.
-   */
-  protected void setUp() throws Exception
-  {
-    if (!SPY_PROPS_FILE.exists())
-      fail("Missing file: " + SPY_PROPS_FILE.getAbsolutePath());
-    P6SpyProperties.setSpyProperties(SPY_PROPS_FILE.getName());
-    checkP6spyEnabled(PersistenceBrokerFactory.getDefaultKey());
-  }
-
-  /**
-   * start count SQL statements
-   */
-  protected final void resetStmtCount()
-  {
-    stmtCount = CountLogger.getSQLStatementCount();
-  }
-
-  /**
-   * assert that the number of statements issued since the last call of {@link #resetStmtCount()}.
-   * is between two specified numbers.
-   *
-   * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
-   */
-  protected final void assertStmtCount(String msg, int minExpected, int maxExpected)
-  {
-    int stmtNum = CountLogger.getSQLStatementCount() - stmtCount;
-    if (stmtNum > maxExpected)
-      fail(msg + ": more SQL statements than expected. Expected: " + maxExpected + ", was:
" + stmtNum);
-    else if (minExpected > 0 && stmtNum == 0)
-      fail("No SQL statements, maybe CountLogger not enabled?");
-    else if (stmtNum < minExpected)
-      fail(msg + ": less SQL statements than expected (Performance improvement? Please correct
test limit)."
-               +  " Expected: " + minExpected + ", was: " + stmtNum);
-    else
-    {
-      logStmtCount(msg, stmtNum);
-    }
-  }
-
-  /**
-   * assert that the number of statements issued since the last call of {@link #resetStmtCount()}.
-   * is equal to a specified number.
-   *
-   * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
-   */
-  protected final void assertStmtCount(String msg, int expected)
-  {
-    assertStmtCount(msg, expected, expected);
-  }
-
-  private void logStmtCount(String msg, int num)
-  {
-    logger.info(msg + ": " + num);
-  }
-
-  protected final void logStmtCount(String msg)
-  {
-    logStmtCount(msg, CountLogger.getSQLStatementCount() - stmtCount);
-  }
-
-  /**
-   * fail ifF the specified PersistenceBroker does not use P6Spy.
-   */
-  protected final void checkP6spyEnabled(PBKey pbKey)
-  {
-    JdbcConnectionDescriptor conDesc
-            = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
-    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"
+
-           " or use ant build property '-DuseP6Spy=true'");
+    private int stmtCount;
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+    private static final File SPY_PROPS_FILE = new File("testsuite-spy.properties");
+
+    /**
+     * sets the spy.properties file name.
+     */
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        if(!SPY_PROPS_FILE.exists())
+            fail("Missing file: " + SPY_PROPS_FILE.getAbsolutePath());
+        P6SpyProperties.setSpyProperties(SPY_PROPS_FILE.getName());
+        checkP6spyEnabled(broker);
+    }
+
+    /**
+     * start count SQL statements
+     */
+    protected final void resetStmtCount()
+    {
+        stmtCount = CountLogger.getSQLStatementCount();
+    }
+
+    /**
+     * assert that the number of statements issued since the last call of {@link #resetStmtCount()}.
+     * is between two specified numbers.
+     *
+     * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
+     */
+    protected final void assertStmtCount(String msg, int minExpected, int maxExpected)
+    {
+        int stmtNum = CountLogger.getSQLStatementCount() - stmtCount;
+        if(stmtNum > maxExpected)
+            fail(msg + ": more SQL statements than expected. Expected: " + maxExpected +
", was: " + stmtNum);
+        else if(minExpected > 0 && stmtNum == 0)
+            fail("No SQL statements, maybe CountLogger not enabled?");
+        else if(stmtNum < minExpected)
+            fail(msg + ": less SQL statements than expected (Performance improvement? Please
correct test limit)."
+                    + " Expected: " + minExpected + ", was: " + stmtNum);
+        else
+        {
+            logStmtCount(msg, stmtNum);
+        }
+    }
+
+    /**
+     * assert that the number of statements issued since the last call of {@link #resetStmtCount()}.
+     * is equal to a specified number.
+     *
+     * @param msg short description of the actions since the last call of {@link #resetStmtCount()}.
+     */
+    protected final void assertStmtCount(String msg, int expected)
+    {
+        assertStmtCount(msg, expected, expected);
+    }
+
+    private void logStmtCount(String msg, int num)
+    {
+        logger.info(msg + ": " + num);
+    }
+
+    protected final void logStmtCount(String msg)
+    {
+        logStmtCount(msg, CountLogger.getSQLStatementCount() - stmtCount);
+    }
+
+    /**
+     * fail ifF the specified PersistenceBroker does not use P6Spy.
+     */
+    protected final void checkP6spyEnabled(PersistenceBroker broker)
+    {
+        JdbcConnectionDescriptor conDesc = broker.serviceConnectionManager().getConnectionDescriptor();
+        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"
+
+                    " or use ant build property '-DuseP6Spy=true'");
+        }
     }
-  }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java?view=diff&rev=524317&r1=524316&r2=524317
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/CollectionCountTest.java
Fri Mar 30 16:10:39 2007
@@ -12,11 +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.PersistenceBrokerFactory;
 import org.apache.ojb.broker.Person;
 import org.apache.ojb.broker.ProductGroup;
 import org.apache.ojb.broker.Project;
@@ -33,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 = PersistenceBrokerFactory.defaultPersistenceBroker();
-  }
-
-  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 = new QueryByCriteria(ProductGroup.class, 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/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java?view=diff&rev=524317&r1=524316&r2=524317
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/EmptyCacheCountTest.java
Fri Mar 30 16:10:39 2007
@@ -20,57 +20,21 @@
  */
 public class EmptyCacheCountTest extends AbstractCountTest
 {
-  protected PersistenceBroker myPB;
-
-  private Class old_ObjectCache;
-  private String[] old_CacheFilter;
-
-  private OjbConfiguration getConfig()
-  {
-      return (OjbConfiguration) OjbConfigurator.getInstance().getConfigurationFor(null);
-  }
-
-  /**
-   * switch cache to {@link ObjectCacheEmptyImpl}.
-   * @throws Exception
-   */
-  protected void setUp() throws Exception
-  {
-    //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheEmptyImpl.class);
-    super.setUp();
-    myPB = PersistenceBrokerFactory.defaultPersistenceBroker();
-    //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/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java?view=diff&rev=524317&r1=524316&r2=524317
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/SimpleCountTest.java
Fri Mar 30 16:10:39 2007
@@ -1,88 +1,87 @@
 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.PersistenceBrokerFactory;
 import org.apache.ojb.broker.Person;
 
-import java.util.Collection;
-
 /**
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
  * @version $Id$
  */
-public class SimpleCountTest
-        extends org.apache.ojb.broker.sqlcount.AbstractCountTest
+public class SimpleCountTest extends AbstractCountTest
 {
-  private Identity aId;
-
-  protected PersistenceBroker myPB;
+    private Identity oid;
 
-  protected void setUp() throws Exception
-  {
-    super.setUp();
-    resetStmtCount();
-    myPB = PersistenceBrokerFactory.defaultPersistenceBroker();
-    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/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java?view=diff&rev=524317&r1=524316&r2=524317
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sqlcount/TwoLevelSimpleTest.java
Fri Mar 30 16:10:39 2007
@@ -9,8 +9,6 @@
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
 import org.apache.ojb.broker.cloneable.CloneableGroup;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
 
 /**
  * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
@@ -18,64 +16,34 @@
  */
 public class TwoLevelSimpleTest extends AbstractCountTest
 {
-  private Class old_ObjectCache;
-  private String[] old_CacheFilter;
 
-  private OjbConfiguration getConfig()
-  {
-      return (OjbConfiguration) OjbConfigurator.getInstance().getConfigurationFor(null);
-  }
-  /**
-   * switch cache to {@link org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl}.
-   * @throws Exception
-   */
-  protected void setUp() throws Exception
-  {
-    //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheTwoLevelImpl.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.
-   */
-  public void testAccessArticleTwice()
-  {
-    PersistenceBroker pb0, pb1;
-    pb0 = PersistenceBrokerFactory.defaultPersistenceBroker();
-    pb1 = PersistenceBrokerFactory.defaultPersistenceBroker();
-    assertNotSame(pb0, pb1);
-
-    resetStmtCount();
-    pb0.clearCache();
-    pb0.beginTransaction();
-    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);
-    assertNotNull(group0);
-    assertEquals(CloneableGroup.class, id.getObjectsRealClass());
-    assertStmtCount("access one group", 1);
-    pb0.commitTransaction();
-
-    resetStmtCount();
-    pb1.beginTransaction();
-    Object group1 = pb1.getObjectByIdentity(id);
-    assertStmtCount("access one group again", 0); // lookup again, 2nd level hit, no SQL
access.
-    assertNotSame(group0, group1);
-    pb1.commitTransaction();
-  }
+    /**
+     * retrieve one CdArticle twice.
+     */
+    public void testAccessArticleTwice()
+    {
+        PersistenceBroker pb0, pb1;
+        pb0 = PersistenceBrokerFactory.defaultPersistenceBroker();
+        pb1 = PersistenceBrokerFactory.defaultPersistenceBroker();
+        assertNotSame(pb0, pb1);
+
+        resetStmtCount();
+        pb0.clearCache();
+        pb0.beginTransaction();
+        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);
+        assertNotNull(group0);
+        assertEquals(CloneableGroup.class, id.getObjectsRealClass());
+        assertStmtCount("access one group", 1);
+        pb0.commitTransaction();
+
+        resetStmtCount();
+        pb1.beginTransaction();
+        Object group1 = pb1.getObjectByIdentity(id);
+        assertStmtCount("access one group again", 0); // lookup again, 2nd level hit, no
SQL access.
+        assertNotSame(group0, group1);
+        pb1.commitTransaction();
+    }
 }



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