EJB 3 Goals
The EJB 3 provide an alternative to the CMP Entity
Simplify EJB Development
EJB 2.1 Session Bean Class
EJB 2 Deployment Descriptor
EJB 3 : Simplifying with annotations
Same Example: EJB 3
Same Example: EJB 3
EJB 3 Simplifications
EJB3 in Jboss
EJB3 in Weblogic
EJB3 in Websphere
EJB3 in Glassfish
• Simplify
developers life
• EJB now resembles Plain Java Object (POJO)
• Use metadata annotations
• XML descriptors are no longer necessary
• Default
• Unnecessary artifacts are optional
• Simplify client view using dependency injection
• Standardize persistence API for Java platform
• Based on success of leading ORM solutions
• Including Oracle TopLink, Hibernate
• EJB now resembles Plain Java Object (POJO)
• Use metadata annotations
• XML descriptors are no longer necessary
• Default
• Unnecessary artifacts are optional
• Simplify client view using dependency injection
• Standardize persistence API for Java platform
• Based on success of leading ORM solutions
• Including Oracle TopLink, Hibernate
The EJB 3 provide an alternative to the CMP Entity
- Beans to access the database.
- Unlike the previous ones, they are synchronized with the
- database only when decided by the program.
Simplify EJB Development
• POJO
(Plain Old Java Object) Class
• EJB Class will be a plain java class
• POJI (Plain Old Java interface)
• Regular business interface
• EJB interface does not have to implement EJBObject
• No need of home interface
• Annotations for type of EJB and interface
• EJB Class will be a plain java class
• POJI (Plain Old Java interface)
• Regular business interface
• EJB interface does not have to implement EJBObject
• No need of home interface
• Annotations for type of EJB and interface
EJB 2.1 Session Bean Class
public class CartEJB
implements SessionBean
{
protected Collection items = new ArrayList();
public void add(String item)
{
items.add(item);
}
public CollectiongetItems()
{
return items;
}
public voidcompleteOrder(){ .. }
public void ejbCreate(){}
public voidejbActivate(){}
public voidejbPassivate(){}
public void ejbRemove(){}
public voidsetSessionContext(SessionContext context){}
}
{
protected Collection items = new ArrayList();
public void add(String item)
{
items.add(item);
}
public CollectiongetItems()
{
return items;
}
public voidcompleteOrder(){ .. }
public void ejbCreate(){}
public voidejbActivate(){}
public voidejbPassivate(){}
public void ejbRemove(){}
public voidsetSessionContext(SessionContext context){}
}
EJB 2 Deployment Descriptor
<session>
<display-name>Shopping Cart</display-name>
<ejb-name>MyCart</ejb-name>
<home>CartHome</home>
<remote>Cart</remote>
<ejb-class>CartEJB</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
<display-name>Shopping Cart</display-name>
<ejb-name>MyCart</ejb-name>
<home>CartHome</home>
<remote>Cart</remote>
<ejb-class>CartEJB</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
EJB 3 : Simplifying with annotations
- @Stateless
- @Stateful
- @MessageDriven
- @Entity
Same Example: EJB 3
@Stateful
public class CartBean implements Cart {
private ArrayList items;
public void add(String item) {
items.add(item);
}
public CollectiongetItems() {
return items;
}
@Remove
public void completeOrder()
{
}
}
public class CartBean implements Cart {
private ArrayList items;
public void add(String item) {
items.add(item);
}
public CollectiongetItems() {
return items;
}
@Remove
public void completeOrder()
{
}
}
Same Example: EJB 3
@Remote
public interface Cart {
public void addItem(String item);
public void completeOrder();
public CollectiongetItems();
}
public interface Cart {
public void addItem(String item);
public void completeOrder();
public CollectiongetItems();
}
EJB 3 Simplifications
• Eliminated
requirement for Home Interface
• Not needed for session beans
• Business interface is a POJI
• Bean can implement it
• Bean can have more than one business interface
• Can support remote access
• EJB(Local)Object removed from client view
• RemoteExceptionsare removed from programmer and client view
• Eliminated requirement for unnecessary callbackmethods
• Removed requirement to implement javax.ejb.SessionBean
• Not needed for session beans
• Business interface is a POJI
• Bean can implement it
• Bean can have more than one business interface
• Can support remote access
• EJB(Local)Object removed from client view
• RemoteExceptionsare removed from programmer and client view
• Eliminated requirement for unnecessary callbackmethods
• Removed requirement to implement javax.ejb.SessionBean
EJB3 in Jboss
EJB3 in Weblogic
EJB3 in Websphere
EJB3 in Glassfish
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి