1 22 package org.jboss.ejb3.test.stateful; 23 24 import org.jboss.annotation.ejb.cache.simple.CacheConfig; 25 import org.jboss.logging.Logger; 26 27 import javax.annotation.PreDestroy; 28 import javax.ejb.PostActivate ; 29 import javax.ejb.PrePassivate ; 30 import javax.ejb.Remote ; 31 import javax.ejb.Remove ; 32 import javax.ejb.Stateful ; 33 import javax.ejb.TransactionAttribute ; 34 import javax.ejb.TransactionAttributeType ; 35 import javax.persistence.EntityManager; 36 import javax.persistence.PersistenceContext; 37 import javax.persistence.PersistenceContextType; 38 39 40 43 @Stateful 44 @Remote (EntityFacade.class) 45 @CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1) 46 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 47 public class EntityFacadeBean implements EntityFacade 48 { 49 private @PersistenceContext(type = PersistenceContextType.EXTENDED) 50 EntityManager manager; 51 52 private static final Logger log = Logger.getLogger(EntityFacadeBean.class); 53 54 public Entity createEntity(String name) { 55 log.info("********* createEntity " + name); 56 Entity entity = new Entity(); 57 entity.setName(name); 58 manager.persist(entity); 59 return entity; 60 } 61 62 public Entity loadEntity(Long id) { 63 log.info("********* loadEntity " + id); 64 Entity entity = manager.find(Entity.class, id); 65 return entity; 66 } 67 68 @PrePassivate 69 public void passivate() 70 { 71 log.info("************ passivating"); 72 } 73 74 @PostActivate 75 public void activate() 76 { 77 log.info("************ activating"); 78 } 79 80 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 81 @Remove (retainIfException=true) 82 public void remove() 83 { 84 85 } 86 87 @Remove (retainIfException=true) 88 public void removeWithTx() 89 { 90 91 } 92 93 @PreDestroy 94 public void destroy() 95 { 96 log.info("************ destroying"); 97 Object o = null; 99 o.getClass(); 100 } 101 } 102 | Popular Tags |