1 25 package org.objectweb.easybeans.tests.common.ejbs.base.persistencectxlife; 26 27 import static org.testng.Assert.assertFalse; 28 import static org.testng.Assert.assertTrue; 29 30 import javax.ejb.TransactionAttribute ; 31 import javax.ejb.TransactionAttributeType ; 32 import javax.persistence.EntityManager; 33 34 import org.objectweb.easybeans.tests.common.ejbs.entity.ebstore.EBStore; 35 36 40 public class BasePCtxLifetimeCM00 implements ItfPCtxLifetime00 { 41 42 45 private EntityManager em; 46 47 50 private int id = this.hashCode(); 51 52 55 private EBStore eb; 56 57 61 public void initEntityManager(final EntityManager em) { 62 this.em = em; 63 } 64 65 69 public void setEntityID(final int id) { 70 this.id = id; 71 } 72 73 76 @SuppressWarnings ("boxing") 77 @TransactionAttribute (TransactionAttributeType.REQUIRED) 78 public void createCheckEntity00() { 79 eb = new EBStore(id); 80 em.persist(eb); 81 82 assertTrue(em.contains(eb), "The entity instance should be managed."); 83 84 EBStore ebFind = em.find(EBStore.class, id); 85 86 assertTrue(ebFind == eb, "The entity instances should be equals, " 87 + "they are in the same persistence context."); 88 } 89 90 93 @SuppressWarnings ("boxing") 94 @TransactionAttribute (TransactionAttributeType.NEVER) 95 public void createCheckEntity01() { 96 eb = new EBStore(id); 97 em.persist(eb); 98 99 assertFalse(em.contains(eb), "The entity instance should be detached."); 100 } 101 102 106 @SuppressWarnings ("boxing") 107 @TransactionAttribute (TransactionAttributeType.MANDATORY) 108 public boolean containsEntity() { 109 return em.contains(eb); 110 } 111 112 116 @SuppressWarnings ("boxing") 117 @TransactionAttribute (TransactionAttributeType.NEVER) 118 public boolean existsEntity() { 119 return em.find(EBStore.class, id) != null; 120 } 121 122 125 @SuppressWarnings ("boxing") 126 @TransactionAttribute (TransactionAttributeType.REQUIRED) 127 public void checkManaged() { 128 assertTrue(em.contains(eb), "The entity instance should be managed."); 129 130 EBStore ebFind = em.find(EBStore.class, id); 131 132 assertTrue(ebFind == eb, "The entity instances should be equals, " 133 + "they are in the same persistence context."); 134 } 135 136 139 @SuppressWarnings ("boxing") 140 @TransactionAttribute (TransactionAttributeType.REQUIRED) 141 public void checkDetached() { 142 assertFalse(em.contains(eb), "The entity instance should be detached."); 143 } 144 145 148 @SuppressWarnings ("boxing") 149 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 150 public void removeEntity() { 151 EBStore ebFind = em.find(EBStore.class, id); 152 if (ebFind != null) { 153 em.remove(ebFind); 154 } 155 } 156 157 160 public void initEntityManager() { 161 } 163 164 167 public void persistEntity() { 168 em.persist(eb); 169 } 170 } 171 | Popular Tags |