Development and Deployment Roles Venugopal Pakanati What is EJB technology What is an EJ bean Types of Beans Entity Bean Session Bean EJB Architecture EJB Server EJB Container Locate Create Remove instances of EJB EJB Client Invoke business methods of EJB Home Interface Remote Interface EJB Databases 5 Roles in the application development and deployment life cycle 1 Enterprise Java Bean providers 2 Application Assemblers 3 Deployers 4 System Adminstrators 5 Application Server Vendors Development and Deployment Scenario EJB Provider Application Assembler Deployer Application Server Vendor System Administrator 1 The Enterprise Java Bean Provider referred to as an application domain expert needs to be an expert in the business logic needs to be able to express business logic using Java code does not need to be an expert in system level programming do not need to understand the details of the target environment The enterprise bean provider produces a JAR containing i The bean s home interface ii The bean s remote interface iii The bean s implementation class iv The bean s primary key class in case of an entity bean v A partially complete deployment descriptor Example Banking Account Entity Bean members accountID customerName customerType accountBalance Bean Name Account Home Interface AccountHome HI methods create findbyPrimaryKey Remote Interface Account RI methods withdraw deposit getCustomerType Implementation class AccountEJB Session Bean Bean Name AccountManager Home Interface AccountManagerHome HI methods create Remote Interface AccountManager RI methods createAccount withdraw deposit cancel Implementation class AccountManagerEJB Security Roles UnmediatedAccess Web ATM deposit withdraw Teller deposit withdraw Manager All methods Of session bean i The Bean s Home Interface a Home Interface for the Entity Bean b Home Interface for the Session Bean a Home interface for the entity bean package wrox some isv import javax ejb import java rmi RemoteException public interface AccountHome extends EJBHome public Account create int accountID String customerName String customerType double initialBalance throws CreateException RemoteException public Account findByPrimaryKey Integer accountID throws FinderException RemoteException b Home Interface for the Session Bean package wrox some isv import javax ejb import java rmi RemoteException public interface AccountManagerHome extends EJBHome AccountManager create throws CreateException RemoteException ii The Bean s Remote Interface a Remote Interface for the Entity Bean b Remote Interface for the Session Bean a Remote Interface for the Entity Bean package wrox some isv import javax ejb import java rmi RemoteException public interface Account extends EJBObject void withdraw double amount throws InsufficientFundsException RemoteException void deposit double amount throws RemoteException String getCustomerType throws RemoteException b Remote Interface for the Session Bean package wrox some isv import javax ejb import java rmi RemoteException public interface AccountManager extends EJBObject void createAccount int accountID String customerName String customerType double initialBalance throws NoAccountCreatedException RemoteException void withdraw int accountID double amount throws InsufficientFundsException NoSuchAccountException RemoteException void deposit int accountID double amount throws NoSuchAccountException RemoteException public void cancel int accountID throws RemoteException iii Bean s Implementation Class Session Bean implementation class package wrox some isv import javax ejb import javax naming import java rmi RemoteException public class AccountManagerEJB implements SessionBean public SessionContext ctx public void createAccount int accountID String customerName String customerType double initialBalance throws NoAccountCreatedException try AccountHome accountHome getAccountHome accountHome create accountID customerName customerType initialBalance catch CreateException ce throw new NoAccountCreatedException ce getMessage catch RemoteException re throw new EJBException re public void withdraw int accountID double amount throws InsufficientFundsException NoSuchAccountException try Account account getAccount accountID if amount 250 account getCustomerType equals CustomerTypes INDIVIDUAL ctx isCallerInRole ATM throw new SecurityException account withdraw amount catch RemoteException re throw new EJBException re public void deposit int accountID double amount throws NoSuchAccountException try Account account getAccount accountID account deposit amount catch RemoteException re throw new EJBException re public void cancel int accountID try Account account getAccount accountID account remove catch NoSuchAccountException nsae catch Exception e throw new EJBException e private Account getAccount int accountID throws NoSuchAccountException try AccountHome home getAccountHome return home findByPrimaryKey new Integer accountID catch RemoteException re throw new EJBException re catch FinderException fe throw new NoSuchAccountException private AccountHome getAccountHome try InitialContext initial new InitialContext Object objref initial lookup java comp env ejb GenericAccount AccountHome home AccountHome javax rmi PortableRemoteObject narrow objref AccountHome class return home catch NamingException ne throw new EJBException ne public void ejbCreate public void ejbActivate public void ejbPassivate public void ejbRemove Entity Bean implementation class package wrox some isv import javax ejb import javax naming public class AccountEJB implements EntityBean public Integer accountID public String customerName public String customerType public double accountBalance public void withdraw double amount throws InsufficientFundsException if accountBalance amount 0 throw new InsufficientFundsException accountBalance amount public void deposit double amount accountBalance amount public String getCustomerType return customerType public Integer ejbCreate int accountID String customerName String customerType double initialBalance throws CreateException if customerType equals CustomerTypes CORPORATION customerType equals CustomerTypes INDIVIDUAL throw new CreateException Unknown customer type this accountID new Integer accountID this customerName customerName this customerType customerType this accountBalance initialBalance return this accountID public void ejbActivate public void ejbLoad public void ejbPassivate public void ejbRemove v Deployment Descriptor 2
View Full Document
Unlocking...