KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > txexceptions > 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.txexceptions;
23
24 import javax.ejb.Remote JavaDoc;
25 import javax.ejb.Stateless JavaDoc;
26 import javax.ejb.TransactionAttributeType JavaDoc;
27 import javax.ejb.TransactionAttribute JavaDoc;
28 import javax.persistence.EntityManager;
29 import javax.persistence.PersistenceContext;
30
31 import org.jboss.logging.Logger;
32
33 /**
34  * Comment
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  * @version $Revision: 44777 $
38  */

39 @Stateless JavaDoc
40 @Remote JavaDoc(Dao.class)
41 public class DaoBean implements Dao
42 {
43    private static final Logger log = Logger
44    .getLogger(DaoBean.class);
45    
46    @PersistenceContext EntityManager manager;
47
48    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
49    public void testRequiresNewWithLookedUpEntityManager() throws Exception JavaDoc
50    {
51       RequiresNewTest.doit();
52    }
53
54    public SimpleEntity get(int id)
55    {
56       SimpleEntity en = manager.find(SimpleEntity.class, id);
57       return en;
58    }
59
60    public void remove(int id)
61    {
62       SimpleEntity en = manager.find(SimpleEntity.class, id);
63       manager.remove(en);
64    }
65
66    public void createThrowAnnotatedAppException(int id) throws AnnotatedAppException
67    {
68       persist(id);
69       throw new AnnotatedAppException();
70    }
71    
72    public void createThrowDeploymentDescriptorAppException(int id) throws DeploymentDescriptorAppException
73    {
74       persist(id);
75       throw new DeploymentDescriptorAppException();
76    }
77
78    private void persist(int id)
79    {
80       SimpleEntity entity = new SimpleEntity();
81       entity.setId(id);
82       entity.setStuff("stuff");
83       manager.persist(entity);
84    }
85
86    public void createThrowAppException(int id) throws AppException
87    {
88       persist(id);
89       throw new AppException();
90    }
91
92    public void createThrowCheckedRollbackException(int id) throws CheckedRollbackException
93    {
94       persist(id);
95       throw new CheckedRollbackException();
96    }
97    
98    public void createThrowDeploymentDescriptorCheckedRollbackException(int id) throws DeploymentDescriptorCheckedRollbackException
99    {
100       persist(id);
101       throw new DeploymentDescriptorCheckedRollbackException();
102    }
103
104    public void createThrowNoRollbackRemoteException(int id) throws NoRollbackRemoteException
105    {
106       persist(id);
107       throw new NoRollbackRemoteException();
108    }
109
110    public void createThrowNoRollbackRuntimeException(int id) throws NoRollbackRuntimeException
111    {
112       persist(id);
113       throw new NoRollbackRuntimeException();
114    }
115
116    public void createThrowRollbackRemoteException(int id) throws RollbackRemoteException
117    {
118       persist(id);
119       throw new RollbackRemoteException();
120    }
121
122    public void createThrowRollbackRuntimeException(int id) throws RollbackRuntimeException
123    {
124       persist(id);
125       throw new RollbackRuntimeException();
126    }
127 }
128
Popular Tags