1 package org.apache.ojb.broker.sqlcount; 2 3 import org.apache.ojb.broker.Identity; 4 import org.apache.ojb.broker.PersistenceBroker; 5 import org.apache.ojb.broker.PersistenceBrokerFactory; 6 import org.apache.ojb.broker.Person; 7 8 import java.util.Collection ; 9 10 14 public class SimpleCountTest 15 extends org.apache.ojb.broker.sqlcount.AbstractCountTest 16 { 17 private Identity aId; 18 19 protected PersistenceBroker myPB; 20 21 protected void setUp() throws Exception 22 { 23 super.setUp(); 24 resetStmtCount(); 25 myPB = PersistenceBrokerFactory.defaultPersistenceBroker(); 26 myPB.beginTransaction(); 27 Person a = new Person(); 28 a.setFirstname("A"); 29 myPB.store(a); 30 aId = new Identity(a, myPB); 31 myPB.commitTransaction(); 32 logStmtCount("Wrote test data"); 33 } 34 35 38 public void testRetrievePerson() 39 { 40 resetStmtCount(); 41 myPB.clearCache(); 42 logger.info("begin txn"); 43 myPB.beginTransaction(); 44 logger.info("retrieving person"); 45 Person a = (Person)myPB.getObjectByIdentity(aId); 46 logger.info("comitting txn"); 50 myPB.commitTransaction(); 52 assertStmtCount("retrieve Person by Identity", 4); 53 } 54 55 public void testRetrievePersonTwice() 56 { 57 resetStmtCount(); 58 myPB.clearCache(); 59 logger.info("begin txn"); 60 myPB.beginTransaction(); 61 Person a = (Person)myPB.getObjectByIdentity(aId); assertStmtCount("retrieve Person by Identity", 3); 63 resetStmtCount(); 64 Person b = (Person)myPB.getObjectByIdentity(aId); assertSame(a, b); 66 assertStmtCount("retrieve Person 2nd time", 0); 67 myPB.commitTransaction(); 68 } 69 70 public void testRetrieveEmptyProjects() 71 { 72 resetStmtCount(); 73 myPB.clearCache(); 74 logger.info("begin txn"); 75 myPB.beginTransaction(); 76 Person a = (Person)myPB.getObjectByIdentity(aId); assertStmtCount("retrieve Person by Identity", 3); 78 resetStmtCount(); 79 logger.info("accessing projects"); 80 Collection c = a.getProjects(); 81 assertEquals(0, c.size()); 82 assertStmtCount("accessing non-proxy collection", 0); 83 Collection d = a.getRoles(); 84 assertStmtCount("accessing proxy-collection", 0); 85 assertEquals(0, d.size()); 86 myPB.commitTransaction(); 87 } 88 } 89 | Popular Tags |