1 package test.ejb; 2 3 import test.interfaces.Account; 4 import test.interfaces.AccountData; 5 import test.interfaces.AccountPK; 6 import test.interfaces.AccountValue; 7 import test.interfaces.Customer; 8 9 import javax.ejb.*; 10 import java.util.Date ; 11 12 113 public abstract class AccountBean extends BaseEntityBean implements EntityBean { 114 129 public abstract Integer getId(); 130 131 139 public abstract void setId(Integer id); 140 141 146 public void deposit(float amount) { 147 setBalance(getBalance() + amount); 148 setLastModificationDate(new Date ()); 149 } 150 151 156 public void withdraw(float amount) { 157 if (amount <= 0) 158 throw new IllegalArgumentException ("Invalid amount: " + amount + ", must be > 0"); 159 160 setBalance(getBalance() - amount); 161 setLastModificationDate(new Date ()); 162 } 163 164 168 public float getTotalBalance() { 169 return 0; 171 } 172 173 191 public abstract test.interfaces.Customer getOwner(); 192 193 196 public abstract void setOwner(test.interfaces.Customer owner); 197 198 215 public abstract float getBalance(); 216 217 220 public abstract void setBalance(float balance); 221 222 239 public abstract Date getLastModificationDate(); 240 241 public abstract void setLastModificationDate(Date d); 242 243 255 public abstract String getAccountId(); 256 257 261 public abstract void setData(AccountData data); 262 263 272 public abstract AccountData getData(); 273 274 278 public abstract AccountValue getAccountValue(); 279 280 284 public abstract void setAccountValue(AccountValue value); 285 286 293 public AccountPK ejbCreate(AccountValue data) 294 throws CreateException { 295 setId(data.getId()); 296 setAccountValue(data); 297 298 return null; 299 } 300 301 304 public void ejbPostCreate(AccountValue data) 305 throws CreateException { 306 } 307 308 316 public void ejbHomeTransfer(Account from, Account to, float amount) { 317 try { 318 from.withdraw(amount); 319 to.deposit(amount); 320 } 321 catch (java.rmi.RemoteException e) { 322 throw new EJBException(e); 323 } 324 } 325 326 333 public Integer getGeneratedPrimaryKey() { 334 return (Integer ) entityContext.getPrimaryKey(); 335 } 336 } 337 | Popular Tags |