1 / 12

Structure of Enterprise Java Beans

Structure of Enterprise Java Beans. Introduction. Main goal of Enterprise Java Bean (EJB) architecture is to free the application developer from having to deal with the system level aspects of an application. This allows the bean developer to focus solely on the logic of the application.

vgagne
Download Presentation

Structure of Enterprise Java Beans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structure of Enterprise Java Beans

  2. Introduction • Main goal of Enterprise Java Bean (EJB) architecture is to free the application developer from having to deal with the system level aspects of an application. This allows the bean developer to focus solely on the logic of the application.

  3. Parts of EJB • EJB class that implements the business methods and life cycle methods; uses other helper classes and libraries to implement. • Client-view API: consists of EJB home interface and remote interface. • Home interface: controls life cycle : create, remove, find methods • Remote interface: to invoke the EJB object methods

  4. Parts of EJB (contd.) • Deployment Descriptor: XML document for bean assembler and deployer; • A declaration about EJB environment needed for customizing the bean to the operating environment. • Container Runtime services include: transactions, security,distribution,load balancing, multithreading, persistence, failure recovery, resource pooling, state amnagement, clustering..

  5. Naming Convention • EJB class is a descriptive name of the business entity or process with the word Bean appended. Ex: AccountBean • Home interface is same as business entity name with the word “Home” appended. Ex: AccountHome • Remote interface is just the name of the entity. Ex: Account • The name of the entire EJB (reference in deployment descriptor) is same as the enity name with EJB appended. Ex: AccountEJB

  6. Enterprise Bean Parts <<Home Interface>> AccountHome <<Remote Interface>> Account create() find() remove() debit() credit() getBalance() <<Enterrpise Bean class> AccountBean Deployment Descriptor name = AccountEJB class = AccountBean home = AccountHome remote = Account type = Entity transaction = required ….. ejbCreate() ejbFind() ejbRemove() debit() credit() getBalance()

  7. AccountHome Interface import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.FinderException; import java.util.Collection; public interface AccountHome extends javax.ejb.EJBHome { //create methods Account create (String lastName, String firstName) throws RemoteException, CreateException, BadNameException; Account create (String lastName) throws RemoteException, CreateException; // find methods Account findByPrimaryKey (AccountKey primaryKey) throws RemoteException, FinderException; Collection findInActive(Date sinceWhen) throws RemoteException, FinderException, BadDateException;

  8. EJBHome Interface import java.rmi.RemoteException; public interface EJBHome extends java.rmi.Remote { void remove(Handle handle) throws RemoteException, RemoveException; void remove(Object primaryKey) throws RemoteException, RemoveException; EJBMetaData getEJBMetaData( ) throws RemoteException; HomeHandle getHomeHandle() throws RemoteException; }

  9. Account Interface import java.rmi.RemoteException; public interface Account extends javax.ejb.EJBObject { BigDecimal getBalance() throws RemoteException; void credit(BiGDecimal amount) throws RemoteException; Void debit(BigDecimal amount) throws RemoteException, InSufficientFundsException; }

  10. EJBObject Interface import java.rmi.RemoteException; public interface EJBObject extends java.rmi.Remote { public EJBHome getEJBHome() throws RemoteException; public Object getPrimaryKey() throws RemoteException; public void remove() throws RemoteException, RemoveException; Public Handle getHandle() throws RemoteException; Boolean isIdentical (EJBObject obj2) throws RemoteException; }

  11. AccountBean class public class AccountBean implements javax.ejb.EntityBean { // life cycle methods from home interface public AccountKey ejbCreate (String latName, String firstName) throws … {…} public AccountKey ejbCreate(String lastName) throws …{…} public AccountKey ejbFindByPrimaryKey(AccountKey primarykey)… {…} Public Collection ejbFindInactive( Data sinecWhen).. {…} // business methods from remote interface public BigDecimal getBalance() {….} public void credit(BigDecimal amt) {…} Public void debit(BigDecimal amt) throws InsufficientFundException {….} // container callbacks from EntityBean container public ejbRemove( ) throws RemoveException{ …} public void setEntityContext(EntityContext ec) {…} public unsetEntityContext(EntityContext ec) {…} public void ejbActivate() {…} public void ejbLoad() {….} public void ejbStore() {….} }

  12. Deployment Descriptor … <entity-bean> <ejb-name>AccountEJB</ejb-name> <home>com.wombat.AccopuntHome</home> <remote>com.wombat.Account</remote> <ejb-class>com.wombat.AccountBean</ejb-class> <persistence-type>Bean<\persistence-type> <primary-key-class>com.wombat.AccountKey</primary-kay-class> </entity-bean> … <container-transaction> <method> <ejb-name>AcoountEJB</ejb-name> <method-name>*</method-name> </method> <trans-attribute>required</trans-attribute> </container-transaction> …

More Related