KickJava   Java API By Example, From Geeks To Geeks.

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


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.AccountData;
38 import org.jboss.test.banknew.interfaces.AccountSessionHome;
39 import org.jboss.test.banknew.interfaces.Constants;
40 import org.jboss.test.banknew.interfaces.Customer;
41 import org.jboss.test.banknew.interfaces.CustomerData;
42 import org.jboss.test.banknew.interfaces.CustomerHome;
43 import org.jboss.test.banknew.interfaces.CustomerPK;
44 import org.jboss.test.util.ejb.SessionSupport;
45
46 /**
47  * The Session bean represents the customer's business interface
48  *
49  * @author Andreas Schaefer
50  * @version $Revision: 41581 $
51  *
52  * @ejb:bean name="bank/CustomerSession"
53  * display-name="Customer Session"
54  * type="Stateless"
55  * view-type="remote"
56  * jndi-name="ejb/bank/CustomerSession"
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/AccountSession"
67  *
68  * @ejb:ejb-ref ejb-name="bank/Customer"
69  */

70 public class CustomerSessionBean
71    extends SessionSupport
72 {
73    
74    /** The serialVersionUID */
75    private static final long serialVersionUID = 5798218546370782410L;
76
77    // Constants -----------------------------------------------------
78

79    // Attributes ----------------------------------------------------
80

81    // Static --------------------------------------------------------
82

83    // Constructors --------------------------------------------------
84

85    // Public --------------------------------------------------------
86

87    /**
88     * @ejb:interface-method view-type="remote"
89     **/

90    public CustomerData createCustomer( String JavaDoc pBankId, String JavaDoc pName, float pInitialDeposit )
91       throws CreateException JavaDoc, RemoteException JavaDoc
92    {
93       Customer lCustomer = getCustomerHome().create(
94          pBankId,
95          pName
96       );
97       CustomerData lNew = lCustomer.getData();
98       getAccountHome().create().createAccount(
99          lNew.getId(),
100          Constants.CHECKING,
101          pInitialDeposit
102       );
103       return lNew;
104    }
105    
106    /**
107     * @ejb:interface-method view-type="remote"
108     **/

109    public void removeCustomer( String JavaDoc pCustomerId )
110       throws RemoveException JavaDoc, RemoteException JavaDoc
111    {
112       try {
113          getCustomerHome().findByPrimaryKey(
114             new CustomerPK( pCustomerId )
115          ).remove();
116       }
117       catch( FinderException JavaDoc fe ) {
118          // When not found then ignore it because customer is already removed
119
}
120    }
121    
122    /**
123     * @ejb:interface-method view-type="remote"
124     **/

125    public CustomerData getCustomer( String JavaDoc pCustomerId )
126       throws FinderException JavaDoc, RemoteException JavaDoc
127    {
128       Customer lCustomer = getCustomerHome().findByPrimaryKey(
129          new CustomerPK( pCustomerId )
130       );
131       return lCustomer.getData();
132    }
133    
134    /**
135     * @ejb:interface-method view-type="remote"
136     **/

137    public Collection JavaDoc getCustomers( String JavaDoc pBankId )
138       throws FinderException JavaDoc, RemoteException JavaDoc
139    {
140       Collection JavaDoc lCustomers = getCustomerHome().findByBank(
141          pBankId
142       );
143       Collection JavaDoc lList = new ArrayList JavaDoc( lCustomers.size() );
144       Iterator JavaDoc i = lCustomers.iterator();
145       while( i.hasNext() ) {
146          lList.add( ( (Customer) i.next() ).getData() );
147       }
148       return lList;
149    }
150    
151    /**
152     * @ejb:interface-method view-type="remote"
153     **/

154    public Collection JavaDoc getAccounts( String JavaDoc pCustomerId )
155       throws FinderException JavaDoc, RemoteException JavaDoc
156    {
157       try {
158          return getAccountHome().create().getAccounts( pCustomerId );
159       }
160       catch( CreateException JavaDoc ce ) {
161          throw new EJBException JavaDoc( ce );
162       }
163    }
164    
165    /**
166     * @ejb:interface-method view-type="remote"
167     **/

168    public AccountData createAccount( String JavaDoc pCustomerId, int pType, float pInitialDeposit )
169       throws CreateException JavaDoc, RemoteException JavaDoc
170    {
171       return getAccountHome().create().createAccount(
172          pCustomerId,
173          pType,
174          pInitialDeposit
175       );
176    }
177    
178    /**
179     * @ejb:interface-method view-type="remote"
180     **/

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

260
Popular Tags