Download presentation
Presentation is loading. Please wait.
1
Enterprise Java Beans
2
What Are EJB’s? Enterprise Java Beans
EJB: special kind of JavaBean for performing server-side business logic More powerful version of the regular beans
3
Where they fit in a system
5
Developing EJP
6
Create enterprise application project
10
Create your EJP
14
Put business logic into your EJP
25
Create servlet which will call your business logic
30
Define dependency between Servlet and EJP
35
Put controller logic into your servlet
38
Create JSP File
42
Fill JSP file with user interface code
45
Deploy and Run
51
What Are EJB’s? Enterprise Java Beans
EJB: special kind of JavaBean for performing server-side business logic More powerful version of the regular beans that we’ve used in class
52
Where they fit in a system
53
EJB’s in J2EE
54
EJB Container Functions as a runtime environment for EJB components beans Containers are transparent to the client in that there is no client API to manipulate the container Container provides EJB instance life cycle management and EJB instance identification. Manages the connections to the enterprise information systems (EISs)
55
EJB Container(cont’d)
Java Naming and Directory Interface, Enterprise Naming Context
56
EJB Class A bean has a single Java class at its core
This class is written by a developer if it’s a session bean This class is sometimes generated by a tool if it’s an entity bean Implements application-specific business logic Implements one of the following contracts: javax.ejb.EntityBean javax.ejb.SessionBean These contracts provide for consistent behavior when activating beans, passivating beans, reading data, writing data Every container can expect these methods in every bean
57
Three kinds of EJB’s Session
associate client information with a specific client both stateless and stateful versions Entity groups associated information in an abstraction that provides transaction support Message Bean - rarely used, hardly supported
58
What is a Session Bean? Represents a single Client inside the J2EE server one client at a time/ not persistent when the client terminates, the session bean is disassociated from the client There are two types: Stateful and Stateless...
59
Stateful These represent a set of interactions between client and server. Example: shopping cart Saves information over several method invocations. There is a lot of overhead associated with using stateful beans
60
Stateless Beans A stateless bean does not save information between method calls. Limited application Little overhead multiple clients can use the same bean instance without alteration Example: fetch from a read-only database or send a confirmation for an order
61
Entity Beans Associates pieces of information in a group
Accessed by multiple clients at a time Persistent and Serializable The container loads and stores the entity beans in the database These are more similar to regular beans
62
More on Entity Beans Transactions: this is what makes an Entity Bean special. Entity beans rely on the container to enforce robust transactions example: Airline booking: if the flight booking action fails, then the credit card charge action fails, or vice versa.
63
Persistence in Entity Beans
Container managed persistence the container controls when the bean is read from or written to the database Bean managed persistence the bean’s implementation performs all of the sql operations that loads, stores, and updates the bean’s data to or from the database. Bean is responsible for connection allocation to the database
64
Connection Pooling Setting up connections to the database is resource intensive Connection pooling maintains a pool of database connections for the entity beans so that the connection is maintained when a bean finishes, and is available for other entity beans. Specific to database and EJB container implementation
65
Message Beans A message bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS message listener, which is similar to an event listener except that it receives messages instead of events. Many systems do not yet support JMS, message bean use is currently not widespread
66
Using an Entity bean from a Session bean
An entity bean can be shared by multiple sessions. This allows for data encapsulation; clients can interact with data via session beans within transaction boundaries. Can do all database interaction from session bean as an alternative encapsulation is weakened
67
Using EJB’s
68
An EJB Example... Online Banking Application
Demonstrates how all the component technologies--enterprise beans, J2EE application clients, and Web components fit together
69
Online Banking Application
Two clients: a J2EE application client used by administrators to manage customers and accounts Web client used by customers to access account histories and perform transactions. The clients access the customer, account, and transaction information maintained in a database through enterprise beans.
70
Online Bank Application Overview
71
Session beans used The online bank application has three session beans: AccountControllerEJB, CustomerControllerEJB, and TxControllerEJB. These session beans provide a client's view of the application's business logic. Hidden from the clients are the server-side routines that implement the business logic, access databases, manage relationships, and perform error checking.
72
Entity Beans used For each business entity represented in our simple bank, the bank application has a matching entity bean: AccountEJB, CustomerEJB, TxEJB The purpose of these beans is to provide an object view of these database tables: account, customer, and tx. For each column in a table, the corresponding entity bean has an instance variable. Because they use bean-managed persistence, the entity beans contain the SQL statements that access the tables. For example, the create method of the CustomerEJB entity bean calls the SQL INSERT command.
73
Database
74
JAR FILE Packaging EJB Components
An EJB application and its various components are deployed and distributed in the form of packages. The process of packaging: Enables you to handle and use multiple files related to one EJB component, simultaneously. Saves disk space by compressing files. The EJB components of an EJB application are packaged into Java Archive (JAR) files and the Web components are packaged into Web Archive (WAR) files.
75
The components of an enterprise bean are packaged as an ejb-jar file.
The various component files that are packaged into an ejb-jar file are: Bean class file Remote interface file Local interface file Local home interface file Home interface file Deployment descriptor file
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.