KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > sqlcount > EmptyCacheCountTest


1 /*
2  * (C) 2003 ppi Media
3  * User: om
4  */

5
6 package org.apache.ojb.broker.sqlcount;
7
8 import org.apache.ojb.broker.CdArticle;
9 import org.apache.ojb.broker.Identity;
10 import org.apache.ojb.broker.InterfaceArticle;
11 import org.apache.ojb.broker.PersistenceBroker;
12 import org.apache.ojb.broker.PersistenceBrokerFactory;
13 import org.apache.ojb.broker.cache.ObjectCacheEmptyImpl;
14 import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
15 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
16
17 /**
18  * @author <a HREF="mailto:om@ppi.de">Oliver Matz</a>
19  * @version $Id: EmptyCacheCountTest.java,v 1.2.4.2 2005/08/16 15:04:39 aclute Exp $
20  */

21 public class EmptyCacheCountTest extends AbstractCountTest
22 {
23   protected PersistenceBroker myPB;
24
25   private Class JavaDoc old_ObjectCache;
26   private String JavaDoc[] old_CacheFilter;
27
28   private OjbConfiguration getConfig()
29   {
30       return (OjbConfiguration) OjbConfigurator.getInstance().getConfigurationFor(null);
31   }
32
33   /**
34    * switch cache to {@link ObjectCacheEmptyImpl}.
35    * @throws Exception
36    */

37   protected void setUp() throws Exception JavaDoc
38   {
39     //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheEmptyImpl.class);
40
super.setUp();
41     myPB = PersistenceBrokerFactory.defaultPersistenceBroker();
42     //old_CacheFilter = getConfig().getCacheFilters();
43
//old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
44
}
45
46   /**
47    * undo Cache change.
48    * @throws Exception
49    */

50   protected void tearDown() throws Exception JavaDoc
51   {
52     //getConfig().setCacheFilters(old_CacheFilter);
53
//ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
54
super.tearDown();
55   }
56
57   /**
58    * retrieve one CdArticle twice.
59    */

60   public void testAccessArticleTwice()
61   {
62     resetStmtCount();
63     myPB.clearCache();
64     myPB.beginTransaction();
65     Identity id = new Identity(null, InterfaceArticle.class, new Object JavaDoc[] {new Integer JavaDoc(200)});
66     logger.info(id.toString());
67     assertNull(id.getObjectsRealClass());
68     myPB.getObjectByIdentity(id);
69     assertEquals(CdArticle.class, id.getObjectsRealClass());
70     assertStmtCount("access one cd", 1, 3); // 3 tables: Artikel, BOOKS, CDS
71
resetStmtCount();
72     myPB.getObjectByIdentity(id);
73     assertStmtCount("access one cd again", 1); // lookup again, but exploit objectsRealClass
74
myPB.commitTransaction();
75   }
76 }
77
Popular Tags