KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > stateful > EntityFacadeBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
29 import javax.ejb.PrePassivate JavaDoc;
30 import javax.ejb.Remote JavaDoc;
31 import javax.ejb.Remove JavaDoc;
32 import javax.ejb.Stateful JavaDoc;
33 import javax.ejb.TransactionAttribute JavaDoc;
34 import javax.ejb.TransactionAttributeType JavaDoc;
35 import javax.persistence.EntityManager;
36 import javax.persistence.PersistenceContext;
37 import javax.persistence.PersistenceContextType;
38
39
40 /**
41  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
42  */

43 @Stateful
44 @Remote JavaDoc(EntityFacade.class)
45 @CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
46 @TransactionAttribute JavaDoc(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 JavaDoc 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 JavaDoc id) {
63       log.info("********* loadEntity " + id);
64       Entity entity = manager.find(Entity.class, id);
65        return entity;
66    }
67    
68    @PrePassivate JavaDoc
69    public void passivate()
70    {
71       log.info("************ passivating");
72    }
73    
74    @PostActivate JavaDoc
75    public void activate()
76    {
77       log.info("************ activating");
78    }
79    
80    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
81    @Remove JavaDoc(retainIfException=true)
82    public void remove()
83    {
84       
85    }
86    
87    @Remove JavaDoc(retainIfException=true)
88    public void removeWithTx()
89    {
90       
91    }
92    
93    @PreDestroy
94    public void destroy()
95    {
96       log.info("************ destroying");
97       // throw RuntimeException
98
Object JavaDoc o = null;
99       o.getClass();
100    }
101 }
102
Popular Tags