1 25 package org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.flushoperation; 26 27 import static org.testng.Assert.assertEquals; 28 29 import javax.ejb.Remote ; 30 import javax.ejb.Stateful ; 31 import javax.ejb.TransactionAttribute ; 32 import javax.ejb.TransactionAttributeType ; 33 import javax.persistence.EntityManager; 34 import javax.persistence.FlushModeType; 35 import javax.persistence.PersistenceContext; 36 37 import org.objectweb.easybeans.tests.common.ejbs.entity.ebstore.EBStore; 38 39 45 @Stateful 46 @Remote (ItfEntityManagerFlushTester.class) 47 public class SFSBEntityManagerFlushTester implements ItfEntityManagerFlushTester { 48 49 52 @PersistenceContext 53 private EntityManager entityManager; 54 55 59 @TransactionAttribute (TransactionAttributeType.REQUIRED) 60 private void removeEntity() { 61 EBStore ebstore = entityManager.find(EBStore.class, ENTITY_ID); 62 if (ebstore != null) { 63 entityManager.remove(ebstore); 64 } 65 } 66 67 71 public void startup() { 72 removeEntity(); 73 EBStore ebstore = new EBStore(); 74 ebstore.setId(ENTITY_ID.intValue()); 75 ebstore.setName(ENTITY_NAME); 76 entityManager.persist(ebstore); 77 } 78 79 82 public void verifyDefaultFlushMode() { 83 assertEquals(entityManager.getFlushMode(), FlushModeType.AUTO, 84 "The flush mode is not beginning with the default value"); 85 } 86 87 90 @TransactionAttribute (TransactionAttributeType.REQUIRED) 91 public void setFlushModeAuto() { 92 entityManager.setFlushMode(FlushModeType.AUTO); 93 assertEquals(entityManager.getFlushMode(), FlushModeType.AUTO, 94 "The flush mode was not set."); 95 96 EBStore ebstoreBeforeChange = entityManager.find(EBStore.class, ENTITY_ID); 97 ebstoreBeforeChange.setName(ENTITY_NAME_2); 98 entityManager.createQuery("SELECT e FROM EBStore e"); 100 EBStore ebstoreAfterChange = entityManager.find(EBStore.class, ENTITY_ID); 102 assertEquals(ebstoreAfterChange.getName(), ENTITY_NAME_2, "The container did not make a flush after the query"); 103 } 104 105 110 @TransactionAttribute (TransactionAttributeType.REQUIRED) 111 public void setFlushModeCommit() { 112 entityManager.setFlushMode(FlushModeType.COMMIT); 113 assertEquals(entityManager.getFlushMode(), FlushModeType.COMMIT, 114 "The flush mode was not set."); 115 116 EBStore ebstoreBeforeChange = entityManager.find(EBStore.class, ENTITY_ID); 117 ebstoreBeforeChange.setName(ENTITY_NAME_2); 118 entityManager.createQuery("SELECT e FROM EBStore e"); 120 EBStore ebstoreAfterChange = entityManager.find(EBStore.class, ENTITY_ID); 122 assertEquals(ebstoreAfterChange.getName(), ENTITY_NAME, "The container made a flush after the query"); 123 } 124 125 } 126 | Popular Tags |