Table of Contents

~~SLIDESHOW~~

Enterprise Integration Tier Services

In principle, the business logic of an enterprise application could be performed by domain objects which implement a model of the business concept as Plain-Old Java Objects (POJOs).

In practice, the requirements of enterprise applications, namely

make the implementation of objects in the business tier much more of a challenge.

Lecture Content

An Example

class BankAccount {
 
    def deposit(amount) {
        balance += amount
    }
 
    def withdraw(amount) {
        balance -= amount
    }
 
// ----- properties -----------------
    def number
    def balance
}

This model does not take into account practicalities such as overdraft limits!

Use Case: Make a Transfer

Now suppose I want to transfer £100 to my daughter’s account. Here’s the collaboration diagram:

Use case: make a transfer

So what's complex about that?

    myAccount.withdraw(100.00)
    daughtersAccount.deposit(100.00);

A Real Bank Transfer (1)

A Real Bank Transfer (2)

A Real Bank Transfer (3)

Comments


Notes

Transactions must be secure: I must provide proof of identity (authentication) and be authorized to make the transfer. My bank must authenticate itself and be authorized to make a funds transfer to my daughter’s account.

Transaction is distributed. Accounts are maintained in different machines. I access my bank across the internet, the banks access each other across the internet.

Data integrity must be assured: money can only be in my account or in my daughter’s. It cannot be lost in transit. If a failure occurs, both accounts should roll-back to their original state. The object representing my account may not even be on the same server the next time I log in: but the balance has to be correct!

There must be an audit trail for legislative and customer information purposes.

Lecture Content

The Key Business Tier Services

Having seen this simple example, we can straight away identify some key services provided to objects in the Business Tier:

Transaction Support

The atomic withdraw and deposit methods and the entities representing the two bank accounts have to be protected inside the transfer transaction.

Persistence

Security

Transparent resource location

Logging

Lecture Content

Business Tiers are Complex

What's Java's Solution?

The Application Programming Model

Application Programming Model

Components, Containers and Connectors

Components, Containers and Connectors

Java EE Architecture

Jave EE Architecture

EJB Components

EJB Container

Anatomy of an EJB

An EJB consists of a number of pieces, including the bean itself, some interfaces, and an information file. Everything is packaged into a special jar file.


Notes

Originally EJB relied heavily on interfaces and XML deployment descriptors. With the introduction of annotations to Java in Java SE 5, this has gradually changed.

EJB Operation

Types of EJBs

Entity Beans

Why So Complex?

How it works

How it works

Lecture Content

Developing an EJB

Remote interface for the DateHere EJB (EJB 2 version)

1| Example 1: Remote interface for the DateHereBean (EJB 2)
import java.rmi.*;
import javax.ejb.*;
 
package uk.ac.swan.atm42.ejb;
 
public interface TimeHere extends EJBObject {
  public String getTimeHere() throws RemoteException;
}

Remote interface for the DateHere EJB (EJB 3 version)

In EJB 3, the details can be left to the container: interface is a plain-old-Java interface annotated with javax.ejb.Remote.

1|Example 2: Remote interface for the DateHereBean (at-m42/Examples/lecture15/TimeHere.java)
extern> http://cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/TimeHere.java

The Home interface

The Home Interface Specification

  1. The Home interface must be public.
  2. The Home interface must extend the interface javax.ejb.EJBHome.
  3. Each create method in the Home interface must declare java.rmi.RemoteException in its throws clause as well as a javax.ejb.CreateException.
  4. The return value of a create method must be a Remote Interface.
  5. The return value of a finder method (Entity Beans only) must be a Remote Interface or java.util.Enumeration or java.util.Collection.
  6. Any object passed as an argument (either directly or embedded within a local object) must be a valid RMI-IIOP data type (this includes other EJB objects)
  7. In EJB 3 the Home interface is provided automatically by the container and you don't need to provide code.

Home interface for the TimeHere (EJB 2)

1|Example 3: Remote interface for the DateHereBean (at-m42/Examples/lecture15/TimeHereHome.java)
extern> http://cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/TimeHereHome.java

Business Logic

You can now implement the business logic. When you create your EJB implementation class, you must follow these guidelines:

  1. The class must be public.
  2. The class must implement an EJB interface (either javax.ejb.SessionBean or javax.ejb.EntityBean).
  3. The class should define methods that map directly to the methods in the Remote interface. Note that the class does not implement the Remote interface; it mirrors the methods in the Remote interface but does not throw java.rmi.RemoteException. - Define one or more ejbCreate() methods to initialize your EJB.
  4. The return value and arguments of all methods must be valid RMI-IIOP data types.

TimeHereBean (Session Bean) EJB 2 Version

1| Example 4: SessionBean implemented using EJB 2 conventions
// Simple Stateless Session Bean
// that returns current system time.
 
package uk.ac.swan.atm42.ejb;
 
import java.rmi.*;
import javax.ejb.*;
 
public class TimeHereBean implements SessionBean {
  private SessionContext sessionContext;
  //return time here  
  public String getTimeHere() {
    return new Date().toString();
  }  
  // EJB methods 
  public void ejbCreate() throws CreateException {}  
  public void ejbRemove() {}
  public void ejbActivate() {}
  public void ejbPassivate() {}
  public void setSessionContext(SessionContext ctx) {
    sessionContext = ctx;
  }
}

Version 3 EJBs

TimeHereBean (Session Bean) EJB 3 Version

1| Example 5: SessionBean implemented using EJB 3 conventions (at-m42/Examples/lecture15/TimeHereBean.java)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/TimeHereBean.java

Deployment Descriptor (EJB 2)

An XML file that describes the EJB component. Should be stored in a file called ejb-jar.xml.

1|Example 6: Deployment Descriptor for the TimeHereBean (not required in EJB 3 containers) (at-m42/Examples/lecture15/ejb-jar.xml)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/ejb-jar.xml

Deploying the EJB

The Client

1|Example 7: Client program for TimeHereBean (at-m42/Examples/lecture15/TimeHereClient.java)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/TimeHereClient.java
1| Example 7: Client program for TimeHereBean (at-m42/Examples/lecture15/TimeHereClient.java)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture15/TimeHereClient.java

Lecture Content

Is the Java Solution a Good Solution?

Lecture Summary


Home | Previous Lecture | Lectures | Next Lecture