1 22 package org.jboss.test.cmp2.optimisticlock.ejb; 23 24 import org.jboss.test.cmp2.optimisticlock.interfaces.CmpEntityLocal; 25 import org.jboss.test.cmp2.optimisticlock.interfaces.CmpEntityLocalHome; 26 import org.jboss.test.cmp2.optimisticlock.interfaces.FacadeHome; 27 import org.jboss.logging.Logger; 28 29 import javax.ejb.SessionBean ; 30 import javax.ejb.CreateException ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.FinderException ; 33 import javax.naming.NamingException ; 34 import javax.naming.InitialContext ; 35 36 45 public class FacadeBean 46 implements SessionBean 47 { 48 static Logger log = Logger.getLogger(FacadeBean.class); 50 private FacadeHome myHome; 51 52 56 public void createCmpEntity(String jndiName, 57 Integer id, 58 String stringGroup1, 59 Integer integerGroup1, 60 Double doubleGroup1, 61 String stringGroup2, 62 Integer integerGroup2, 63 Double doubleGroup2) 64 throws Exception 65 { 66 if(log.isDebugEnabled()) 67 { 68 log.debug("createCmpEntity> jndiName=" + jndiName 69 + ", id=" + id 70 + ", stringGroup1=" + stringGroup1 71 + ", integerGroup1=" + integerGroup1 72 + ", doubleGroup1=" + doubleGroup1 73 + ", stringGroup2=" + stringGroup2 74 + ", integerGroup2=" + integerGroup2 75 + ", doubleGroup2=" + doubleGroup2); 76 } 77 78 CmpEntityLocalHome entityHome = getCmpEntityHome(jndiName); 79 entityHome.create(id, stringGroup1, integerGroup1, doubleGroup1, 80 stringGroup2, integerGroup2, doubleGroup2); 81 } 82 83 86 public void safeRemove(String jndiName, Integer id) throws Exception 87 { 88 log.debug("safeRemove> jndiName=" + jndiName + ", id=" + id); 89 try 90 { 91 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 92 entity.remove(); 93 } 94 catch(FinderException e){} 95 } 96 97 100 public void testNullLockedFields(String jndiName, Integer id) throws Exception 101 { 102 log.debug("testNullLockedFields> begin"); 103 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 104 entity.setDoubleGroup1(new Double (11.11)); 105 entity.setDoubleGroup2(new Double (22.22)); 106 entity.setIntegerGroup1(new Integer (11)); 107 entity.setIntegerGroup2(new Integer (22)); 108 entity.setStringGroup1("str1 modified in testNullLockedFields"); 109 entity.setStringGroup2("str2 modified in testNullLockedFields"); 110 log.debug("testNullLockedFields> done"); 111 } 112 113 116 public void testKeygenStrategyPass(String jndiName, Integer id) throws Exception 117 { 118 log.debug("testKeygenStrategyPass> begin"); 119 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 120 entity.setIntegerGroup1(new Integer (111)); 121 entity.setStringGroup2("modified in testKeygenStrategyPass"); 122 entity.getDoubleGroup1(); 123 log.debug("testKeygenStrategyPass> done"); 124 } 125 126 129 public void testKeygenStrategyFail(String jndiName, Integer id) throws Exception 130 { 131 log.debug("testKeygenStrategyFail> begin"); 132 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 133 entity.setIntegerGroup1(new Integer (111)); 134 entity.setStringGroup2("modified in testKeygenStrategyFail"); 135 entity.getDoubleGroup1(); 136 myHome.create().modifyGroup1InRequiresNew(jndiName, id); 137 log.debug("testKeygenStrategyFail> done"); 138 } 139 140 143 public void testTimestampStrategyPass(String jndiName, Integer id) throws Exception 144 { 145 log.debug("testTimestampStrategyPass> begin"); 146 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 147 entity.setIntegerGroup1(new Integer (111)); 148 entity.setStringGroup2("modified in testTimestampStrategyPass"); 149 entity.getDoubleGroup1(); 150 log.debug("testTimestampStrategyPass> done"); 151 } 152 153 156 public void testTimestampStrategyFail(String jndiName, Integer id) throws Exception 157 { 158 log.debug("testTimestampStrategyFail> begin"); 159 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 160 entity.setIntegerGroup1(new Integer (111)); 161 entity.setStringGroup2("modified in testTimestampStrategyFail"); 162 entity.getDoubleGroup1(); 163 myHome.create().modifyGroup1InRequiresNew(jndiName, id); 164 log.debug("testTimestampStrategyFail> done"); 165 } 166 167 170 public void testVersionStrategyPass(String jndiName, Integer id) throws Exception 171 { 172 log.debug("testVersionStrategyPass> begin"); 173 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 174 entity.setIntegerGroup1(new Integer (111)); 175 entity.setStringGroup2("modified in testVersionStrategyPass"); 176 entity.getDoubleGroup1(); 177 log.debug("testVersionStrategyPass> done"); 178 } 179 180 183 public void testVersionStrategyFail(String jndiName, Integer id) throws Exception 184 { 185 log.debug("testVersionStrategyFail> begin"); 186 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 187 entity.setIntegerGroup1(new Integer (111)); 188 entity.setStringGroup2("modified in testVersionStrategyFail"); 189 entity.getDoubleGroup1(); 190 myHome.create().modifyGroup1InRequiresNew(jndiName, id); 191 log.debug("testVersionStrategyFail> done"); 192 } 193 194 197 public void testGroupStrategyPass(String jndiName, Integer id) throws Exception 198 { 199 log.debug("testGroupStrategyPass> begin"); 200 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 201 entity.setIntegerGroup1(new Integer (111)); 202 entity.setStringGroup2("modified in testGroupStrategyPass"); 203 entity.getDoubleGroup1(); 204 myHome.create().modifyGroup1InRequiresNew(jndiName, id); 205 log.debug("testGroupStrategyPass> done"); 206 } 207 208 211 public void testGroupStrategyFail(String jndiName, Integer id) throws Exception 212 { 213 log.debug("testGroupStrategyFail> begin"); 214 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 215 entity.setIntegerGroup1(new Integer (111)); 216 entity.setStringGroup2("modified in testGroupStrategyPass"); 217 entity.getDoubleGroup1(); 218 myHome.create().modifyGroup2InRequiresNew(jndiName, id); 219 log.debug("testGroupStrategyFail> done"); 220 } 221 222 225 public void testReadStrategyPass(String jndiName, Integer id) throws Exception 226 { 227 log.debug("testReadStrategyPass> begin"); 228 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 229 entity.setIntegerGroup1(new Integer (111)); 230 entity.getStringGroup1(); 231 entity.getDoubleGroup1(); 232 myHome.create().modifyGroup2InRequiresNew(jndiName, id); 233 log.debug("testReadStrategyPass> done"); 234 } 235 236 239 public void testReadStrategyFail(String jndiName, Integer id) throws Exception 240 { 241 log.debug("testReadStrategyFail> begin"); 242 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 243 entity.setIntegerGroup1(new Integer (111)); 244 entity.getStringGroup2(); 245 entity.getDoubleGroup1(); 246 myHome.create().modifyGroup2InRequiresNew(jndiName, id); 247 log.debug("testReadStrategyFail> done"); 248 } 249 250 253 public void testModifiedStrategyPass(String jndiName, Integer id) throws Exception 254 { 255 log.debug("testModifiedStrategyPass> begin"); 256 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 257 entity.setIntegerGroup1(new Integer (111)); 258 entity.setStringGroup1("modified in testModifiedStrategyPass"); 259 entity.setDoubleGroup1(new Double (111.111)); 260 myHome.create().modifyGroup2InRequiresNew(jndiName, id); 261 log.debug("testModifiedStrategyPass> done"); 262 } 263 264 267 public void testModifiedStrategyFail(String jndiName, Integer id) throws Exception 268 { 269 log.debug("testModifiedStrategyFail> begin"); 270 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 271 entity.setStringGroup2("modified by testModifiedStrategyFail"); 272 myHome.create().modifyGroup2InRequiresNew(jndiName, id); 273 log.debug("testModifiedStrategyFail> done"); 274 } 275 276 280 public void modifyGroup2InRequiresNew(String jndiName, Integer id) throws Exception 281 { 282 log.debug("modifyGroup2InRequiresNew"); 283 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 284 entity.setIntegerGroup2(new Integer (222)); 285 entity.setStringGroup2("modified by modifyGroup2InRequiresNew"); 286 entity.setDoubleGroup2(new Double (222.222)); 287 } 288 289 293 public void modifyGroup1InRequiresNew(String jndiName, Integer id) throws Exception 294 { 295 log.debug("modifyGroup1InRequiresNew"); 296 CmpEntityLocal entity = getCmpEntityHome(jndiName).findByPrimaryKey(id); 297 entity.setIntegerGroup1(new Integer (333)); 298 entity.setStringGroup1("modified by modifyGroup1InRequiresNew"); 299 entity.setDoubleGroup1(new Double (333.333)); 300 } 301 302 305 public void testUpdateLockOnSync(String jndiName, Integer id) throws Exception 306 { 307 log.debug("testUpdateLockOnSync> begin"); 308 CmpEntityLocal entity = getCmpEntityHome(jndiName).findById(id); 309 entity.setStringGroup1("FIRST UPDATE"); 310 311 entity = getCmpEntityHome(jndiName).findById(id); 312 entity.setStringGroup1("SECOND UPDATE"); 313 314 log.debug("testUpdateLockOnSync> done"); 315 } 316 317 320 public void testExplicitVersionUpdateOnSync(String jndiName, Integer id) throws Exception 321 { 322 log.debug("testExplicitVersionUpdateOnSync> begin"); 323 CmpEntityLocal entity = getCmpEntityHome(jndiName).findById(id); 324 if(entity.getVersionField().longValue() != 1) 325 throw new Exception ("entity.getVersionField().longValue() != 1"); 326 entity.setStringGroup1("FIRST UPDATE"); 327 328 entity = getCmpEntityHome(jndiName).findById(id); 329 if(entity.getVersionField().longValue() != 2) 330 throw new Exception ("entity.getVersionField().longValue() != 2"); 331 entity.setStringGroup1("SECOND UPDATE"); 332 333 log.debug("testExplicitVersionUpdateOnSync> done"); 334 } 335 336 public void setSessionContext(SessionContext ctx) 338 { 339 myHome = (FacadeHome)ctx.getEJBHome(); 340 } 341 public void ejbCreate() throws CreateException {} 342 public void ejbRemove() {} 343 public void ejbActivate() {} 344 public void ejbPassivate() {} 345 346 private CmpEntityLocalHome getCmpEntityHome(String entityJndiName) 348 throws NamingException 349 { 350 InitialContext ic = new InitialContext (); 351 CmpEntityLocalHome cmpEntityHome = (CmpEntityLocalHome) 352 ic.lookup(entityJndiName); 353 return cmpEntityHome; 354 } 355 } 356 | Popular Tags |