KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > exception > EntityExceptionTesterBean


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.test.exception;
23
24 import java.rmi.RemoteException JavaDoc;
25 import javax.ejb.CreateException JavaDoc;
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.EntityBean JavaDoc;
28 import javax.ejb.EntityContext JavaDoc;
29 import javax.ejb.FinderException JavaDoc;
30
31 /**
32  * A test of entity beans exceptions.
33  *
34  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
35  * @version $Revision: 37406 $
36  */

37 public class EntityExceptionTesterBean
38    implements EntityBean JavaDoc
39 {
40     private EntityContext JavaDoc ctx;
41
42     String JavaDoc key;
43
44     public String JavaDoc ejbCreate(String JavaDoc key)
45        throws CreateException JavaDoc
46     {
47        this.key = key;
48        return key;
49     }
50
51     public void ejbPostCreate(String JavaDoc key)
52        throws CreateException JavaDoc
53     {
54     }
55
56     public String JavaDoc ejbFindByPrimaryKey(String JavaDoc key)
57        throws FinderException JavaDoc
58     {
59        throw new FinderException JavaDoc("Error, bean instance was discarded!");
60     }
61
62     public String JavaDoc getKey()
63     {
64        return key;
65     }
66
67     public void applicationExceptionInTx()
68        throws ApplicationException
69     {
70        throw new ApplicationException("Application exception from within " +
71                                       "an inherited transaction");
72     }
73
74     public void applicationExceptionInTxMarkRollback()
75        throws ApplicationException
76     {
77        ctx.setRollbackOnly();
78        throw new ApplicationException("Application exception from within " +
79                                       "an inherited transaction");
80     }
81
82     public void applicationErrorInTx()
83     {
84        throw new ApplicationError("Application error from within " +
85                                   "an inherited transaction");
86     }
87
88     public void ejbExceptionInTx()
89     {
90        throw new EJBException JavaDoc("EJB exception from within " +
91                               "an inherited transaction");
92     }
93
94     public void runtimeExceptionInTx()
95     {
96        throw new RuntimeException JavaDoc("Runtime exception from within " +
97                                   "an inherited transaction");
98     }
99
100     public void remoteExceptionInTx()
101        throws RemoteException JavaDoc
102     {
103        throw new RemoteException JavaDoc("Remote exception from within " +
104                                  "an inherited transaction");
105     }
106
107     public void applicationExceptionNewTx()
108        throws ApplicationException
109     {
110        throw new ApplicationException("Application exception from within " +
111                                       "a new container transaction");
112     }
113
114     public void applicationExceptionNewTxMarkRollback()
115        throws ApplicationException
116     {
117        ctx.setRollbackOnly();
118        throw new ApplicationException("Application exception from within " +
119                                       "a new container transaction");
120     }
121
122     public void applicationErrorNewTx()
123     {
124        throw new ApplicationError("Application error from within " +
125                                   "a new container transaction");
126     }
127
128     public void ejbExceptionNewTx()
129     {
130        throw new EJBException JavaDoc("EJB exception from within " +
131                               "a new container transaction");
132     }
133
134     public void runtimeExceptionNewTx()
135     {
136        throw new RuntimeException JavaDoc("Runtime exception from within " +
137                                   "a new container transaction");
138     }
139
140     public void remoteExceptionNewTx()
141        throws RemoteException JavaDoc
142     {
143        throw new RemoteException JavaDoc("Remote exception from within " +
144                                  "a new container transaction");
145     }
146
147     public void applicationExceptionNoTx()
148        throws ApplicationException
149     {
150        throw new ApplicationException("Application exception without " +
151                                       "a transaction");
152     }
153
154     public void applicationErrorNoTx()
155     {
156        throw new ApplicationError("Application error from within " +
157                                   " an inherited transaction");
158     }
159
160     public void ejbExceptionNoTx()
161     {
162        throw new EJBException JavaDoc("EJB exception without " +
163                               "a transaction");
164     }
165
166     public void runtimeExceptionNoTx()
167     {
168        throw new RuntimeException JavaDoc("Runtime exception without " +
169                                   "a transaction");
170     }
171
172     public void remoteExceptionNoTx()
173        throws RemoteException JavaDoc
174     {
175        throw new RemoteException JavaDoc("Remote exception without " +
176                                  "a transaction");
177     }
178
179     public void setEntityContext(EntityContext JavaDoc ctx)
180     {
181        this.ctx = ctx;
182     }
183
184     public void unsetEntityContext()
185     {
186     }
187
188     public void ejbLoad()
189     {
190     }
191
192     public void ejbStore()
193     {
194     }
195
196     public void ejbActivate()
197     {
198     }
199
200     public void ejbPassivate()
201     {
202     }
203
204     public void ejbRemove()
205     {
206     }
207 }
Popular Tags