Structure of Enterprise Java Beans B Ramamurthy 2132022
Structure of Enterprise Java Beans B. Ramamurthy 2/13/2022 B. Ramamurthy 1
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. 2/13/2022 B. Ramamurthy 2
Parts of 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. n n Home interface: controls life cycle : create, remove, find methods Remote interface: to invoke the EJB object methods 2/13/2022 B. Ramamurthy 3
Parts of EJB (contd. ) Deployment Descriptor: XML document for bean assembler and deployer; n 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. . 2/13/2022 B. Ramamurthy 4
Naming Convention EJB class is a descriptive name of the business entity or process with the word Bean appended. Ex: Account. Bean Home interface is same as business entity name with the word “Home” appended. Ex: Account. Home 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: Account. EJB 2/13/2022 B. Ramamurthy 5
Enterprise Bean Parts <<Home Interface>> Account. Home <<Remote Interface>> Account debit() credit() get. Balance() create() find() remove() <<Enterrpise Bean class> Account. Bean ejb. Create() ejb. Find() ejb. Remove() debit() credit() get. Balance() 2/13/2022 Deployment Descriptor name = Account. EJB class = Account. Bean home = Account. Home remote = Account type = Entity transaction = required …. . B. Ramamurthy 6
Account. Home Interface import java. rmi. Remote. Exception; javax. ejb. Create. Exception; javax. ejb. Finder. Exception; java. util. Collection; public interface Account. Home extends javax. ejb. EJBHome { //create methods Account create (String last. Name, String first. Name) throws Remote. Exception, Create. Exception, Bad. Name. Exception; Account create (String last. Name) throws Remote. Exception, Create. Exception; // find methods Account find. By. Primary. Key (Account. Key primary. Key) throws Remote. Exception, Finder. Exception; Collection find. In. Active(Date since. When) throws Remote. Exception, Finder. Exception, Bad. Date. Exception; 2/13/2022 B. Ramamurthy 7
EJBHome Interface import java. rmi. Remote. Exception; public interface EJBHome extends java. rmi. Remote { void remove(Handle handle) throws Remote. Exception, Remove. Exception; void remove(Object primary. Key) throws Remote. Exception, Remove. Exception; EJBMeta. Data get. EJBMeta. Data( ) throws Remote. Exception; Home. Handle get. Home. Handle() throws Remote. Exception; } 2/13/2022 B. Ramamurthy 8
Account Interface import java. rmi. Remote. Exception; public interface Account extends javax. ejb. EJBObject { Big. Decimal get. Balance() throws Remote. Exception; void credit(Bi. GDecimal amount) throws Remote. Exception; Void debit(Big. Decimal amount) throws Remote. Exception, In. Sufficient. Funds. Exception; } 2/13/2022 B. Ramamurthy 9
EJBObject Interface import java. rmi. Remote. Exception; public interface EJBObject extends java. rmi. Remote { public EJBHome get. EJBHome() throws Remote. Exception; public Object get. Primary. Key() throws Remote. Exception; public void remove() throws Remote. Exception, Remove. Exception; Public Handle get. Handle() throws Remote. Exception; Boolean is. Identical (EJBObject obj 2) throws Remote. Exception; } 2/13/2022 B. Ramamurthy 10
Account. Bean class public class Account. Bean implements javax. ejb. Entity. Bean { // life cycle methods from home interface public Account. Key ejb. Create (String lat. Name, String first. Name) throws … {…} public Account. Key ejb. Create(String last. Name) throws …{…} public Account. Key ejb. Find. By. Primary. Key(Account. Key primarykey)… {…} Public Collection ejb. Find. Inactive( Data sinec. When). . {…} // business methods from remote interface public Big. Decimal get. Balance() {…. } public void credit(Big. Decimal amt) {…} Public void debit(Big. Decimal amt) throws Insufficient. Fund. Exception {…. } // container callbacks from Entity. Bean container public ejb. Remove( ) throws Remove. Exception{ …} public void set. Entity. Context(Entity. Context ec) {…} public unset. Entity. Context(Entity. Context ec) {…} public void ejb. Activate() {…} public void ejb. Load() {…. } public void ejb. Store() {…. } } 2/13/2022 B. Ramamurthy 11
Deployment Descriptor … <entity-bean> <ejb-name>Account. EJB</ejb-name> <home>com. wombat. Accopunt. Home</home> <remote>com. wombat. Account</remote> <ejb-class>com. wombat. Account. Bean</ejb-class> <persistence-type>Bean<persistence-type> <primary-key-class>com. wombat. Account. Key</primary-kay-class> </entity-bean> … <container-transaction> <method> <ejb-name>Acoount. EJB</ejb-name> <method-name>*</method-name> </method> <trans-attribute>required</trans-attribute> </container-transaction> … 2/13/2022 B. Ramamurthy 12
- Slides: 12