0% found this document useful (0 votes)
55 views24 pages

J2Ee Part 2: Enterprise Javabeans

This document provides an overview of Java Enterprise Edition (JEE) Part 2, which describes Enterprise JavaBeans (EJB). It discusses the EJB container, interfaces, entity and session beans, persistence, and deployment. The key points are that EJBs use interfaces to define business logic, entity beans represent data objects while session beans represent processes, and the container manages transactions and persistence.

Uploaded by

satyanarayana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views24 pages

J2Ee Part 2: Enterprise Javabeans

This document provides an overview of Java Enterprise Edition (JEE) Part 2, which describes Enterprise JavaBeans (EJB). It discusses the EJB container, interfaces, entity and session beans, persistence, and deployment. The key points are that EJBs use interfaces to define business logic, entity beans represent data objects while session beans represent processes, and the container manages transactions and persistence.

Uploaded by

satyanarayana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

J2EE Part 2:

Enterprise JavaBeans
CSCI 4300
Images and code samples from jGuru EJB tutorial,
[Link]
EJB container
• Created by an
application server
program
• We use SUN
Application Server on
[Link]
• Must write EJB to
specified interfaces
EJB Interfaces
• Client: a Java
program (servlet,
bean)
• Home interface: local
object
• Remote interface:
access the actual
EJB, possibly across
a network
EJB Interface example
• CustomerHome home = // ...
• // Use the home interface to
create a new instance of
the Customer bean.
• Customer customer =
[Link](customerID);
• // using a business method
on the Customer.
• [Link](someName);
Entity beans represent data
objects:
import [Link];
import [Link];

public interface Customer extends EJBObject {


public Name getName() throws RemoteException;
public void setName(Name name) throws
RemoteException;
public Address getAddress() throws RemoteException;
public void setAddress(Address address) throws
RemoteException;
}
Session Beans represent business
processes:
public interface HotelClerk extends EJBObject
{ public void reserveRoom(Customer cust,
RoomInfo ri, Date from, Date to)
throws RemoteException;
public RoomInfo availableRooms( Location loc,
Date from, Date to)
throws RemoteException; }
An Entity Bean class
• The Bean class actually
implements the
EntityBean interface
(business logic)
• For example, maintains a
database connection for
customer info
• Client reads and writes
the bean, and does not
need to do DB access
EJB lifecycle methods (home
interface)
public interface CustomerHome extends EJBHome {
public Customer create(Integer customerNumber)
throws RemoteException, CreateException;
public Customer findByPrimaryKey(
Integer customerNumber)
throws RemoteException, FinderException;
public Enumeration findByZipCode(int zipCode)
throws RemoteException, FinderException;
}
-- these return instances of Customer, the remote interface
Stub and Skeleton Methods

• Stub method on local system represents the


remote object
• Skeleton method on remote system represents
the local client
Container-Managed Persistence
• Persistence: arranging that data stored
will be available in a later session
• Container-Managed Persistence: EJB
container automatically saves EntityBean
contents to a database and restores on
demand
• Developer writes no DB code!
• Easiest for developer, hardest for EJB
container
EntityBean creation code
EntityBean business logic
EntityBean Callback methods
Customer Data Members
Serializable objects
• Serializable: an object can be saved to a string and
correctly restored from the string
• A class whose data members are primitive values is
automatically serializable
• Classes that use trees, etc. can be made serializable:
Automatically generated SQL for
this EntityBean:
Bean-Managed persistence
The entity bean itself must contain the DB
code to:
• Store the bean data contents into the
database
• Restore the bean from its stored contents
These methods invoked as callbacks from
the EJB container
Stateless Session Beans
• Represent business processes (transactions)
• Contain no persistent data
• Shared among multiple clients
Acme SessionBean creation

• JNDI: Java Directory and Naming Interface (find


objects in a networked environment)
• InitialContext: provided by EJB container, gives
JNDI access
Acme SessionBean operations

• Normally, we would open an output stream and


write the request to the server!
EJB Descriptor
Assembly descriptor
EJB Deployment
The EJB jar file contains:
• Home interface class
• Remote interface class
• Bean implementation class
• META-INF/[Link]
Then, drop it into the JBOSS deploy
directory!
WAR and EAR files

Buildfile source:
[Link]

You might also like