1 / 18

Enterprise Java Bean

Enterprise Java Bean. 2110472 Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University. Outline. Overview. EJB Architecture. EJB Interfaces. Example. Overview. What is EJB ? Component-based Server-side (similar to Servlet).

chi
Download Presentation

Enterprise Java Bean

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. Enterprise Java Bean 2110472 Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University

  2. Outline • Overview. • EJB Architecture. • EJB Interfaces. • Example.

  3. Overview • What is EJB ? • Component-based Server-side (similar to Servlet). • Same as Servlet ? • Transaction • Atomic execution of multiple operations. • Ex: Transfer money between two accounts • Withdraw from the source account. • Deposit to the destined account. • Must execute all-or-nothing.

  4. Overview • Distributed • Invoke EJB over the network • Interface vs. implementation.

  5. Overview • The caller feels like invoke local class instance • Use method as you call Java class. • Location independence • Can be on any server. • Advance techniques: load balancing, fault tolerance, … • Security • Who can use what ? • Access control.

  6. Data as an Object • Typical JSP: • Built-in SQL statement in JSP page. • Problems ? • For the user of EJB • Data are objects. • Each field is a data member of a Java class. • No direct contact to database (let EJB handle it).

  7. Example: Using EJB Integer id = new Integer(351); Customer cust = custHome.findByPrimaryKey(id); System.out.println(cust.getName()); Customer customer = custHome.create(new Integer(804)); Name name = new Name("Richard", "Wayne", "Monson-Haefel"); customer.setName(name);

  8. EJB Basic Architecture

  9. EJB Type • Entity Bean • Data object with actual storage • Room, customer, etc. • Permanent / persistence. • Container-managed vs. bean-managed. • Session Bean • Business processes / methods • Reserve_room, availableRoom, etc. • Stateless (one action) vs. stateful (sequence of actions).

  10. EJB Container

  11. EJB Conceptual View

  12. EJB Home Interface • Allow client to manage the bean (factory) • Create a new bean or find the existing bean. • Developer must define the primary key (type). • No need to write “Implementation”. public interface CustomerHome extends EJBHome { public Customer create(Integer customerNumber) throws RemoteException, CreateException; public Customer findByPrimaryKey(Integer customerNumber) throws RemoteException, FinderException; public Enumeration findByZipCode(int zipCode) throws RemoteException, FinderException; }

  13. EJB Remote Interface • Interface to the actual data • Define how the data looks like. • Access (get/set) data in each field. public interface Customer extends EJBObject { public Name getName() throws RemoteException; public void setName(Name name) throws RemoteException; public Address getAddress() throws RemoteException; public void setAddress(Address address) throws RemoteException; }

  14. Ex: Using EJB Interfaces Integer id = new Integer(351); Customer cust = custHome.findByPrimaryKey(id); System.out.println(cust.getName()); Customer customer = custHome.create(new Integer(804)); Name name = new Name("Richard", "Wayne", "Monson-Haefel"); customer.setName(name);

  15. Container-Managed Bean public class CustomerBean implements EntityBean { int customerID; Address myAddress; Name myName; CreditCard myCreditCard; // CREATION METHODS public Customer ejbCreate(Integer id) { customerID = id.intValue(); return null; } public void ejbPostCreate(Integer id) { } public Customer ejbCreate(Integer id, Name name) { myName = name; return ejbCreate(id); } public void ejbPostCreate(Integer id, Name name) { }

  16. Container-Managed Bean // BUSINESS METHODS public Name getName() { return myName; } public void setName(Name name) { myName = name; } public Address getAddress() { return myAddress; } public void setAddress(Address address) { myAddress = address; } public CreditCard getCreditCard() { return myCreditCard; } public void setCreditCard(CreditCard card) { myCreditCard = card; }

  17. Container-Managed Bean // CALLBACK METHODS public void setEntityContext(EntityContext cntx) { } public void unsetEntityContext() { } public void ejbLoad() { } public void ejbStore() { } public void ejbActivate() { } public void ejbPassivate() { } public void ejbRemove() { } }

  18. References • jGuru, Enterprise JavaBeans Technology Fundamentals, http://developer.java.sun.com/developer/onlineTraining/. • EJB Tutorial, http://www.ejbtut.com/Overview.jsp. • A. Hemrajani, The state of Java middleware, Part 2: Enterprise JavaBeans, JavaWorld, April 1999, http://www.javaworld.com/javaworld/jw-04-1999/jw-04-middleware_p.html.

More Related