Entity Beans
|
Entity Beans |
The EntityBean Interface public interface javax.ejb.EntityBean { public abstract void ejbActivate(); public abstract void ejbLoad(); public abstract void ejbPassivate(); public abstract void ejbRemove(); public abstract void ejbStore(); public abstract void setEntityContext(EntityContext ctx); public abstract void unsetEntityContext(); }
ejbActivate() and ejbPassivate()
ejbLoad() and ejbStore()
setEntityContext() and unsetEntityContext()
ejbRemove()
ejbFindByPrimaryKey()
Bean-Managed and Container-Managed Persistence
Reentrant and Non-reentrant Entity Beans
|
A High Level View of an EJB Conversation
|
A High Level View of an EJB Conversation |
|
Building and Deploying EJBs
|
Building and Deploying EJBs |
|
Writing the EJB:
Deploying the EJBs:
Connecting to the EJB
|
Roles in EJB
|
Roles in EJB |
a) Enterprise Bean Provider
b) Deployer
c) Application Assembler
d) EJB Server Provider
e) EJB Container Provider
f) System Administrator
|
Session Beans
|
Session Beans |
ejbPassivate()
ejbActivate()
ejbRemove()
setSessionContext(SessionContext ctx)
The EJBContext Interface
getCallerIdentity()
getEJBHome()
getEnvironment()
getRollbackOnly()
getUserTransaction()
The UserTransaction Interface public interface javax.jtx.UserTransaction { public final static int STATUS_ACTIVE; public final static int STATUS_COMMITTED; public final static int STATUS_COMMITTING; public final static int STATUS_MARKED_ROLLBACK; public final static int STATUS_NO_TRANSACTION; public final static int STATUS_PREPARING; public final static int STATUS_PREPARED; public final static int STATUS_ROLLEDBACK; public final static int STATUS_ROLLING_BACK; public final static int STATUS_UNKNOWN; public abstract void begin(); public abstract void commit(); public abstract int getStatus(); public abstract void rollback(); public abstract void setRollbackOnly(); public abstract void setTransactionTimeout(int seconds); }
isCallerInRole()
setRollbackOnly()
The SessionContext Interface
public interface javax.ejb.SessionContext extends javax.ejb.EJBContext { public abstract EJBObject getEJBObject(); }
The Rules for an ejbCreate() method in Session Beans are as follows:
The following steps are involved in the creation of a new Session Bean:
Stateful and Stateless Session Beans
The SessionSynchronization Interface public interface javax.ejb.SessionSynchronization { public abstract void afterBegin(); public abstract void afterCompletion(boolean committed); public abstract void beforeCompletion(); }
afterBegin()
beforeCompletion()
afterCompletion()
|
Enterprise Beans
|
The EJB Home Interface
public interface javax.ejb.EJBHome extends java.rmi.Remote { public abstract EJBMetaData getEJBMetaData(); public abstract void remove (Handle handle); public abstract void remove (Object primaryKey); }
getEJBMetaData()
public interface javax.ejb.EJBMetaData { public abstract EJBHome getEJBHome(); public abstract Class getHomeInterfaceClass(); public abstract Class getPrimaryKeyClass(); public abstract Class getRemoteInterfaceClass(); public abstract boolean isSession(); }
remove(Handle handle)
remove(Object primaryKey)
The EJBHome interface does not provide any methods by which a client can create new beans or look up existing ones. Instead, the EJB bean developer must write the method signatures for these tasks in their own interfaces.
The EJBObject Interface All remote interfaces extend the EJBObject interface:
public interface javax.ejb.EJBObject extends java.rmi.Remote { public abstract EJBHome getEJBHome(); public abstract Handle getHandle(); public abstract Object getPrimaryKey(); public abstract boolean isIdentical (EJBObject obj); public abstract void remove(); }
getEJBHome()
getHandle()
getPrimaryKey()
isIdentical()
Two Entity beans that are from the same home interface and have the same primary key are considered identical.
The two references in this method do not necessarily point to the same object in memory, but all of these instances are considered to have the same identity.
remove()
Note: To create a remote interface, simply create an interface that inherits from EJBObject and add the method signatures of the methods. And there is no need to implement this remote interface. Instead the container generates a proxy object that interacts with remote clients and passes their method calls to the bean.
The EnterpriseBean Interface
public interface javax.ejb.EnterpriseBean extends java.io.Serializable {
}
|
EJB Containers
|
EJB Containers |
a) Support for transactions
b) Support for Management of Multiple Instances
i) Instance Passivation
ii) Instance Pooling
iii) Database Connection Pooling
iv) Precached instances
v) Optimized method invocations
c) Support for persistence
d) Support for security
|
EJB Servers
- It is a “Container Container” – it contains the EJB container
- It is responsible for providing the container with lower-level services such as network connectivity.
- The EJB Specification 1.0 did not outline the exact interface between the EJB container and the EJB server. So, interface is currently left up to the individual vendor.
- At an abstract level, though, the relationship between the container and server is such that the server will provide the container with low-level implementation of the services required by the container.
- The layered architecture is shown below:
Overview of EJB’s Software Architecture
|
Overview of EJB’s Software Architecture
The diagram presents a high-level view of the EJB architecture, showing the various relationships between the various components.
|
|
This illustrates the Key Features of the EJB Architecture
|
EJB Logical Architecture
|
EJB Logical Architecture |
|
· A EJB system is logically a three-tier system · The three tiers are as follows: a) The Client b) The EJB Server c) The Database (or other persistent store) · This is a logical architecture because these tiers don’t necessarily have to reside on three different machines. · For example, a) The EJB server and the database might reside on the same machine, when the EJB server includes built-in functionalities for persistent storage. b) The client and the EJB server might reside on the same machine, when an EJB bean makes a call to another bean in the same container. The caller bean is acting as a client here. c) These two cases can be combined to have all the tiers in a single machine. · EJB’s role in each of these tiers are: a) A program on the client side makes call to remote EJBs. The client needs to know how to find the EJB server and how to interact with the objects that reside on the EJB server. b) The EJB components live in the middle tier. The EJB objects reside inside an EJB container, which in turn resides in an EJB server. c) EJB can access the database themselves, typically via Java Database connecting (JDBC), or they can allow the container to handle their data storage needs for them.
|



