Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Triad of Beans I Oleh: Dini Addiati (1203000366) Fahrurrozi Rahman (120300042Y) Irfan Hilmy (1203000552) Salman Azis A (1203001001) Aziiz Surahman.

Similar presentations


Presentation on theme: "The Triad of Beans I Oleh: Dini Addiati (1203000366) Fahrurrozi Rahman (120300042Y) Irfan Hilmy (1203000552) Salman Azis A (1203001001) Aziiz Surahman."— Presentation transcript:

1 The Triad of Beans I Oleh: Dini Addiati (1203000366) Fahrurrozi Rahman (120300042Y) Irfan Hilmy (1203000552) Salman Azis A (1203001001) Aziiz Surahman (1203007026) Titin Farida(1203007077

2 Session Beans What is Session Beans?  A session beans represent work being performed for client code that is calling it Session Bean life time  Equivalent of a session of the client code that is calling the session bean  Non-persistent  Could be as long as a browser window is open, as long as your java applet is running, as long as your java application is open,as long as another bean is using your bean.

3 SESSION BEANS SUB TYPES Stateful Session Bean Stateless Session Bean stateful stateless MonSessionBean Atribut method ejbCreate(Arg arg) MonSessionBean method ejbCreate()

4 Stateful Session Bean  a bean that is designed to service business processes that span multiple method requests or transactions  Retaining state on behalf of an individual client  If state is changed during a method invocation, that same state will be available to that same client upon the following invocation Stateless Session Bean  a bean that holds conservations that span a single method call  Do not hold multhimethod conservations with their clients.  Can be pooled, reused, and swapped from one client to another client on each method call  Example: credit card verification

5 Characteristic of Stateful Session Beans Passivation  Container use object serialization (or equivalent protocol ) to convert the bean’s conversational state to bit blob and write out state to disk  The bean instance can be reassigned to a different client, and can hold a brand- new conversation with that new client Activation  A serialized blob that had been written is read back into memory and converted to in-memory bean data What makes the whole process work??  javax.ejb.EnterpriseBean interface extends java.io.Serializable  every enterprise bean class indirectly implements this interface  reapplied recursively on those objects

6

7 Entity Beans Entity Beans are persistent objects that can be stored in permanent storage.

8 Features of Entity Beans Entity Beans Survive Failures. They survive critical failures such as server crashing or even database crashing. Entity Beans Instance Are a View into a Database. The object and the database itself are one and the same. This means update to the object will update the database too. Several Entity Beans Instances May Represent the Same Underlying Data. EJB dictates only single thread can run within a bean instance. We could allow containers to instantiate multiple instance of the same entity bean class. This would allow many clients to concurrently interact with separate instance, each represent the same entity data.

9 Features of Entity Beans Entity Bean Instances Can Be Pooled.  Entity bean instances are recyclable objects and may be pooled depending on container’s policy.  The container may pool and reuse entity bean instances to represent different instances of the same type of data. There Are Two Ways to Persist Entity Beans.  A bean-managed persistent entity bean is entity bean that must be persisted by hand. The component developer must write the code to translate the object in the database.  Another way is container-managed persistence. In this case, the container perform the persistence.

10 Features of Entity Beans Creation and Removal of Entity Beans.  Because entity beans instance and the underlying database are one and the same, the initialization of an entity bean instance should entail initialization of database data. Entity Beans Can Be Found.  Because entity bean data is uniquely identified in an underlying storage, entity beans can also be found rather than created.  We can define many ways to find an entity bean. Just list all methods in the entity bean home interface. These are called finder methods.

11 Features of Entity Beans We Can Modify Entity Bean Data without Using EJB.  We can directly modifying the underlying database where the bean data is stored. For example we can simply delete/create the entity bean data by directly delete/add the row in the database.

12 Writing Bean-Managed Persistent Entity Beans: A Bank Account Implements javax.ejb.EntityBean Finding existing entity beans: ejbFind() (finder methods). Create java files Create deployment descriptor (XML file) Create container-specific deployment descriptor Setting up the database Running the client program

13 javax.ejb.EntityBean interface public interface javax.ejb.EntityBean extends javax.ejb.EnterpriseBean { public void setEntityContext(javax.ejb.EntityContext); public void unsetEntityContext(); public void ejbRemove(); public void ejbActivate(); public void ejbPassivate(); public void ejbLoad(); public void ejbStore(); } javax.ejb.EnterpriseBean interface public interface javax.ejb.EnterpriseBean implements java.io.Serializable{ }

14 ejbFind() Finder methods : Find existing bean in storage, load old entity bean data, not create new database. Example other finder methods: /** Finds the unique bank account indexed by primary key */ public AccountPK ejbFindByPrimaryKey(AccountPK key) throws FinderException {...} /** Find the all product entity beans. Return a collection of primary keys */ public Collection ejbFindAllProducts() throws FinderException {...}

15 Finder Methods Rules All finder methods must begin with ejbFind You must have at least one finder method, called ejbFindByPrimaryKey. You can have many different finder methods, each with different names and different parameters. A finder method must return either primary key for the entity bean it finds or a collection of primary keys if it finds more than one. As with ejbCreate(), client do not invoke your finder methods on the bean instance itself.

16 Account examples.AccountHome examples.Account. The Account Bean’s ejb-jar.xml deployment descriptor

17 Bean-Managed Persistent Example: A Bank Account > java.rmi.Remote > javax.ejb.EJBLocalObject > javax.ejb.EJBObject > javax.ejb.EJBHome > javax.ejb.EJBLocalHome > Bank Account Local Interface > Bank Account Remote Interface > Bank Account Home Interface > Bank Account Local Home Interface Bank Account EJB Local Object Bank Account EJB Object Bank Account Home Object Bank Account Local Home Object > javax.ejb.EnterpriseBean > javax.ejb.EntityBean Bank Account Bean Implementation Class Bank Account Primary Key Class > java.io.Serializable Comes with Java 2 Platform Comes with EJB Distribution Supplied by Bean Provider (We Will Write) Generated for Us by Container Vendor’s Tools Figure 1. The bank account object model

18 The files that we must create for our entity bean component Account.java : is our entity bean’s remote interface-what remote clients use to call our bean’s methods. AccountLocal.java : is our entity bean’ local interface-what local clients use to call our bean’s methods. AccountHome.java : our home interface AccountLocalHome.java : our local home interface, the higher performing home interface used by local clients. AccountPK.java : our entity bean’s primary key class.

19 AccountBean.java : our bean implementation code divided into several sections. Bean-managed state fields : persistable fields of our entity bean class. Our bean instance will load and store database data into these fields. Business logic methods : this method perform services for clients, such as withdrawing or depositing into an account. EJB-required methods : these are EJB-required methods that the container calls to manage our bean. AccountException.java Client.java

20 ejbRemove() 1: ejbCreate() 2: ejbPostCreate() Does Not Exist Pooled 1: unsetEntityContext() 2: JVM Will Garbage Collect and Call finalize() 1:newInstance() 2:setEntityContext() Passive Your Bean: 1: ejbStore() 2: ejbPassivate() Activate Your Bean: 1: ejbActivate() 2: ejbLoad() Ready Business Method ejbStore()ejbLoad() ejbFind() ejbHome() The lifecycle of a bean-managed persistent entity bean Figure 2. The lifecycle of a bean-managed persistent entity bean


Download ppt "The Triad of Beans I Oleh: Dini Addiati (1203000366) Fahrurrozi Rahman (120300042Y) Irfan Hilmy (1203000552) Salman Azis A (1203001001) Aziiz Surahman."

Similar presentations


Ads by Google