Copyright: I don’t have anything. This is only my resume to OCMJEA 6 study based on Bambara’s book (an excellent one, if you can, buy it here). All the images are from the book and from Google Images. Personal use only. Sorry for english errors. Sergio Figueras (sergio@yourecm.com).

OCMJEA 6 - Study Book
Java EE 6 Enterprise Architect Certified Master 1Z0-807
4. Business Tier Technologies
5522fcb5e6172dc7166b2286_Screen%20Shot%202015-04-06%20at%2018.45.29.png

CERTIFICATION OBJECTIVE 5.01 - Identify the correct technology to apply to a Given Scenario including Entity Classes, Session Beans, Message Driven Beans, Timers, Interceptors and POJOs.

5522fdaae6172dc7166b22c6_Screen%20Shot%202015-04-06%20at%2018.47.15.png

1. New Features of JavaEE 6

- Focus on productivity with several new @Annotations and remove of lot of XML configs.
- Making configuration more declarative with @Annotations, generics, type safe enums.
- Decoupling EJB from infrastructure.
- Looser Coupling Contexts and Dependency Injections
- Convention over Configuration
- Simplified Packaging

2. New Features of EJB 3.1

55241c77cae2aec616b60361_Screen%20Shot%202015-04-07%20at%2015.12.45.png

3. Scenarios to use EJB

- Scalability: JavaEE Containers can run in Cluster and EJB components can run along nodes to provide scalability.
- Transactions: Transactions are easily applied by the JavaEE container in EJB components.
- Fine grained Security: EJBs supports declarative and programatic security.
- Reuse: It's easy to a client reuse EJB components.
- Lots of client options (mobile, desktop, web, etc).
EJBs must take care only of Business domain. Every low level services must be provided by the EJB container.

4. Entity class

Lightweight POJO annotated with @Entity, must have a public no args constructor, the class must not be declared final neither their instance variables can be final. Optionally, if they are RMI parameters they must implement Serializable interface.

552421a1984438680ce4f380_Screen%20Shot%202015-04-07%20at%2015.34.47.png

5. Entity beans

Since JEE 5 they are being discouraged. If you wanna provide access through EJB-QL and Bean Managed Persistence (BMP), you should use.

552423b7216b808c054e6c5b_Screen%20Shot%202015-04-07%20at%2015.38.02.png

6. Session Beans

A session bean encapsulates business logic that can be invoked programmatically by a client over local, remote, or web service client views. To access an application that is deployed on the server, the client invokes the session bean’s methods. The session bean performs work for its client, shielding it from complexity by executing business tasks inside the server.A session bean is not persistent. (That is, its data is not saved to a database.)

55242a15984438680ce4f596_Screen%20Shot%202015-04-07%20at%2016.11.23.png

6.1 Stateful Session Beans

Used in: beans represents conversational state between the bean and a specific client, the bean must hold specific state for a client, the bean represents the state between a client and another component of the app.
Example: buying cart
The state of an object consists of the values of its instance variables. In a stateful session bean, the instance variables represent the state of a unique client/bean session. Because the client interacts (“talks”) with its bean, this state is often called the conversational state.As its name suggests, a session bean is similar to an interactive session. A session bean is not shared; it can have only one client, in the same way that an interactive session can have only one user. When the client terminates, its session bean appears to terminate and is no longer associated with the client.The state is retained for the duration of the client/bean session. If the client removes the bean, the session ends and the state disappears. This transient nature of the state is not a problem, however, because when the conversation between the client and the bean ends, there is no need to retain the state.

5524317d984438680ce4f6a6_stateful.gif

6.2 Stateless Session Beans

Used in: no state for a specified client, implements a webservice.
Example:  Currency converters
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained. Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. That is, the state of a stateless session bean should apply across all clients.Because they can support multiple clients, stateless session beans can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients.A stateless session bean can implement a web service, but a stateful session bean cannot.

5524318b216b808c054e6e63_stateless.gif

6.3 Singleton Session Beans

Used in: The state or functionality must be shared by multiple threads across the app, the app must perform a task before a startup and or a shutdown,   the bean implements a webservice endpoint.
Example: webservice endpoint
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained. Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. That is, the state of a stateless session bean should apply across all clients.Because they can support multiple clients, stateless session beans can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients.A stateless session bean can implement a web service, but a stateful session bean cannot.
Concurrent access to a singleton EJB is by default controlled by the container. Both read and write access to a singleton is limited to one client at a time. However, it is possible to provide a finer level of concurrency control through the use of annotations.

5524319f5c5abb6a0cf4c465_singleton.gif552431ab984438680ce4f6ae_singleton2.jpg

6.3.1 Container Managed Concurrency (CMC) / Bean Managed concurrency (BMC)

You can annotate the class with @ConcurrencyManagement(CONTAINER, BEAN) to define the concurrency management.

7. Message Driven Beans

Used for: long processing methods (reports, for example). When resources are not available 100% of the time. To parallelize processes. Receive and process messages from third party apps.
Message Driven Beans (MDB) are beans that can process asynchronous messages (instead of Session beans that can process only synchronous messages). They can consume JMS or JCA messages.
- They are stateless, but they can access or update information in database.
- They execute upon receive a message of a client.
- They are invoked asynchronously.
- They execute for short periods.
- They can made part of transaction.
When messages arrives, they call onMessage() method, which normally converts that message to one of 5 JMS message types and execute business logic.

7. Timer Service

Applications that model business work flows often rely on timed notifications. The timer service of the enterprise bean container enables you to schedule timed notifications for all types of enterprise beans except for stateful session beans. You can schedule a timed notification to occur according to a calendar schedule, at a specific time, after a duration of time, or at timed intervals. For example, you could set timers to go off at 10:30 a.m. on May 23, in 30 days, or every 12 hours.

Programmatic timers are set by explicitly calling one of the timer creation methods of theTimerService interface. Automatic timers are created upon the successful deployment of an enterprise bean that contains a method annotated with the java.ejb.Schedule or java.ejb.Schedules annotations.

Automatic timers are created by the EJB container when an enterprise bean that contains methods annotated with the @Schedule or @Schedules annotations is deployed. An enterprise bean can have multiple automatic timeout methods, unlike a programmatic timer, which allows only one method annotated with the @Timeoutannotation in the enterprise bean class.

552433b5216b808c054e6f38_Screen%20Shot%202015-04-07%20at%2016.51.08.png

Automatic timer:

552433da984438680ce4f782_Screen%20Shot%202015-04-07%20at%2016.53.01.png5524350a984438680ce4f7b6_Screen%20Shot%202015-04-07%20at%2016.56.32.png552435175c5abb6a0cf4c4e5_Screen%20Shot%202015-04-07%20at%2016.57.37.png

CERTIFICATION OBJECTIVE 5.02 - Identify the benefits and drawbacks of persistence tecnologies such as BMP, CMP and JPA. Include ease of development, scalability, extensibility and security

1. Bean Managed Persistence

Use Bean Managed Persistence (BMP) when you need more performance than the Container can give with CMP (Container Managed Persistence). The main drawback is you need to produce a lot of code in this case.
Benefits: 

55243e3d4c7e85431a63ab6a_Screen%20Shot%202015-04-07%20at%2017.37.20.png

Drawbacks:

55243ef762b351b3134c27b3_Screen%20Shot%202015-04-07%20at%2017.40.13.png

2. Container Managed Persistence

Use Container Managed Persistence to let the Container take care of the persistence state of objects. It’s good because you leave all the implementation details to the container. So, your developers will produce faster. However, the SQL generated by the container and sent to the database is not optimal. The main benefits are:

552441f162b351b3134c284d_Screen%20Shot%202015-04-07%20at%2017.53.05.png

And the drawbacks are:

5524423762b351b3134c2858_Screen%20Shot%202015-04-07%20at%2017.54.24.png

3. Java Data Objects (JDO)

Java Data Objects is an antique specification before JPA specification. It's like an ORM. The main benefits are:

552443f469f19db11306aa46_Screen%20Shot%202015-04-07%20at%2018.01.32.png5524440262b351b3134c28a9_Screen%20Shot%202015-04-07%20at%2018.01.39.png

The main drawback is that its not frequently updated.

552445214c7e85431a63ad66_Screen%20Shot%202015-04-07%20at%2018.06.41.png

CERTIFICATION OBJECTIVE 5.03 - Identify the benefits and drawbacks of implementing Web Services in the EJB Component Container

Benefits

 – Increase Developer Productivity (@WebService is easy!)
 – Quickly exposes public methods as WebService methods.
 – Consumers can quickly consumes services.

Drawbacks

AS A PROVIDER:
 – It can figure out a messy development if you just distributes @WebService annotation everywhere.
 - Security is a concern because you just expose these methods.
AS A CONSUMER:
 – You must validate outcome data to see if the result will not leak your persistance layer.

CERTIFICATION OBJECTIVE 5.04 - Identify the benefits and drawbacks of implementing JPA and JPQL in a Given Scenario