1 22 package org.jboss.test.readahead.ejb; 23 24 import java.util.Iterator ; 25 import java.util.Collection ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 import javax.ejb.EJBException ; 29 import javax.ejb.SessionBean ; 30 import javax.ejb.SessionContext ; 31 import org.jboss.test.readahead.interfaces.AddressHome; 32 import org.jboss.test.readahead.interfaces.AddressRemote; 33 import org.jboss.test.readahead.interfaces.CMPFindTestEntityHome; 34 import org.jboss.test.readahead.interfaces.CMPFindTestEntityRemote; 35 36 45 public class CMPFindTestSession implements SessionBean { 46 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 47 48 private static final int DATASET_SIZE = 100; 49 50 private SessionContext sessionContext; 51 52 public void ejbCreate() { 53 } 54 public void ejbRemove() { 55 } 56 public void ejbActivate() { 57 } 58 public void ejbPassivate() { 59 } 60 public void setSessionContext(SessionContext context) { 61 sessionContext = context; 62 } 63 64 public void removeTestData() { 65 try { 66 InitialContext ctx = new InitialContext (); 67 CMPFindTestEntityHome home = (CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity"); 68 69 Collection coll = home.findAll(); 70 Iterator iter = coll.iterator(); 71 while (iter.hasNext()) { 72 CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next(); 73 74 rem.remove(); 75 } 76 } catch (Exception e) { 77 } 78 } 79 80 public void createTestData() { 81 try { 82 InitialContext ctx = new InitialContext (); 83 CMPFindTestEntityHome home = (CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity"); 84 AddressHome addrHome = (AddressHome)ctx.lookup("Address"); 85 for (int i=0;i<DATASET_SIZE;i++) { 86 String key = Long.toString(System.currentTimeMillis())+"-"+i; 87 CMPFindTestEntityRemote rem = home.create(key); 88 rem.setName("Name"); 89 rem.setRank("Rank"); 90 rem.setSerialNumber("123456789"); 91 if ((i % 2) ==0) { 93 addrHome.create(rem.getKey(), "1", "123 east st.", "Eau Claire", "WI", "54701"); 94 } else { 95 addrHome.create(rem.getKey(), "1", "123 east st.", "Milwaukee", "WI", "54201"); 96 } 97 } 98 } catch (Exception e) { 99 log.debug("Exception caught: "+e); 100 log.debug("failed", e); 101 throw new EJBException (e.getMessage()); 102 } 103 } 104 105 public void addressByCity() { 106 try { 107 InitialContext ctx = new InitialContext (); 108 AddressHome home = (AddressHome)ctx.lookup("Address"); 109 110 long startTime = System.currentTimeMillis(); 111 Collection coll = home.findByCity("Eau Claire"); 112 int count = 0; 113 Iterator iter = coll.iterator(); 114 while (iter.hasNext()) { 115 AddressRemote rem = (AddressRemote)iter.next(); 116 rem.getCity(); 117 count++; 119 } 120 long endTime = System.currentTimeMillis(); 121 log.debug("called "+count+" beans in "+(endTime-startTime)+" ms."); 122 } catch (Exception e) { 123 log.debug("Caught "+e); 124 } 125 } 126 127 public void testByCity() { 128 try { 129 InitialContext ctx = new InitialContext (); 130 CMPFindTestEntityHome home = (CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity"); 131 132 long startTime = System.currentTimeMillis(); 133 Collection coll = home.findByCity("Eau Claire"); 134 int count = 0; 135 Iterator iter = coll.iterator(); 136 while (iter.hasNext()) { 137 CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next(); 138 rem.getName(); 139 count++; 141 } 142 long endTime = System.currentTimeMillis(); 143 log.debug("called "+count+" beans in "+(endTime-startTime)+" ms."); 144 } catch (Exception e) { 145 } 146 } 147 public void testFinder() { 148 try { 149 InitialContext ctx = new InitialContext (); 150 CMPFindTestEntityHome home = (CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity"); 151 152 long startTime = System.currentTimeMillis(); 153 Collection coll = home.findAll(); 154 int count = 0; 155 Iterator iter = coll.iterator(); 156 while (iter.hasNext()) { 157 CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next(); 158 rem.getName(); 159 count++; 161 } 162 long endTime = System.currentTimeMillis(); 163 log.debug("called "+count+" beans in "+(endTime-startTime)+" ms."); 164 } catch (Exception e) { 165 } 166 } 167 168 public void testUpdates() { 169 try { 170 InitialContext ctx = new InitialContext (); 171 CMPFindTestEntityHome home = (CMPFindTestEntityHome)ctx.lookup("CMPFindTestEntity"); 172 173 long startTime = System.currentTimeMillis(); 174 Collection coll = home.findAll(); 175 int count = 0; 176 Iterator iter = coll.iterator(); 177 while (iter.hasNext()) { 178 CMPFindTestEntityRemote rem = (CMPFindTestEntityRemote)iter.next(); 179 rem.getName(); 180 rem.setRank("Very"); 181 count++; 182 } 183 long endTime = System.currentTimeMillis(); 184 log.debug("called "+count+" beans in "+(endTime-startTime)+" ms."); 185 } catch (Exception e) { 186 } 187 } 188 } 189 | Popular Tags |