EJB Architecture: Remote Client View
EJB Architecture: Remote Client View
An EJB client JAR file is an optional JAR file that can contain all the class files that a client
program needs to use the client view of the enterprise beans that are contained in the EJB JAR
file. If you decide not to create a client JAR file for an EJB module, all of the client interface
classes will be in the EJB JAR file.
EJB container:
An EJB container is a run-time environment that manages one or more enterprise beans.
It manages the life cycles of enterprise bean objects, coordinates distributed transactions and
implements object security.
Deployment descriptor:
A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR
file or an EAR file. It contains metadata describing the contents and structure of the
enterprise beans, and runtime transaction and security information for the EJB container.
EJB server:
An EJB server is a high-level process or application that provides a run-time environment to
support the execution of server applications that use enterprise beans.
An EJB server provides a JNDI-accessible naming service.
It manages and coordinates the allocation of resources to client applications, provides access
to system resources and provides a transaction service.
Local interfaces:
They improve the efficiency of intra-container entity relationships.
Container-managed relationships:
In these, the container manages object relationships between entity beans.
Inter-Server Interoperability:
It enables heterogeneous environments.
EJB Invocation
Steps to EJB invocation are:
Retrieve Home Object reference from Naming Service via JNDI.
Return Home Object reference to the client.
Create a new EJB Object through Home Object interface.
Create EJB Object from the EJB Object.
Return EJB Object reference to the client.
Invoke business method using EJB Object reference.
Delegate request to Bean (Enterprise Bean).
EJB Context?
EJBContext is an interface. This is implemented by the EJB container. This is also a part of
bean-container contract. The subclass of EJBContext called EntityContext is used by entity
beans. The bean class gets information about the container, client using the bean and the bean
itself from the EJBContext objects.
finder() method:
1. A finder method can retrieve multiple entity beans for the storage persistence.
2. A finder method can return only a local or remote interface or a collection of interfaces.
3. A finder method is defined in the Entity Bean class for Bean-Managed Persistence and not
defined in the Container-Managed Persistence.
Entity Bean:
It is a data component that persists data onto a secondary storage such as a database.
Like a simple java class, the Entity Bean has attributes and methods. Attributes are used to
store data and methods are to perform operations on the fields.
Entity beans can be viewed as a record in a database. An Entity Bean lasts as long as the data
it represents.
Message-Driven Bean:
A Message-Driven Bean is an enterprise bean that is used to manage messages
asynchronously. It acts as a listener to receive messages. The message can be sent by using
any J2EE component-application client, another enterprise bean, a web component or by a
JMS application.
Clients do not access the message driven beans through interfaces. Message Driven Beans are
primarily focused on JMS. It is possible to get messages by multiple parties.
Bean-Managed Persistence:
Compared to CMP, Bean-Managed Persistence is complicated.
The reason behind is to hardcode to persistence logic in the bean class.
In order to hardcode the persistence logic, the enterprise developer need to know the type of
database and also the way of the bean class fields maps to that of the database.
BMP provides more flexibility in managing the state between bean class fields to the
database.
System Administrator:
The system administrator is responsible to maintain the deployed EJB applications very
frequently. He has to see that the EJBs run 24x7 environment without any interruption
including the restart of a server in case of its crash. In addition to these, he is also responsible
to maintain the security of the users.
EJB Server Provider:
The EJB Server Provider provides the EJB server that hosts the EJB container. Most of the
EJB containers are packaged with the EJB Servers.
EJB Container Provider:
The EJB container provider provides the resources to write an EJB container and conforms
that the software is on par to the EJB specifications. He should also provide the required
softwares and tools to the administrator in order to administer the EJB applications.
2. While mapping a CMP bean with SQL Server database, a field of float type need to be
mapped with database column of type FLOAT only, not for REAL.
3. A table which has a multi-column primary key and one or more foreign keys which share
any one of the primary key columns, then the foreign keys must contain columns which are
not of primary key or exactly the same primary key columns.
4. For Example: the two columns that comprises a primary key are A and B. Then the
columns that comprises a foreign key are column A and column B or column C and column
D, but certainly not column A and column D or column B and column C or column A and
column C or column B and D.
5.While using root-leaf approach in order to map inheritance, the foreign-key constraints are
to be removed from the database for avoiding referential integrity related issues. The same
process is to be followed while using secondary maps with multiple tables.
Entity bean
Entity beans are objects that represents a persistence storage mechanism. The objects can be a
customer, product, account etc. Each entity bean has underlying table in a relational database
and each row in the table represents the instance of the bean.
Need of entity beans:
1. When it is needed by multiple clients.
2. When any action from the database side.
3. When a transaction is to be performed from the client.
4. When the enforcement of accuracy and integrity is needed.
1. Author and compile the various entity beans that are to be deployed. This includes bean
class, remote interfaces, home interfaces, and the primary key class, if required.
2. Get the mapping done for the entity beans for the appropriate database tables and save the
mapping information that is a deployable XML file.
3. Assemble the entity beans into a .jar or .ear file
1. Configuration:
Specifying the number of properties for the bean. The usage of persistence mechanism and
the needed information to do so.
2. Code generation:
The information from the configuration phase is used by the different tools to generate the
classes for the required beans. This process may include helper classes related to transactions,
persistence, and security.The implementations of EJBHome and EJBObject, and the stubs and
skeletons required for RMI-IIOP.
3. Installation:
The EJB server is started and make the beans available to the client’s applications.
2. Pooled State:
- At the time of starting the EJB server,with the help of the method Class.newInstance() , all
the instances are created and placed in a pool. The default values of the persistent fields are
set. The bean class should never contain the constructor. Therefore the default no-argument
must be available in the container.
- Before placing the instances in the pool, an instance EntityContext is assigned by the
container which assigns and implements the setEntityContext() method by the bean class,
followed by entering into the instance pool.
- Now the bean instance is available for the client requests and become active soon after
receiving the requests. The bean container provides different levels of access at every stage of
the bean’s life cycle.
- Once the bean reaches this state, it can accept the requests from the client. The state of a
beans instance reaches to ready state once the container assigns it to an EJB object.
- The sorting mechanism is not supported in EJB QL. Reason is EJB QL does not support
ORDER BY clause. The sorting can be done after retrieving data and can be simplified by
using the Java collections framework (sort() method ).
- To be simple and clear, the CMP is being performed by the container which needs almost no
hard coding.
- While implementing the beans the complexity is reduced and all the finder methods are
implemented by the container.
1. FROM clause:
- FROM clause specifies the scope of the query. The scope is a the identification variables.
- In order to a valid query every query must contain the FROM clause. There are two
components in the FROM clause :
FROM {AbstractSchemaName entityBeanVariable}
AbstractSchemaName is the specification of an alias name for an entity bean using the tag
<abstract-schema-name> in the ejb-jar.xml file.
Using IN : The IN keyword designate a set of data collection for the preceding identifier to
evaluate.
Using AND: The AND clause is used to combine logical expressions in the query.
Using AS: The AS clause is used to designate an identifier as the rest of the query.
3. WHERE clause:
- WHERE clause specifies the conditional selection for the query which results in restricted
values in the query. This clause is optional.
- Template code, base class, interface dependency are not available and very lightweight.
Won’t express the container dependency and easily breakable such as the typos by the
developers.
Interface:
- The expression is clearly depended and no breakages.
- Coding template is a lot.
Base class:
- Template code availability in base class. Extendibility by the developers.
- No template code, not breakable.
- Single inheritance in java makes this base class.
Annotations:
- Remote methods overhead will be eliminated that is needed at the time of existence of EJBs
in different clients and servers.
Local interfaces versus Dependent value objects.
Local interfaces:
- An interface that establishes the communications between EJBs of the same machine.
- The overhead of using remote methods can be eliminated by remote methods that are needed
when the EJBs of separate clients and servers.
- Local interfaces are BMP constructs.
Dependent value objects:
Message-driven bean
- A MDB is one of the enterprise bean that allows an EJB application to perform messages
asynchronously.
- It is a message listener similar to event listener that receives messages instead of events.
- It is similar to JMS message listener.
- Unlike a session bean or entity bean, a message driven bean has only a bean class.
- The message process starts when the container calls the message-driven bean’s onMessage
method soon after a message arrives.
Procedure:
- Pass the session object as the parameter to the constructor of MimeMessage object. This
creates an initially empty message.
- Add the necessary content to the message using the methods
setSubject(),setContent(),setReceipients(),addForm() .
- Send the message using send() method
<security-role> :
- The definition of the security role is specified in this element.
<role-name> :
- The name of the role for the security is mentioned in this element. The name can be Admin,
Architect,Owner.
<description> :
- The description about the security model is given in the tag which is optional.
Custom Security :
- Custom security encourages the bean provider to specify a mechanism for the security.
- The needs the business method to implement the security logic.
- The methods that support custom security at bean level are:
- java.security.Principal getCallerPrincipal()
- boolean isCallerInRole(java.lang.String roleName)
- Any security validation type can be customised along with these methods.
Authorization : - This ensures that the accessibility to the private resources only by the
authorized user. To have the accessibility, the user is mandatory to authorized first.
Secure Communication :
EJB container
An EJB container will provide the runtime environment for EJB applications within the
application server.
- It is responsible for all the operations of the EJB applications.
- The container acts as an intermediary action between the business logic of the bean and the
rest of the world of the enterprise application.
- One or more EJB modules can be installed within a single EJB container.
- The role of EJB container is to perform transactional actions such as,
1. Starting a transaction.
2. Rollback a transaction or commit a transaction.
3. Managing various connection pools for the database resources.
4. Bean’s instance variables with corresponding data items which are stored in a database will
be synchronized.
4. Transaction:
EJB provides 2 types of transactions:
1. Container-managed transactions
2. Bean-managed transactions
- One or more EJB modules can be installed within a single EJB container. The role of EJB
container is to perform transactional actions such as,
1. Starting a transaction.
2. Rollback a transaction or commit a transaction.
3. Managing various connection pools for the database resources.
4. Bean’s instance variables with corresponding data items which are stored in a database will
be synchronized.
Web Container: