KickJava   Java API By Example, From Geeks To Geeks.

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


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.Identity;
9 import org.apache.ojb.broker.PersistenceBroker;
10 import org.apache.ojb.broker.PersistenceBrokerFactory;
11 import org.apache.ojb.broker.cloneable.CloneableGroup;
12 import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
13 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
14
15 /**
16  * @author <a HREF="mailto:om@ppi.de">Oliver Matz</a>
17  * @version $Id: TwoLevelSimpleTest.java,v 1.1.4.2 2005/08/16 15:04:39 aclute Exp $
18  */

19 public class TwoLevelSimpleTest extends AbstractCountTest
20 {
21   private Class JavaDoc old_ObjectCache;
22   private String JavaDoc[] old_CacheFilter;
23
24   private OjbConfiguration getConfig()
25   {
26       return (OjbConfiguration) OjbConfigurator.getInstance().getConfigurationFor(null);
27   }
28   /**
29    * switch cache to {@link org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl}.
30    * @throws Exception
31    */

32   protected void setUp() throws Exception JavaDoc
33   {
34     //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheTwoLevelImpl.class);
35
//ObjectCacheFactory.getInstance().setClassToServe(org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl.class);
36
super.setUp();
37     //old_CacheFilter = getConfig().getCacheFilters();
38
//old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
39
}
40
41   /**
42    * undo Cache change.
43    * @throws Exception
44    */

45   protected void tearDown() throws Exception JavaDoc
46   {
47     //getConfig().setCacheFilters(old_CacheFilter);
48
//ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
49
super.tearDown();
50   }
51
52   /**
53    * retrieve one CdArticle twice.
54    */

55   public void testAccessArticleTwice()
56   {
57     PersistenceBroker pb0, pb1;
58     pb0 = PersistenceBrokerFactory.defaultPersistenceBroker();
59     pb1 = PersistenceBrokerFactory.defaultPersistenceBroker();
60     assertNotSame(pb0, pb1);
61
62     resetStmtCount();
63     pb0.clearCache();
64     pb0.beginTransaction();
65     Identity id = new Identity(null, CloneableGroup.class, new Object JavaDoc[] {new Integer JavaDoc(1)});
66     logger.info(id.toString());
67     assertNull(id.getObjectsRealClass());
68     Object JavaDoc group0 = pb0.getObjectByIdentity(id);
69     assertNotNull(group0);
70     assertEquals(CloneableGroup.class, id.getObjectsRealClass());
71     assertStmtCount("access one group", 1);
72     pb0.commitTransaction();
73
74     resetStmtCount();
75     pb1.beginTransaction();
76     Object JavaDoc group1 = pb1.getObjectByIdentity(id);
77     assertStmtCount("access one group again", 0); // lookup again, 2nd level hit, no SQL access.
78
assertNotSame(group0, group1);
79     pb1.commitTransaction();
80   }
81 }
82
Popular Tags