KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > regression > ejbthree440 > session > InheritanceDemo


1 package org.jboss.ejb3.test.regression.ejbthree440.session;
2
3 import java.util.Date JavaDoc;
4 import org.jboss.serial.io.MarshalledObject;
5 import java.io.IOException JavaDoc;
6
7 import javax.ejb.Remote JavaDoc;
8 import javax.ejb.Stateless JavaDoc;
9 import javax.persistence.EntityManager;
10 import javax.persistence.PersistenceContext;
11 import javax.persistence.Query;
12
13 import org.jboss.annotation.ejb.RemoteBinding;
14
15 import org.jboss.ejb3.test.regression.ejbthree440.model.MyResource;
16 import org.jboss.ejb3.test.regression.ejbthree440.model.Resource;
17 import org.jboss.ejb3.test.regression.ejbthree440.model.User;
18 import org.jboss.ejb3.test.regression.ejbthree440.session.i.IInheritanceDemo;
19
20 @Stateless JavaDoc
21 @RemoteBinding(jndiBinding="InheritanceDemo/remote")
22 @Remote JavaDoc(IInheritanceDemo.class)
23 public class InheritanceDemo implements IInheritanceDemo {
24   @PersistenceContext(unitName="mlog")
25   protected EntityManager em;
26
27   public void create() {
28     User u = new User();
29     u.setName("Test User");
30     u.setPassword("acuia.sckln");
31     u.setActive(false);
32     em.persist(u);
33     
34     MyResource r = new MyResource();
35     r.setUser(u);
36     r.setSkills("0");
37     r.setActive(false);
38     r.setDescription("Inheritance Demo Resource");
39     r.setMyField("hello world");
40     r.setCreated(new Date JavaDoc());
41     r.setUpdated(new Date JavaDoc());
42     em.persist(r);
43   }
44   
45   public Resource read() {
46     Query q = em.createQuery("SELECT u FROM Resource u WHERE u.description = :d");
47     q.setParameter("d", "Inheritance Demo Resource");
48     Resource r = (Resource) q.getSingleResult();
49     return r;
50   }
51
52    public MarshalledObject readFromMO()
53    {
54       try
55       {
56          return new MarshalledObject(read());
57       }
58       catch (IOException JavaDoc e)
59       {
60          throw new RuntimeException JavaDoc(e);
61       }
62    }
63   
64   public void remove() {
65     Resource r = read();
66     em.remove(r);
67   }
68 }
69
Popular Tags