KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > regression > ejbthree290 > DAOBean


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.regression.ejbthree290;
23
24 import javax.ejb.Stateless JavaDoc;
25 import javax.persistence.PersistenceContext;
26 import javax.persistence.EntityManager;
27 import javax.persistence.EntityNotFoundException;
28 import javax.ejb.Remote JavaDoc;
29 import javax.ejb.EJB JavaDoc;
30
31 /**
32  * Comment
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 45473 $
36  */

37 @Stateless JavaDoc
38 @Remote JavaDoc(DAO.class)
39 public class DAOBean implements DAO
40 {
41    @PersistenceContext EntityManager manager;
42    @EJB JavaDoc DeleteLocal local;
43
44    public MyEntity create()
45    {
46       MyEntity e = new MyEntity();
47       e.name = "Bill";
48       manager.persist(e);
49       return e;
50    }
51
52    public void findAndDelete(int id) throws Exception JavaDoc
53    {
54       MyEntity e = manager.find(MyEntity.class, id);
55       local.removeEntity(e.id);
56       try
57       {
58          manager.refresh(e);
59       }
60       catch (EntityNotFoundException e1)
61       {
62          return; // correct
63
}
64       throw new RuntimeException JavaDoc("Expected EntityNotFoundException");
65    }
66
67    public void merge(MyEntity e) throws Exception JavaDoc
68    {
69       //local.removeEntity(e.id);
70
//the spec says IllegalArgumentException if the entity is removed (ie a scheduled for remove as per the spec)
71
MyEntity managedEntity = manager.find(MyEntity.class, e.id);
72       managedEntity.name="Joe";
73       manager.remove(managedEntity);
74       try
75       {
76          manager.merge(managedEntity);
77       }
78       catch (IllegalArgumentException JavaDoc e1)
79       {
80          return;
81       }
82       throw new RuntimeException JavaDoc("expected IllegalArgumentException");
83    }
84
85    public void mergeAfterRemove(MyEntity e) throws Exception JavaDoc
86    {
87       e = manager.merge(e);
88       manager.remove(e);
89       try
90       {
91          manager.merge(e);
92       }
93       catch (IllegalArgumentException JavaDoc e1)
94       {
95          return;
96       }
97       throw new RuntimeException JavaDoc("expected IllegalArgumentException");
98    }
99
100 }
101
Popular Tags