KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import javax.ejb.CreateException JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.FinderException JavaDoc;
32 import javax.ejb.RemoveException JavaDoc;
33 import javax.ejb.SessionContext JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36
37 import org.jboss.test.banknew.interfaces.Bank;
38 import org.jboss.test.banknew.interfaces.BankData;
39 import org.jboss.test.banknew.interfaces.BankHome;
40 import org.jboss.test.banknew.interfaces.BankPK;
41 import org.jboss.test.banknew.interfaces.CustomerData;
42 import org.jboss.test.banknew.interfaces.CustomerSession;
43 import org.jboss.test.banknew.interfaces.CustomerSessionHome;
44 import org.jboss.test.util.ejb.SessionSupport;
45
46 /**
47  * The Session bean represents a bank's business interface.
48  *
49  * @author Andreas Schaefer
50  * @version $Revision: 41581 $
51  *
52  * @ejb:bean name="bank/BankSession"
53  * display-name="Bank Session"
54  * type="Stateless"
55  * view-type="remote"
56  * jndi-name="ejb/bank/BankSession"
57  *
58  * @ejb:interface extends="javax.ejb.EJBObject"
59  *
60  * @ejb:home extends="javax.ejb.EJBHome"
61  *
62  * @ejb:pk extends="java.lang.Object"
63  *
64  * @ejb:transaction type="Required"
65  *
66  * @ejb:ejb-ref ejb-name="bank/Bank"
67  *
68  * @ejb:ejb-ref ejb-name="bank/CustomerSession"
69  */

70 public class BankSessionBean
71    extends SessionSupport
72 {
73    
74    // Constants -----------------------------------------------------
75

76    // Attributes ----------------------------------------------------
77

78    // Static --------------------------------------------------------
79

80    // Constructors --------------------------------------------------
81

82    // Public --------------------------------------------------------
83

84    /** The serialVersionUID */
85    private static final long serialVersionUID = -4732008507323917820L;
86
87    /**
88     * @ejb:interface-method view-type="remote"
89     **/

90    public BankData createBank( String JavaDoc pName, String JavaDoc pAddress )
91       throws CreateException JavaDoc, RemoteException JavaDoc
92    {
93       Bank lBank = getBankHome().create( pName, pAddress );
94       return lBank.getData();
95    }
96    
97    /**
98     * @ejb:interface-method view-type="remote"
99     **/

100    public void removeBank( String JavaDoc pBankId )
101       throws RemoveException JavaDoc, RemoteException JavaDoc
102    {
103       try {
104          getBankHome().findByPrimaryKey(
105             new BankPK( pBankId )
106          ).remove();
107       }
108       catch( FinderException JavaDoc fe ) {
109       }
110    }
111    
112    /**
113     * @ejb:interface-method view-type="remote"
114     **/

115    public Collection JavaDoc getBanks()
116       throws FinderException JavaDoc, RemoteException JavaDoc
117    {
118       Collection JavaDoc lBanks = getBankHome().findAll();
119       Collection JavaDoc lList = new ArrayList JavaDoc( lBanks.size() );
120       Iterator JavaDoc i = lBanks.iterator();
121       while( i.hasNext() ) {
122          lList.add( ( (Bank) i.next() ).getData() );
123       }
124       return lList;
125    }
126    
127    /**
128     * @ejb:interface-method view-type="remote"
129     **/

130    public CustomerData getCustomer( String JavaDoc pCustomerId )
131       throws FinderException JavaDoc, RemoteException JavaDoc
132    {
133       return getCustomerSession().getCustomer( pCustomerId );
134    }
135    
136    /**
137     * @ejb:interface-method view-type="remote"
138     **/

139    public Collection JavaDoc getCustomers( String JavaDoc pBankId )
140       throws FinderException JavaDoc, RemoteException JavaDoc
141    {
142       return getCustomerSession().getCustomers( pBankId );
143    }
144    
145    /**
146     * @ejb:interface-method view-type="remote"
147     **/

148    public CustomerData createCustomer( String JavaDoc pBankId, String JavaDoc pName, float pInitialDeposit )
149       throws CreateException JavaDoc, RemoteException JavaDoc
150    {
151       return getCustomerSession().createCustomer(
152          pBankId,
153          pName,
154          pInitialDeposit
155       );
156    }
157    
158    /**
159     * @ejb:interface-method view-type="remote"
160     **/

161    public void removeCustomer( String JavaDoc pCustomerId )
162       throws RemoveException JavaDoc, RemoteException JavaDoc
163    {
164       getCustomerSession().removeCustomer(
165          pCustomerId
166       );
167    }
168    
169    private BankHome getBankHome() {
170       try {
171          return (BankHome) new InitialContext JavaDoc().lookup( BankHome.COMP_NAME );
172       }
173       catch( NamingException JavaDoc ne ) {
174          throw new EJBException JavaDoc( ne );
175       }
176    }
177    
178    private CustomerSession getCustomerSession()
179       throws RemoteException JavaDoc
180    {
181       try {
182          return ( (CustomerSessionHome) new InitialContext JavaDoc().lookup( CustomerSessionHome.COMP_NAME ) ).create();
183       }
184       catch( NamingException JavaDoc ne ) {
185          throw new EJBException JavaDoc( ne );
186       }
187       catch( CreateException JavaDoc ce ) {
188          throw new EJBException JavaDoc( ce );
189       }
190    }
191    
192    // SessionBean implementation ------------------------------------
193
public void setSessionContext(SessionContext JavaDoc context)
194    {
195       super.setSessionContext(context);
196    }
197 }
198
199 /*
200  * $Id: BankSessionBean.java 41581 2006-03-01 16:10:00Z adrian $
201  * Currently locked by:$Locker$
202  * Revision:
203  * $Log$
204  * Revision 1.3 2006/03/01 16:09:58 adrian
205  * Remove xdoclet from jca tests
206  *
207  * Revision 1.1.16.1 2005/10/29 05:04:35 starksm
208  * Update the LGPL header
209  *
210  * Revision 1.1 2002/05/04 01:08:25 schaefera
211  * Added new Stats classes (JMS related) to JSR-77 implemenation and added the
212  * bank-new test application but this does not work right now properly but
213  * it is not added to the default tests so I shouldn't bother someone.
214  *
215  * Revision 1.1.2.2 2002/04/29 21:05:17 schaefera
216  * Added new marathon test suite using the new bank application
217  *
218  * Revision 1.1.2.1 2002/04/17 05:07:24 schaefera
219  * Redesigned the banknew example therefore to a create separation between
220  * the Entity Bean (CMP) and the Session Beans (Business Logic).
221  * The test cases are redesigned but not finished yet.
222  *
223  * Revision 1.1.2.2 2002/04/15 04:28:15 schaefera
224  * Minor fixes regarding to the JNDI names of the beans.
225  *
226  * Revision 1.1.2.1 2002/04/15 02:32:24 schaefera
227  * Add a new test version of the bank because the old did no use transactions
228  * and the new uses XDoclet 1.1.2 to generate the DDs and other Java classes.
229  * Also a marathon test is added. Please specify the jbosstest.duration for
230  * how long and the test.timeout (which must be longer than the duration) to
231  * run the test with run_tests.xml, tag marathon-test-and-report.
232  *
233  * Revision 1.2 2001/01/07 23:14:34 peter
234  * Trying to get JAAS to work within test suite.
235  *
236  * Revision 1.1.1.1 2000/06/21 15:52:37 oberg
237  * Initial import of jBoss test. This module contains CTS tests, some simple examples, and small bean suites.
238  *
239  *
240  *
241  */

242
Popular Tags