001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.banknew.ejb;
023:
024: import java.rmi.RemoteException;
025: import java.util.ArrayList;
026: import java.util.Collection;
027: import java.util.Iterator;
028:
029: import javax.ejb.CreateException;
030: import javax.ejb.EJBException;
031: import javax.ejb.FinderException;
032: import javax.ejb.RemoveException;
033: import javax.ejb.SessionContext;
034: import javax.naming.InitialContext;
035: import javax.naming.NamingException;
036:
037: import org.jboss.test.banknew.interfaces.AccountData;
038: import org.jboss.test.banknew.interfaces.AccountSessionHome;
039: import org.jboss.test.banknew.interfaces.Constants;
040: import org.jboss.test.banknew.interfaces.Customer;
041: import org.jboss.test.banknew.interfaces.CustomerData;
042: import org.jboss.test.banknew.interfaces.CustomerHome;
043: import org.jboss.test.banknew.interfaces.CustomerPK;
044: import org.jboss.test.util.ejb.SessionSupport;
045:
046: /**
047: * The Session bean represents the customer's business interface
048: *
049: * @author Andreas Schaefer
050: * @version $Revision: 57211 $
051: *
052: * @ejb:bean name="bank/CustomerSession"
053: * display-name="Customer Session"
054: * type="Stateless"
055: * view-type="remote"
056: * jndi-name="ejb/bank/CustomerSession"
057: *
058: * @ejb:interface extends="javax.ejb.EJBObject"
059: *
060: * @ejb:home extends="javax.ejb.EJBHome"
061: *
062: * @ejb:pk extends="java.lang.Object"
063: *
064: * @ejb:transaction type="Required"
065: *
066: * @ejb:ejb-ref ejb-name="bank/AccountSession"
067: *
068: * @ejb:ejb-ref ejb-name="bank/Customer"
069: */
070: public class CustomerSessionBean extends SessionSupport {
071:
072: /** The serialVersionUID */
073: private static final long serialVersionUID = 5798218546370782410L;
074:
075: // Constants -----------------------------------------------------
076:
077: // Attributes ----------------------------------------------------
078:
079: // Static --------------------------------------------------------
080:
081: // Constructors --------------------------------------------------
082:
083: // Public --------------------------------------------------------
084:
085: /**
086: * @ejb:interface-method view-type="remote"
087: **/
088: public CustomerData createCustomer(String pBankId, String pName,
089: float pInitialDeposit) throws CreateException,
090: RemoteException {
091: Customer lCustomer = getCustomerHome().create(pBankId, pName);
092: CustomerData lNew = lCustomer.getData();
093: getAccountHome().create().createAccount(lNew.getId(),
094: Constants.CHECKING, pInitialDeposit);
095: return lNew;
096: }
097:
098: /**
099: * @ejb:interface-method view-type="remote"
100: **/
101: public void removeCustomer(String pCustomerId)
102: throws RemoveException, RemoteException {
103: try {
104: getCustomerHome().findByPrimaryKey(
105: new CustomerPK(pCustomerId)).remove();
106: } catch (FinderException fe) {
107: // When not found then ignore it because customer is already removed
108: }
109: }
110:
111: /**
112: * @ejb:interface-method view-type="remote"
113: **/
114: public CustomerData getCustomer(String pCustomerId)
115: throws FinderException, RemoteException {
116: Customer lCustomer = getCustomerHome().findByPrimaryKey(
117: new CustomerPK(pCustomerId));
118: return lCustomer.getData();
119: }
120:
121: /**
122: * @ejb:interface-method view-type="remote"
123: **/
124: public Collection getCustomers(String pBankId)
125: throws FinderException, RemoteException {
126: Collection lCustomers = getCustomerHome().findByBank(pBankId);
127: Collection lList = new ArrayList(lCustomers.size());
128: Iterator i = lCustomers.iterator();
129: while (i.hasNext()) {
130: lList.add(((Customer) i.next()).getData());
131: }
132: return lList;
133: }
134:
135: /**
136: * @ejb:interface-method view-type="remote"
137: **/
138: public Collection getAccounts(String pCustomerId)
139: throws FinderException, RemoteException {
140: try {
141: return getAccountHome().create().getAccounts(pCustomerId);
142: } catch (CreateException ce) {
143: throw new EJBException(ce);
144: }
145: }
146:
147: /**
148: * @ejb:interface-method view-type="remote"
149: **/
150: public AccountData createAccount(String pCustomerId, int pType,
151: float pInitialDeposit) throws CreateException,
152: RemoteException {
153: return getAccountHome().create().createAccount(pCustomerId,
154: pType, pInitialDeposit);
155: }
156:
157: /**
158: * @ejb:interface-method view-type="remote"
159: **/
160: public void removeAccount(String pCustomerId, int pType)
161: throws RemoveException, RemoteException {
162: try {
163: getAccountHome().create().removeAccount(pCustomerId, pType);
164: } catch (CreateException ce) {
165: // When not found then ignore it because account is already removed
166: }
167: }
168:
169: private AccountSessionHome getAccountHome() {
170: try {
171: return (AccountSessionHome) new InitialContext()
172: .lookup(AccountSessionHome.COMP_NAME);
173: } catch (NamingException ne) {
174: throw new EJBException(ne);
175: }
176: }
177:
178: private CustomerHome getCustomerHome() {
179: try {
180: return (CustomerHome) new InitialContext()
181: .lookup(CustomerHome.COMP_NAME);
182: } catch (NamingException ne) {
183: throw new EJBException(ne);
184: }
185: }
186:
187: // SessionBean implementation ------------------------------------
188: public void setSessionContext(SessionContext context) {
189: super .setSessionContext(context);
190: }
191: }
192:
193: /*
194: * $Id: CustomerSessionBean.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
195: * Currently locked by:$Locker$
196: * Revision:
197: * $Log$
198: * Revision 1.1.16.2 2006/03/01 15:58:56 adrian
199: * Remove xdoclet from the jca tests + other tidyup
200: *
201: * Revision 1.1.16.1 2005/10/29 05:04:35 starksm
202: * Update the LGPL header
203: *
204: * Revision 1.1 2002/05/04 01:08:25 schaefera
205: * Added new Stats classes (JMS related) to JSR-77 implemenation and added the
206: * bank-new test application but this does not work right now properly but
207: * it is not added to the default tests so I shouldn't bother someone.
208: *
209: * Revision 1.1.2.2 2002/04/29 21:05:17 schaefera
210: * Added new marathon test suite using the new bank application
211: *
212: * Revision 1.1.2.1 2002/04/17 05:07:24 schaefera
213: * Redesigned the banknew example therefore to a create separation between
214: * the Entity Bean (CMP) and the Session Beans (Business Logic).
215: * The test cases are redesigned but not finished yet.
216: *
217: * Revision 1.1.2.2 2002/04/15 04:28:15 schaefera
218: * Minor fixes regarding to the JNDI names of the beans.
219: *
220: * Revision 1.1.2.1 2002/04/15 02:32:24 schaefera
221: * Add a new test version of the bank because the old did no use transactions
222: * and the new uses XDoclet 1.1.2 to generate the DDs and other Java classes.
223: * Also a marathon test is added. Please specify the jbosstest.duration for
224: * how long and the test.timeout (which must be longer than the duration) to
225: * run the test with run_tests.xml, tag marathon-test-and-report.
226: *
227: * Revision 1.2 2001/01/07 23:14:34 peter
228: * Trying to get JAAS to work within test suite.
229: *
230: * Revision 1.1.1.1 2000/06/21 15:52:37 oberg
231: * Initial import of jBoss test. This module contains CTS tests, some simple examples, and small bean suites.
232: *
233: *
234: *
235: */
|