KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > beanexc > AccountEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: AccountEC2.java,v 1.3 2004/03/15 16:02:58 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.beanexc;
27
28 import javax.ejb.EntityBean JavaDoc;
29 import javax.ejb.EntityContext JavaDoc;
30 import javax.ejb.EJBContext JavaDoc;
31 import javax.ejb.RemoveException JavaDoc;
32 import javax.ejb.CreateException JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * This is an entity bean with "container managed persistence version 2".
39  * The state of an instance is stored into a relational database.
40  * @author Philippe Durieux, Philippe Coq, Helene Joanin
41  */

42 public abstract class AccountEC2 extends AccountCommon implements EntityBean JavaDoc {
43  
44     boolean forceToFailEjbStore;
45     protected EntityContext JavaDoc entityContext;
46
47
48     // Get and Set accessor methods of the bean's abstract schema
49
public abstract int getNumber();
50     public abstract void setNumber(int n);
51     public abstract long getBalance();
52     public abstract void setBalance(long d);
53     public abstract String JavaDoc getCustomer();
54     public abstract void setCustomer(String JavaDoc c);
55
56
57
58     public EJBContext JavaDoc getContext() {
59         return entityContext;
60     }
61
62     public void ejbActivate() {
63         logger.log(BasicLevel.DEBUG, "");
64     }
65
66     public void ejbPassivate() {
67         logger.log(BasicLevel.DEBUG, "");
68     }
69
70     public void ejbLoad() {
71         logger.log(BasicLevel.DEBUG, "");
72     }
73
74     public void ejbStore() {
75         logger.log(BasicLevel.DEBUG, "");
76         if (forceToFailEjbStore) {
77             forceToFailEjbStore = false;
78             throw new RuntimeException JavaDoc("RunTimeExceptionInEjbStore");
79         }
80     }
81   
82     /**
83      * This method is common for impl and expl bean
84      * it is used to test exception raised in ejbRemove()
85      * with unspecified transactional context (Required attribute).
86      * This method throws a RemoveException when the value of the PK is between 999990 and 999999
87      */

88     public void ejbRemove() throws RemoveException JavaDoc {
89         logger.log(BasicLevel.DEBUG, "");
90         AccountPK pk = (AccountPK) entityContext.getPrimaryKey();
91         if ((pk.number >= 999990) && (pk.number <= 999999)) {
92             logger.log(BasicLevel.DEBUG,
93                        "RemoveException throwned by bean provider in ejbRemove");
94             throw new RemoveException JavaDoc("RemoveException throwned by bean provider in ejbRemove");
95         }
96     }
97
98     public void setEntityContext(EntityContext JavaDoc ctx) {
99         if (logger == null) {
100             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
101         }
102         logger.log(BasicLevel.DEBUG, "");
103         entityContext = ctx;
104     }
105
106     public void unsetEntityContext() {
107         logger.log(BasicLevel.DEBUG, "");
108         entityContext = null;
109     }
110
111     public AccountPK ejbCreate(int val_number, String JavaDoc val_customer, long val_balance) throws CreateException JavaDoc {
112         logger.log(BasicLevel.DEBUG, "");
113         setNumber(val_number);
114         setCustomer(val_customer);
115         setBalance(val_balance);
116         return (null);
117     }
118
119     /**
120      * this method is common for impl and expl bean
121      * it is used to test exception raised in ejbCreate
122      * with unspecified transactional context (Required attribute)
123      * CAUTION: Do not call ejbCreate inside another ejbCreate (known bug)
124      */

125     public AccountPK ejbCreate(int flag) throws CreateException JavaDoc, AppException {
126         logger.log(BasicLevel.DEBUG, "");
127         setNumber(1951);
128         setCustomer("Myself");
129         setBalance(10000);
130         if (flag == 0) {
131             entityContext.setRollbackOnly();
132             throw new AppException("AppException in ejbCreate(boolean)");
133         } else {
134             int zero = 0;
135             float f = 10 / zero;
136         }
137         return (null);
138     }
139
140     /**
141      * this method is common for impl and expl bean
142      * NotSupported attr.
143      * CAUTION: Do not call ejbCreate inside another ejbCreate (known bug)
144      */

145     public AccountPK ejbCreate(boolean flag) throws CreateException JavaDoc, AppException {
146         logger.log(BasicLevel.DEBUG, "");
147         setNumber(1951);
148         setCustomer("Myself");
149         setBalance(10000);
150         if (flag) {
151             throw new AppException("AppException in ejbCreate(boolean)");
152         } else {
153             int zero = 0;
154             float f = 10 / zero;
155         }
156         return (null);
157     }
158
159     public void ejbPostCreate(int val_number, String JavaDoc val_customer, long val_balance) {
160         logger.log(BasicLevel.DEBUG, "");
161     }
162
163     public void ejbPostCreate(int flag) {
164         logger.log(BasicLevel.DEBUG, "");
165     }
166
167     public void ejbPostCreate(boolean flag) {
168         logger.log(BasicLevel.DEBUG, "");
169     }
170
171     public void doFailedEjbStore_1() {
172         logger.log(BasicLevel.DEBUG, "");
173         setBalance(1000);
174         forceToFailEjbStore = true;
175     }
176     public void doFailedEjbStore_2() {
177         logger.log(BasicLevel.DEBUG, "");
178         setBalance(2000);
179         forceToFailEjbStore = true;
180     }
181     public void doFailedEjbStore_3() {
182         logger.log(BasicLevel.DEBUG, "");
183         setBalance(3000);
184         forceToFailEjbStore = true;
185     }
186
187 }
188
189
Popular Tags