Ejb3 In Action Cap1

1.1 EJB overview

Dal punto di vista dello sviluppatore, EJB è un pezzo di codice che viene eseguito in un ambiente di runtime specializzato chiamato container EJB , che fornisce un numero di component services.

1.1.1 EJB as a component

There are three types of EJB components: session beans, message-driven beans,
and entities. Session beans and message-driven beans are used to implement
business logic in an EJB application, and entities are used for persistence.
Components can be reusable

1.1.2 EJB as a framework

Il framework permette di risparmiare parecchio lavoro sfruttando i servizi già presenza, come sicurezza, validazione , interoperbilità ecc.
Gli EJB sono degli oggetti POJO con l'aggiunta delle annotazioni. Gli EJB possono essere usati per costruire applicazioni stratificati.

EJB allows you to build applications using two different layered architectures:
the traditional four-tier architecture and domain-driven design (DDD). Let’s take
a brief look at each of these architectures.

Traditional four-tier layered architecture

Qui vi è l'architettura a 4 livelli

four-tier.jpg
  1. The presentation layer passes down each request for application functionality to the business logic layer.
  2. The business logic layer is the heart of the application and contains workflow and processing logic. The business logic layer retrieves data from and saves data into the database by utilizing the persistence tier.
  3. The persistence layer provides a high-level object-oriented (OO) abstraction over the database layer. # The database layer typically consists of a relational database management system (RDBMS) like Oracle, DB2, or SQL Server.

EJB implementa il Buisness logic e il Persistence layer.
I bean chiamati session beans e message-driven beans (MDBs) risiedono e usano i servizi in business logic tier, i bean chiamati entities in persistence.
Ecco come EJB implementa il modello a 4 livelli

component-service-ejb.jpg

The traditional four-tier layered architecture is not perfect. One of the most common criticisms is that it undermines the OO ideal of modeling the business domain as objects that encapsulate both data and behavior.
Il problema è che questa archietettura è troppo legata al db piuttosto che alla programmazione ad oggetti qui interviene l'altra alternativa.

Domain-driven design

DDD emphasizes that domain objects should contain business logic and should not just be a dumb replica of database records. Domain objects are known as entities in EJB 3

Implementing a real domain model was almost impossible with EJB 2because beans were not POJOs and did not support many OO features such as inheritance and polymorphism.
Con gli EJB3 invece tutto questo si può realizzare si può aggiungere la buisness logic alle entità in modo da implementare un modello ricco. Anche se molti preferiscono tenere bene separati i livelli di entità e quelli di logica.

1.1.4 Why choose EJB 3?

Ease of use

È il server-side development platform più facile da usare perchè implementa i POJO con le annotazioni contro una verbosità eccessiva degli xml.

Integrated solution stack

EJB 3 offers a complete stack of server solutions, including persistence, messaging, lightweight scheduling, remoting, web services, dependency injection (DI), and interceptors. Si integra facilmente con altre tecnologie JavaEE

Open Java EE standard

EJB is open is developed by the Java Community Process (JCP).

Broad vendor support

Stable, high-quality code base

Clustering, load balancing, and failover

1.2 Understanding EJB types

Vi sono tre tipi di bean:

  1. Session beans
  2. Message-driven beans
  3. Entities

Session beans and message-driven beans (MDBs) are used to build business logic, and they live in the container, which manages these beans and provides services to them. Entities are used to model the persis-
tence part of an application e sono amministrati da un persistence provider

1.2.1 Session beans

Process business logic. A session bean can be invoked either locally or remotely using Java RMI. A stateless session bean can be exposed as a web service.

1.2.2 Message-driven beans

Process business logic. However, MDBs are different in one important way: clients never invoke MDB methods directly. Instead, MDBs are triggered by messages sent to a messaging server, which enables sending asynchronous messages between system components.
MDBs are typically used for robust system integration or asynchronous processing.

1.2.3 Entities and the Java Persistence API

EJB gestisce la persistenza tramite ORM.
ORM is essentially the process of mapping data held in Java objects to database tables using configuration, molto meglio rispetto alle JDBC.
Si usa:

  1. The creation of ORM configuration metadata for mapping entities to relational tables
  2. The EntityManager API—a standard API for performing CRUD (create, read, update, and delete)/persistence operations for entities
  3. The Java Persistence Query Language (JPQL), for searching and retrieving persisted application data

1.3 Getting inside EJB

To execute session beans and MDBs you need an EJB container, and to run your entities you need a
persistence provider.
Come si vede in figura un JavaEE container può avere diversi tipi di container specifici per quello che vi deve girare.
containers.jpg

1.3.1 Accessing EJB services: the EJB container

The container transparently provides EJB component services such as transactions, security management, remoting, and web services support.
The task of putting an EJB 3 component inside a container is called deployment. Once an EJB is successfully deployed in a container, it can be used in your applications.

1.3.3 Gaining functionality with EJB services

Il vantaggio di usare EJB è quello di avere molti servizi già pronti all'uso in modo da doversi concentrare solo sullo sviluppo dell'applicazione. Ecco un elenco dei servizi disponibili
services1.jpg
services2.jpg

1.4 Renaissance (rinascita) of EJB

@Stateless symbol is a metadata annotation that converts the POJO to a full-powered stateless EJB

…. il resto l'ho lasciato perdere per adesso….

Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License