01: /*
02: * (C) 2003 ppi Media
03: * User: om
04: */
05:
06: package org.apache.ojb.broker.sqlcount;
07:
08: import org.apache.ojb.broker.CdArticle;
09: 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: protected PersistenceBroker myPB;
23:
24: private Class old_ObjectCache;
25: private String[] old_CacheFilter;
26:
27: private OjbConfiguration getConfig() {
28: return (OjbConfiguration) OjbConfigurator.getInstance()
29: .getConfigurationFor(null);
30: }
31:
32: /**
33: * switch cache to {@link ObjectCacheEmptyImpl}.
34: * @throws Exception
35: */
36: protected void setUp() throws Exception {
37: //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheEmptyImpl.class);
38: super .setUp();
39: myPB = PersistenceBrokerFactory.defaultPersistenceBroker();
40: //old_CacheFilter = getConfig().getCacheFilters();
41: //old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
42: }
43:
44: /**
45: * undo Cache change.
46: * @throws Exception
47: */
48: protected void tearDown() throws Exception {
49: //getConfig().setCacheFilters(old_CacheFilter);
50: //ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
51: super .tearDown();
52: }
53:
54: /**
55: * retrieve one CdArticle twice.
56: */
57: public void testAccessArticleTwice() {
58: resetStmtCount();
59: myPB.clearCache();
60: myPB.beginTransaction();
61: Identity id = new Identity(null, InterfaceArticle.class,
62: new Object[] { new Integer(200) });
63: logger.info(id.toString());
64: assertNull(id.getObjectsRealClass());
65: myPB.getObjectByIdentity(id);
66: assertEquals(CdArticle.class, id.getObjectsRealClass());
67: assertStmtCount("access one cd", 1, 3); // 3 tables: Artikel, BOOKS, CDS
68: resetStmtCount();
69: myPB.getObjectByIdentity(id);
70: assertStmtCount("access one cd again", 1); // lookup again, but exploit objectsRealClass
71: myPB.commitTransaction();
72: }
73: }
|