In this EJB-JPA tutorial, we will make use of existing Bean and add more functionality to it. Here, we will provide only dummy implementation and in the coming videos, we add code here.
SavingAcBean New Interface Methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package tube.codingexamples.ejb.statelessbean; import javax.ejb.Remote; import tube.coding.examples.jpa.entity.SavingsAccount; @Remote public interface SavingAcBeanRemote { //Sample 3.7: Declare the interface method public int newAccount(String accountHolderName, int initialBalance); //Sample 4.00a: Add Methods for Deposit, Withdraw and Account Closure public int depositMoney(int PersonalBankingId, int amount); public int withdrawMoney(int PersonalBankingId, int amount); public boolean closeSavingsAc(int PersonalBankingId); } |
SavingAcBean Dummy Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
package tube.codingexamples.ejb.statelessbean; import javax.ejb.LocalBean; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import tube.coding.examples.jpa.entity.SavingsAccount; @Stateless(mappedName = "SavingAcBean") @LocalBean public class SavingAcBean implements SavingAcBeanRemote { //Sample 3.6: Create Entiry Manager //UnitName is from persistance.xml @PersistenceContext(unitName = "JPASavingAccount") EntityManager em; public SavingAcBean() {} //Sample 3.8: Create New Account public int newAccount(String accountHolderName, int initialBalance) { SavingsAccount account = new SavingsAccount(); account.setBal(initialBalance); account.setpName(accountHolderName); em.persist(account); return account.getPid(); } //Sample 4.00b: Deposit amount to Bank Account @Override public int depositMoney(int PersonalBankingId, int amount) { return -1; } //Sample 4.00c: Withdraw amount from Savings Account public int withdrawMoney(int PersonalBankingId, int amount) { return -1; } //Sample 4.00d: Close the account. public boolean closeSavingsAc(int PersonalBankingId) { return false; } } |
Categories: JavaEE-EJB-Tube