1 22 package org.jboss.test.banknew.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import javax.ejb.CreateException ; 30 import javax.ejb.EJBException ; 31 import javax.ejb.FinderException ; 32 import javax.ejb.RemoveException ; 33 import javax.ejb.SessionContext ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 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 70 public class CustomerSessionBean 71 extends SessionSupport 72 { 73 74 75 private static final long serialVersionUID = 5798218546370782410L; 76 77 79 81 83 85 87 90 public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit ) 91 throws CreateException , RemoteException 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 109 public void removeCustomer( String pCustomerId ) 110 throws RemoveException , RemoteException 111 { 112 try { 113 getCustomerHome().findByPrimaryKey( 114 new CustomerPK( pCustomerId ) 115 ).remove(); 116 } 117 catch( FinderException fe ) { 118 } 120 } 121 122 125 public CustomerData getCustomer( String pCustomerId ) 126 throws FinderException , RemoteException 127 { 128 Customer lCustomer = getCustomerHome().findByPrimaryKey( 129 new CustomerPK( pCustomerId ) 130 ); 131 return lCustomer.getData(); 132 } 133 134 137 public Collection getCustomers( String pBankId ) 138 throws FinderException , RemoteException 139 { 140 Collection lCustomers = getCustomerHome().findByBank( 141 pBankId 142 ); 143 Collection lList = new ArrayList ( lCustomers.size() ); 144 Iterator i = lCustomers.iterator(); 145 while( i.hasNext() ) { 146 lList.add( ( (Customer) i.next() ).getData() ); 147 } 148 return lList; 149 } 150 151 154 public Collection getAccounts( String pCustomerId ) 155 throws FinderException , RemoteException 156 { 157 try { 158 return getAccountHome().create().getAccounts( pCustomerId ); 159 } 160 catch( CreateException ce ) { 161 throw new EJBException ( ce ); 162 } 163 } 164 165 168 public AccountData createAccount( String pCustomerId, int pType, float pInitialDeposit ) 169 throws CreateException , RemoteException 170 { 171 return getAccountHome().create().createAccount( 172 pCustomerId, 173 pType, 174 pInitialDeposit 175 ); 176 } 177 178 181 public void removeAccount( String pCustomerId, int pType ) 182 throws RemoveException , RemoteException 183 { 184 try { 185 getAccountHome().create().removeAccount( pCustomerId, pType ); 186 } 187 catch( CreateException ce ) { 188 } 190 } 191 192 private AccountSessionHome getAccountHome() { 193 try { 194 return (AccountSessionHome) new InitialContext ().lookup( AccountSessionHome.COMP_NAME ); 195 } 196 catch( NamingException ne ) { 197 throw new EJBException ( ne ); 198 } 199 } 200 201 private CustomerHome getCustomerHome() { 202 try { 203 return (CustomerHome) new InitialContext ().lookup( CustomerHome.COMP_NAME ); 204 } 205 catch( NamingException ne ) { 206 throw new EJBException ( ne ); 207 } 208 } 209 210 public void setSessionContext(SessionContext context) 212 { 213 super.setSessionContext(context); 214 } 215 } 216 217 260 | Popular Tags |