KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > banknew > ejb > TellerSessionBean


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.banknew.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 import org.jboss.test.banknew.interfaces.AccountData;
33 import org.jboss.test.banknew.interfaces.AccountSession;
34 import org.jboss.test.banknew.interfaces.AccountSessionHome;
35 import org.jboss.test.banknew.interfaces.BankException;
36 import org.jboss.test.banknew.interfaces.CustomerData;
37 import org.jboss.test.banknew.interfaces.CustomerSession;
38 import org.jboss.test.banknew.interfaces.CustomerSessionHome;
39 import org.jboss.test.util.ejb.SessionSupport;
40
41 /**
42  * The Session bean represents a bank.
43  *
44  * @author Andreas Schaefer
45  * @version $Revision: 41581 $
46  *
47  * @ejb:bean name="bank/TellerSession"
48  * display-name="Teller Session"
49  * type="Stateless"
50  * view-type="remote"
51  * jndi-name="ejb/bank/TellerSession"
52  *
53  * @ejb:interface extends="javax.ejb.EJBObject"
54  *
55  * @ejb:home extends="javax.ejb.EJBHome"
56  *
57  * @ejb:transaction type="Required"
58  *
59  * @ejb:ejb-ref ejb-name="bank/AccountSession"
60  *
61  * @ejb:ejb-ref ejb-name="bank/BankSession"
62  *
63  * @ejb:ejb-ref ejb-name="bank/CustomerSession"
64  */

65 public class TellerSessionBean
66    extends SessionSupport
67 {
68    /** The serialVersionUID */
69    private static final long serialVersionUID = -1977212418836289874L;
70
71    // Constants -----------------------------------------------------
72

73    // Attributes ----------------------------------------------------
74

75    // Static --------------------------------------------------------
76

77    // Constructors --------------------------------------------------
78

79    // Public --------------------------------------------------------
80

81    /**
82     * @ejb:interface-method view-type="remote"
83     **/

84    public void deposit( String JavaDoc pToAccountId, float pAmount )
85       throws BankException
86    {
87       try {
88          getAccountSession().deposit( pToAccountId, pAmount );
89       }
90       catch( Exception JavaDoc e ) {
91          sessionCtx.setRollbackOnly();
92          throw new BankException( "Could not deposit " + pAmount +
93             " to " + pToAccountId, e );
94       }
95    }
96    
97    /**
98     * @ejb:interface-method view-type="remote"
99     **/

100    public void transfer( String JavaDoc pFromAccountId, String JavaDoc pToAccountId, float pAmount )
101       throws BankException
102    {
103       try {
104          getAccountSession().transfer( pFromAccountId, pToAccountId, pAmount );
105       }
106       catch( Exception JavaDoc e ) {
107          sessionCtx.setRollbackOnly();
108          throw new BankException( "Could not transfer " + pAmount +
109             " from " + pFromAccountId + " to " + pToAccountId, e );
110       }
111    }
112    
113    /**
114     * @ejb:interface-method view-type="remote"
115     **/

116    public void withdraw( String JavaDoc pFromAccountId, float pAmount )
117       throws BankException
118    {
119       try {
120          getAccountSession().withdraw( pFromAccountId, pAmount );
121       }
122       catch( Exception JavaDoc e ) {
123          sessionCtx.setRollbackOnly();
124          throw new BankException( "Could not withdraw " + pAmount +
125             " from " + pFromAccountId, e );
126       }
127    }
128    
129    /**
130     * @ejb:interface-method view-type="remote"
131     **/

132    public AccountData createAccount( String JavaDoc pCustomerId, int pType, float pInitialDeposit )
133       throws BankException
134    {
135       try {
136          return getAccountSession().createAccount( pCustomerId, pType, pInitialDeposit );
137       }
138       catch( Exception JavaDoc e ) {
139          sessionCtx.setRollbackOnly();
140          e.printStackTrace();
141          throw new BankException( "Could not create account", e );
142       }
143    }
144    
145    /**
146     * @ejb:interface-method view-type="remote"
147     **/

148    public void removeAccount( String JavaDoc pAccountId )
149       throws BankException
150    {
151       try {
152          getAccountSession().removeAccount( pAccountId );
153       }
154       catch( Exception JavaDoc e ) {
155          sessionCtx.setRollbackOnly();
156          e.printStackTrace();
157          throw new BankException( "Could not remove account", e );
158       }
159    }
160    
161    /**
162     * @ejb:interface-method view-type="remote"
163     **/

164    public void removeAccount( String JavaDoc pCustomerId, int pType )
165       throws BankException
166    {
167       try {
168          getAccountSession().removeAccount( pCustomerId, pType );
169       }
170       catch( Exception JavaDoc e ) {
171          sessionCtx.setRollbackOnly();
172          e.printStackTrace();
173          throw new BankException( "Could not remove account", e );
174       }
175    }
176    
177    /**
178     * @ejb:interface-method view-type="remote"
179     **/

180    public Collection JavaDoc getAccounts( String JavaDoc pCustomerId )
181       throws BankException
182    {
183       try {
184          return getAccountSession().getAccounts( pCustomerId );
185       }
186       catch( Exception JavaDoc e ) {
187          sessionCtx.setRollbackOnly();
188          e.printStackTrace();
189          throw new BankException( "Could not remove account", e );
190       }
191    }
192    
193    /**
194     * @ejb:interface-method view-type="remote"
195     **/

196    public AccountData getAccount( String JavaDoc pCustomerId, int pType )
197       throws BankException
198    {
199       try {
200          return getAccountSession().getAccount( pCustomerId, pType );
201       }
202       catch( Exception JavaDoc e ) {
203          sessionCtx.setRollbackOnly();
204          e.printStackTrace();
205          throw new BankException( "Could not remove account", e );
206       }
207    }
208    
209    /**
210     * @ejb:interface-method view-type="remote"
211     **/

212    public AccountData getAccount( String JavaDoc pAccountId )
213       throws BankException
214    {
215       try {
216          return getAccountSession().getAccount( pAccountId );
217       }
218       catch( Exception JavaDoc e ) {
219          sessionCtx.setRollbackOnly();
220          e.printStackTrace();
221          throw new BankException( "Could not remove account", e );
222       }
223    }
224    
225    /**
226     * @ejb:interface-method view-type="remote"
227     **/

228    public CustomerData createCustomer( String JavaDoc pBankId, String JavaDoc pName, float pInitialDeposit )
229       throws BankException
230    {
231       try {
232          return getCustomerSession().createCustomer( pBankId, pName, pInitialDeposit );
233       }
234       catch( Exception JavaDoc e ) {
235          sessionCtx.setRollbackOnly();
236          e.printStackTrace();
237          throw new BankException( "Could not create account", e );
238       }
239    }
240    
241    /**
242     * @ejb:interface-method view-type="remote"
243     **/

244    public void removeCustomer( String JavaDoc pCustomerId )
245       throws BankException
246    {
247       try {
248          getCustomerSession().removeCustomer( pCustomerId );
249       }
250       catch( Exception JavaDoc e ) {
251          sessionCtx.setRollbackOnly();
252          e.printStackTrace();
253          throw new BankException( "Could not remove account", e );
254       }
255    }
256    
257    /**
258     * @ejb:interface-method view-type="remote"
259     **/

260    public CustomerData getCustomer( String JavaDoc pCustomerId )
261       throws BankException
262    {
263       try {
264          CustomerSession lSession = getCustomerSession();
265          return lSession.getCustomer( pCustomerId );
266       }
267       catch( Exception JavaDoc e ) {
268          e.printStackTrace();
269          throw new BankException( "Could not get customer for " + pCustomerId, e );
270       }
271    }
272    
273    /**
274     * @ejb:interface-method view-type="remote"
275     **/

276    public Collection JavaDoc getCustomers( String JavaDoc pBankId )
277       throws BankException
278    {
279       try {
280          return getCustomerSession().getCustomers( pBankId );
281       }
282       catch( Exception JavaDoc e ) {
283          e.printStackTrace();
284          throw new BankException( "Could not get customers for bank " + pBankId, e );
285       }
286    }
287    
288    private AccountSession getAccountSession()
289       throws RemoteException JavaDoc
290    {
291       try {
292          AccountSessionHome lHome = (AccountSessionHome) new InitialContext JavaDoc().lookup( AccountSessionHome.COMP_NAME );
293          return lHome.create();
294       }
295       catch( NamingException JavaDoc ne ) {
296          throw new EJBException JavaDoc( ne );
297       }
298       catch( CreateException JavaDoc ce ) {
299          throw new EJBException JavaDoc( ce );
300       }
301    }
302    
303    private CustomerSession getCustomerSession()
304       throws RemoteException JavaDoc
305    {
306       try {
307          CustomerSessionHome lHome = (CustomerSessionHome) new InitialContext JavaDoc().lookup( CustomerSessionHome.COMP_NAME );
308          return lHome.create();
309       }
310       catch( NamingException JavaDoc ne ) {
311          throw new EJBException JavaDoc( ne );
312       }
313       catch( CreateException JavaDoc ce ) {
314          throw new EJBException JavaDoc( ce );
315       }
316    }
317    
318 }
319 /*
320  * $Id: TellerSessionBean.java 41581 2006-03-01 16:10:00Z adrian $
321  * Currently locked by:$Locker$
322  * Revision:
323  * $Log$
324  * Revision 1.3 2006/03/01 16:09:58 adrian
325  * Remove xdoclet from jca tests
326  *
327  * Revision 1.1.16.1 2005/10/29 05:04:35 starksm
328  * Update the LGPL header
329  *
330  * Revision 1.1 2002/05/04 01:08:25 schaefera
331  * Added new Stats classes (JMS related) to JSR-77 implemenation and added the
332  * bank-new test application but this does not work right now properly but
333  * it is not added to the default tests so I shouldn't bother someone.
334  *
335  * Revision 1.1.2.2 2002/04/29 21:05:17 schaefera
336  * Added new marathon test suite using the new bank application
337  *
338  * Revision 1.1.2.1 2002/04/17 05:07:24 schaefera
339  * Redesigned the banknew example therefore to a create separation between
340  * the Entity Bean (CMP) and the Session Beans (Business Logic).
341  * The test cases are redesigned but not finished yet.
342  *
343  * Revision 1.1.2.2 2002/04/15 04:28:15 schaefera
344  * Minor fixes regarding to the JNDI names of the beans.
345  *
346  * Revision 1.1.2.1 2002/04/15 02:32:24 schaefera
347  * Add a new test version of the bank because the old did no use transactions
348  * and the new uses XDoclet 1.1.2 to generate the DDs and other Java classes.
349  * Also a marathon test is added. Please specify the jbosstest.duration for
350  * how long and the test.timeout (which must be longer than the duration) to
351  * run the test with run_tests.xml, tag marathon-test-and-report.
352  *
353  * Revision 1.3 2001/01/07 23:14:34 peter
354  * Trying to get JAAS to work within test suite.
355  *
356  * Revision 1.2 2000/09/30 01:00:55 fleury
357  * Updated bank tests to work with new jBoss version
358  *
359  * Revision 1.1.1.1 2000/06/21 15:52:37 oberg
360  * Initial import of jBoss test. This module contains CTS tests, some simple examples, and small bean suites.
361  */

362
Popular Tags