Enterprise Javabeans 2 1 1St Edition Stefan Denninger
Enterprise Javabeans 2 1 1St Edition Stefan Denninger
com
https://ebookgate.com/product/enterprise-javabeans-2-1-1st-
edition-stefan-denninger/
OR CLICK HERE
DOWLOAD NOW
https://ebookgate.com/product/pediatric-palliative-care-1-auflage-
edition-stefan-j-friedrichsdorf/
ebookgate.com
https://ebookgate.com/product/understanding-enterprise-
soa-1-illustrated-edition-edition-eric-pulier/
ebookgate.com
https://ebookgate.com/product/progress-in-responsible-tourism-
vol-2-1-volume-2-issue-1-1st-edition-harold-goodwin/
ebookgate.com
https://ebookgate.com/product/enterprise-resource-planning-1-ed-
international-ed-edition-mary-sumner/
ebookgate.com
Knowledge Management 2 0 Organizational Models and
Enterprise Strategies 1st Edition Imed Boughzala
https://ebookgate.com/product/knowledge-management-2-0-organizational-
models-and-enterprise-strategies-1st-edition-imed-boughzala/
ebookgate.com
https://ebookgate.com/product/storytown-rolling-along-
level-2-1-grade-2-1st-edition-hsp/
ebookgate.com
https://ebookgate.com/product/enterprise-2-0-social-networking-tools-
to-transform-your-organization-1st-edition-jessica-keyes/
ebookgate.com
https://ebookgate.com/product/the-little-sas-book-for-enterprise-
guide-4-2-1st-edition-susan-j-slaughter/
ebookgate.com
https://ebookgate.com/product/python-2-1-bible-1st-edition-dave-
brueck/
ebookgate.com
Enterprise
JavaBeans 2.1
STEFAN DENNINGER and INGO PETERS with ROB CASTANEDA
translated by David Kramer
All rights reserved. No part of this work may be reproduced or transmitted in any form
or by any means, electronic or mechanical, including photocopying, recording, or by
any information storage or retrieval system, without the prior written permission of
the copyright owner and the publisher.
ISBN 978-1-59059-088-1 ISBN 978-1-4302-0771-9 (eBook)
DOI 10.1007/978-1-4302-0771-9
Trademarked names may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, we use the names only in an editorial
fashion and to the benefit of the trademark owner, with no intention of infringement
of the trademark.
Translator, Editor, Compositor: David Kramer
Technical Reviewer: Mary Schladenhauffen
Editorial Directors: Dan Appleman, Gary Cornell, Simon Hayes, Martin Streicher,
Karen Watterson, John Zukowski
Managing and Production Editor: Grace Wong
Proofreader: Lori Bring
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
The information in this book is distributed on an "as is" basis, without warranty.
Although every precaution has been taken in the preparation of this work, neither the
author nor Apress shall have any liability to any person or entity with respect to any
loss or damage caused or alleged to be caused directly or indirectly by the information
contained in this work.
Contents at a Glance
Acknowledgments x
Preface xl
1 Introduction 1
2 Fundamentals 7
4 Session Beans 63
7 Transactions 277
8 Security 323
References 457
Index 459
Contents
Acknowledgments x
Preface xi
1 Introduction 1
A Hypothetical Scenario . 1
First the Bad News . 1
TheTask . . . . . . . . . 1
The Solution . . . . . . . 2
Multiple-User Capability 3
Scalability . . . . . . . . 3
Availability. . . . . . . . 3
Connection with the Outside World 4
Integration with Other Applications and Rapid Extensibility. . 4
Short Development Cycles . . . . . . . 4
Configurability . . . . . . . . . . . . . 5
Stepwise Migration and Data Storage . . 5
Summary .. 5
So Now What? . 6
2 Fundamentals 7
Enterprise . 7
Java . 11
Beans . . . 13
4 Session Beans 63
Introduction . 63
Concepts . . . 64
Programming 75
Examples ·. 97
7 Transactions 277
Fundamentals . .......... 277
Concepts . . . . . . . . . . . . . . 280
Implicit Transaction Management 286
Explicit Transaction Management 305
Transactions in the Deployment Descriptor 319
8 Security 323
Introduction . ..... 323
Programming .. . .... 326
vi
Contents
References 457
Index 459
vii
About the Authors
Stefan Denninger
Stefan Denninger completed his university education in February 1996 with
a degree in business management. He has worked as a software engineer
for Kromberg & Schubert in Abensberg, Germany, IXOS Software in Munich,
Germany, and eCircle Solutions in Munich. He currently works for ConSol GmbH
in Munich as a senior software consultant.
Ingo Peters
Ingo Peters currently works with the HypoVereinsbank, a group of European
banks managing Internet portals and applications. As a project manager, he
has guided many different applications and Internet portals using Enterprise
JavaBeans to success. He started programming with Enterprise JavaBeans in 1998.
Rob Castaneda
Rob Castaneda is Principal Architect at CustomWare Asia Pacific, where
he provides architecture consulting and training in EJB/J2EE/XML-based
applications and integration servers to clients throughout Asia and America.
Rob's multinational background, combined with his strong real-world business
experience, enables him to see through the specifications to create realistic
solutions to major business problems. He has also contributed to and technically
edited various leading EJB and J2EE books.
Acknowledgments
Working on this book has been a great pleasure for all of the authors. Long
discussions about local interfaces and dependent objects have resulted in
several chapters being rewritten and then rewritten again, and changes in the
specification have led to many interesting discussions and insights.
Without the active support of colleagues and friends, work on this book would
not have been nearly so interesting, nor so productive. Stefan Denninger and
Ingo Peters would like particularly to thank Stefan Schulze and Alexander Greisle,
whose constructive and highly competent feedback have significantly improved
the quality of this book. They would also like to thank the readers of the first
German edition, whose support and feedback made the second edition possible.
Finally, they wish to thank their editor, Martin Asbach, of Ad dison-Wesley, for his
great care and friendly collaboration in bringing this book into the world, to the
staff of Apress for making the English translation possible, and for their amiable
and uncomplicated collaboration.
Rob Castaneda would like to thank John Zukowski, Grace Wong, and the team
at Apress, as well as colleagues at CustomWare Asia Pacific, including Ian Daniel,
Nathan Lee, and Scott Babbage, as well as his wife, Aimee Castaneda. Without the
support of the these individuals, this work would not have been achievable.
Preface
ENTERPRISE IAVABEANS (BIB) IS THE standard component architecture for the
creation of distributed business applications in the programming language
Java. EJB offers all mechanisms necessary for the creation of applications for
enterprise-wide deployment and for the control of critical business processes.
Application developers can profit from distribution of processes, transaction
security, pooling of network connections, synchronous and asynchronous
notification, multithreading, object persistence, and platform independence.
With EJB, programming remains relatively simple.
In March 1998 the first specification of Enterprise JavaBeans was published
by Sun Microsystems. In relatively short order there followed in December 1999
the consolidated version 1.1. In the meantime, the component architecture has
accounted for considerable change in the market for application servers, so
that today, the large majority of application servers support EJB. EJB has also
established itself in the growing market for finished application components.
Today, there exists a large market for everything from specialized solutions to
specific problems to complete application frameworks.
In August 2001 version 2.0 was released. The new version offers considerable
extensions and improvements, which are considered in this book, now in its
second edition. The first edition has been greatly revised in order to take account
of the following developments:
• The new message-driven beans (EJB 2.0) offer completely new ways to
achieve asynchronous communication and parallel processing of business
logic. This is made possible by the integration of the Java Message Service
(JMS) into tht EJB architecture.
• Local interfaces (EJB 2.0) enable optimization of process-internal
communication among Enterprise Beans and between local clients and
Enterprise Beans.
• The persistence manager has been introduced (EJB 2.0). With relationships
between entity beans it is now possible to model complex data structures.
The associated query language EJB QL makes it possible to work efficiently
with these structures.
• A new chapter (Chapter 8) deals with security issues of EJB.
• The chapter on practical applications (Chapter 9) has been greatly
expanded.
• All the examples have been reworked, with emphasis on ease of execution.
Preface
Today, one may safely state that Enterprise JavaBeans has brought the
success of the programming language Java to the server, particularly in the
areas of portals and integration of older applications, where EJB has become a
widely used solution strategy. However, information technology is on the verge
of yet new changes. The trend today is in the direction of freely combinable
application components from a variety of producers that are connected via
web services. EJB 2.0 offers answers to these growing requirements. Particularly
the new developments in the areas of marketplaces, private stock exchanges,
e-procurement, and electronic funds transfer can profit from using EJB as the
base architecture.
This book is directed to the reader who wishes to learn more about
Enterprise JavaBeans. It discusses the fundamental concepts underlying the EIB
architecture. Building on this foundation, it explains the technical details and
concrete programming of Enterprise Beans. Many examples are used to clarify
and expand on the concepts introduced. The source code for all the examples
in this book is available at http://www.apress.comin the "Downloads" section.
A knowledge of the Java programming language and a basic understanding of
distributed programming are prerequisites for reading this book.
xii
CHAPTER 1
Introduction
A Hypothetical Scenario
Imagine that you are an application programmer working for a midsize firm in the
automobile industry that maintains numerous offices in a number of European
countries. Your firm is pursuing the strategy of developing its own business
applications in house. At first glance such a strategy may seem rather odd. But
extreme competition and increasing cost pressures now demand a high level of
flexibility and stability from the development team, and your division leader has
guaranteed that the software systems developed will have these characteristics,
and this is the justification for management's decision to support in-house
development.
Up to now each office has installed and maintained its own software system,
since the development teams in each branch have been working independently
of one another.
The Task
Your job is to develop a prototype for this new system, which after an evaluation
phase is to be further developed into a stable building block of the new system.
Chapter 1
The Solution
A superficial reading of the above text could easily lead one to the conclusion that
the task as set out should give little trouble to an application developer who is
an expert in business applications. But if one reads more closely, a rather more
complex pictwe begins to present itself (see Figure 1-1). The crux of the problem
is in the new set of circumstances that confront ow application specialist. These
altered circumstances bring problems that will complicate the development of a
prototype of a rudimentary accounting system. Let us examine the situation more
closely in terms of the following observations.
Easy Extensibility
Stepwise Migration
~_.;",."""",~ ~
~I ~ Multiuser Capability
~---::
Data Storage
Business Scalability
Configurability
Problem Usability
2
Introduction
Multiple-User Capability
The accounting system, which until now has been conceived as an isolated
solution, must now be integrated into a larger system and enable a number
of users to work simultaneously. For this the system must satisfy the following
requirements:
• transactions,
• user control,
• security mechanisms,
• networking capability.
A further consideration is the necessity of ensuring that the requirements
listed above are standardized and consistent among all modules of the system.
This is a very important requirement to consider. It is often overlooked because it
does not directly map to any user requirements, and it becomes a critical factor in
working with remote development teams.
Scalability
To accommodate an increase in the number of employees the system must be
scalable. If the previously available resources become overtaxed, then it must be
possible to expand the software to include additional resources. This goal results
in a distribution of the applications among several servers usually located within
a cluster. The system should then (possibly after a reconfiguration) make use of
the new resources and thus offer improved performance without the occurrence
of bottlenecks. It is important that the reconfiguration and redeployment of an
application be flexible and not require major source code modifications and
recompilation. Rigid designs that require that source code modifications be made
in reconfiguring and redeploying the system reduce the system's flexibility and
increase the burden on the system administrator.
Availability
In general, but most importantly at critical junctures such as end of quarter
or year end, the system must offer a high degree of availability. If a computer
becomes unavailable, then another computer must be able to take over the
requisite functions without a great deal of effort (or perhaps none at all) in
reconfiguring the system. This requires that the system be capable of transferring
functional units from one computer to another.
3
Chapter 1
4
Introduction
Configurability
If applications that are developed in one location are to be usable at another (just
think of differences in national laws, languages, notation, and on and on), then
there must be a high degree of configurability, so that the applications can be
adapted without the necessity of being recompiled. As a further alternative one
might imagine (thinking again of the building-block approach) replacing building
blocks that cannot be implemented at a particular location by location-optimized
building blocks.
Summary
The number of considerations that are required in order to produce the solution to
our problem can easily exceed the capabilities of a normally endowed application
developer. However, today a number of software companies offer solutions to
developers that provide ways of overcoming the problems inherent in a project
such as the one that we have described, and a great deal of the thought and design
required to handle the issues listed above have been collected into a number of
industry standard platforms. This book discusses one of these platforms in great
detail: Enterprise JavaBeans (or BJB for short). So wake up and smell the coffee,
and let's get started.
5
Chapter 1
So Now What?
In Chapter 2 we discuss the fundamentals of Enterprise JavaBeans and place
them in the context of the technologies for software development. In Chapter 3
we devote our attention to the fundamental architecture of Enterprise JavaBeans
as well as the roles that the development team can play during the development,
deployment, and management stages of the system. The different varieties of
components (known as beans), namely, entity, session, and message-driven beans,
are discussed in Chapters 4, 5, and 6. Building on this we go on in Chapter 7 to
discuss the topic of transactions, while Chapter 8 is devoted to security. In each
of these chapters extensive examples are introduced to clarify the discussion. In
Chapter 9 we discuss several aspects of the practical application of the principles
discussed (again with extensive examples). Finally, in Chapter 10, we discuss web
services and the integration of Enterprise JavaBeans to other platforms that exist
within common enterprises.
After you have read this book you should have a firm grasp of the capabilities
of the Enterprise JavaBeans platform. Furthermore, you should be in a position to
translate the knowledge you have gained from theory into practice.
6
CHAPTER 2
Fundamentals
Enterprise
The programming language Java is known primarily for two features: its platform
independence and its ability to beautify web pages by means of applets. However,
Java has many capabilities to offer above and beyond the decoration of web pages.
Java is a full-fledged object-oriented programming language that is increasingly
being used for the development of enterprise-critical applications. As Figure 2-1
shows, Enterprise JavaBeans is a building block in the product and interface
catalog of Sun Microsystems for the development of enterprise applications.
In the figure, J2EE stands for java 2 Platform, Enterprise Edition, JSP for
javaServer Pages, and EJB for Enterprise javaBeans.
Enterprise JavaBeans is not a product, but merely a specification. Any
individual who feels the calling may bring to market an implementation of the
Enterprise JavaBeans specification.
That Enterprise JavaBeans involves a client-server architecture should be no
cause for wonderment (Sun has positioned Enterprise JavaBeans in the domain.
of server-side applications logic. Three-tiered architecture is currently the one
favored by most system architects (the trend is in the direction of multitiered, or
multilayered, architectures).
Three-tiered systems are distinguished in that the actual program logic (in
relation to enterprise applications often called "business logic") is located in the
middle layer (on an application server); see Figure 2-2.
Application Layer
(Middleware)
The bundling of the application logic on its own server in a layer between
the clients and the database offers the following advantages over traditional
two-tiered systems:
• The client programs become significantly smaller (and therefore are
often called "thin clients") and thus require fewer resources of the client
computer.
• The database is transparent to the client developer. The middle layer
(application layer) is completely abstracted from access to the data and
8
Fundamentals
(Single-Layer)
Systems
(Two- Layer)
Systems
(Three-Layer)
Systems
(n-Layer)
Systems
== - - - - --- - -
1 Number of Users n
9
Chapter 2
Economic Viability
Economic viability refers to the domains of development, acquisition, main-
tenance, and adaptation. Economic viability in development exists when the
technology actively supports a shortening of the development cycle. An increase
in productivity thus leads to reduced costs, which can then be passed along (this
is what economic viability in acquisition means to nondevelopers). Economic
viability in maintenance is the result of stability, which results in lower servicing
requirements. Economic viability as it relates to further development and adap-
ation is offered by a technology that enables a system to be extended or adapted
without great expense and risk.
Security
The question of security must be examined with extreme care. In relationship to
an investment, such security exists if the technology promises a certain minimum
life span and is assured of long-term support. Security also refers to security
against breakdown, that is, to availability. Its purpose is to avoid costs due to
failure in parts of the system or to system breakdowns. Security means as well the
capability of a technology to protect sensitve data from prying eyes and to protect
the system from unwelcome intruders.
Requirements
The deployment of a particular technology is justified only at the point where
there is a requirement for the capabilities that it offers. An enterprise will not
institute a technology or product merely on account of its current popularity
without experiencing a genuine need.
10
Fundamentals
In the following chapters this book will lay out in detail how the Enterprise
JavaBeans specification attempts to deal with the requirements of modem
enterprises for a stable system.
Java
Object Orientation
Java is an object-oriented programming language, and thus it offers the developer
the advantages of object-oriented techniques. Java is also well equipped for the
next step, namely, in the direction of component-oriented software development,
for which object-oriented technologies are the best starting point (more on this in
the section "Beans."
Platform Independence
Many enterprises find themselves confronted with the problem of a heteroge-
neous hardware and software landscape that can lead to almost insuperable
difficulties. Many software systems are available only for specific platforms.
Java source code is translated by the Java compiler not into machine code, but
into machine-neutral byte code, which is then interpreted by a Java run-time
environment. Therefore, applications that are developed in "pure" Java can
run on all platforms for which a Java run-time environment is available. The
run-time environment is platform-dependent and provides the Java program
an implementation of abstract interfaces for system-dependent operations (for
example, for access to file systems, access to network interfaces, and the display
of graphical interfaces). Java applications offer an enterprise increased security
and continuity through their platform independence.
11
Chapter 2
Dynamics
As an interpreted language Java provides the capability of loading byte code
either from the local file system or over a network into the address space of a
process and from this to generate objects at run time (that is, program segments
can be reloaded at run time, even over a network). Thus the stony path of rigid,
inflexible systems is smoothed into dynamic run-time systems with a high degree
of adaptability, and a contribution as well to greater flexibility and continuity.
Java classes can be examined at run time (reflection). Methods can be called
dynamically, attributes recognized and modified, and so on. With increasing
support for Java in database systems (Oracle, for example), groupware systems
(such as Lotus Notes), web servers (via Servlet API and JavaServer Pages), and
browsers there are numerous possible combinations for system development.
Even the linkage with other platform-independent technologies such as XML
offers interesting perspectives. Thus in version 1.1 of the EJB specification
XML replaces serialized classes as deployment descriptors (more details on
deployment descriptors in Chapter 3).
Stability
The Java programming language is relatively easy to learn (compared, for
example, to C++) and less subject to programming errors to the extent that certain
language features (such as pointers to variables and functions) are absent, in
favor of a consistent object orientation. Since it is platform-independent, to
the extent to which the system in question has been developed in pure Java, no
porting is necessary. Thus the possibility of porting errors does not arise. Since
Java is an interpreted language, serious run-time errors (such as access to invalid
object references, null pointers) do not lead to uncontrolled system crashes. nie
program is terminated in a controlled manner by the run-time environment.
Thus critical errors can be located and fixed more rapidly.
Security
Java supports security through the features of the language. Thus direct access to
memory by means of pointers is forbidden, stack overflow and exceeding array
bounds are trapped and reported as an error in the form of an exception, and so
on. Java also supports the sandbox concept, which has application p~arily to
applets.
12
Fundamentals
Performance
The advantages that Java gains from the properties of an interpreted language
must be paid for with performance limitations. Although much has been done to
improve Java's performance (for example, by just-in-time compilation), execution
speed remains a critical point (in complex client applications as well as in
server applications). Through continual improvement in hardware and the Java
run-time environment this problem has perhaps become less severe. However,
until Java reaches the execution speed of a compiled language, there will remain
the necessity of developmental work in the area of virtual machines.
Beans
When speaking about Sun Microsystems and components, the talk is always
about beans. The currently most popular component of Java is most likely
JavaBeans. Before we go into the difference between JavaBeans and Enterprise
JavaBeans, we need to dive briefly into the world of componentware, without
wishing to get involved in a full-blown discussion of the component paradigm.
There are numerous books about components that show the variety of ways that
this topic can be addressed. Here, however, we shall merely take a glance at the
topic (which plays an important role with respect to Enterprise JavaBeans) in
order to increase our understanding a bit.
In order to avoid misunderstandings we should mention explicitly that the
intention of this book is not to give ,the reader instructions in how to develop
good components. This book describes the component architecture of Enterprise
JavaBeans, their practical application, and the requirements that components
must fulfill if they are to be deployed in an EJB server.
13
Chapter 2
Software Components
We would like to offer a definition of software components, cited in [6] as well as
in [17], that represents a relatively neutral middle ground between the very broad
and the very narrow:
• As a rule, objects are not big enough to deal with a complete task from
beginning to end. They serve more for structuring and mapping to models.
• A component can be used only in a particular way that has been defined
by the public interface. Objects can, by the process of derivation, be altered
(almost) at will.
14
Fundamentals
• Objects also offer the concept of the interface, which as a rule, however,
is narrowly coupled to the underlying system technology and thus limits
interoperability.
Undoubtedly, the close relationship between objects and components is
clear. The object-oriented approach and techniques thus seem to offer the best
basis for the development of components and component-oriented software.
A fundamental concept of the component paradigm is that of the interface.
The interface of a component is a sort of contract whose conditions the
components are obligated to fulfill. It is an interaction point with the components,
documenting their features and capacities. A component can have several
interfaces. Each interface represents a service provided by the component (for a
detailed discussion of interfaces see, for example, [33)). Chapter 3 will show in
detail how this aspect of components is transplanted into Enterprise JavaBeans.
An advantage of component-oriented software development is (as mentioned
previously) in the reusability of cod~. A further advantage is the possibility, with
the aid of completed components, of rapidly developing application prototypes
(for an extensive treatment of this see [9)). The early availability of a prototype
means that in the early stage of development one is already able to confront
design choices; (pilot) customers or (pilot) users can be brought into the
development process at an earlier stage, and so on. The reuse of code in the form
of (mature) software components can lead to a shortening of development cycles
and savings in development costs.
15
Chapter 2
Component Architecture
As mentioned above, Enterprise JavaBeans is a component architecture. The
domains of application and variety of forms of a component architecture can
be quite diverse. Enterprise JavaBeans represents a quite particular variant: a
component architecture for distributed, server-side, and transaction-oriented
components. Thus Enterprise Beans are components that provide services
to many clients on a single server. Without a framework that embeds the
components into a sort of run-time environment and provides them necessary
services, each component that is to be made available over a network would have
to have its own server. This would make the development of such components
much more difficult and if several components were deployed on one computer
would result in an unnecessary strain on its resources. Even the reusability of a
component could thereby become endangered, since servers must frequently
be matched to the underlying platform. A component architecture such as
Enterprise JavaBeans makes possible the deployment of components for
distributed applications without the components themselves being significantly
affected (see Figure 2-5).
o Communications Point
Figure 2-5. Example ofcomponent architecture.
16
Fundamentals
17
Chapter 2
18
Fundamentals
This bean class is not derived from any class. It does not implement any
standard interface, and is nevertheless a valid JavaBean (only visible JavaBeans
must be derived from java.awt.Component). It simply follows the naming
conventions established in the specification. It has the property a Property, which
can be manipulated and read by the methods setAProperty and getAProperty.
Since it implements the interface AEventListener, it can react to the event
AEvent. It triggers the event BEvent, for which other beans can register via
addBEventListener and unregister via removeBEventListener. By exchanging
events beans can pair with one another dynamically, since they can register and
unregister for particular events at run time. This coupling over events is also a
loose coupling, since the bean is abstracted from the actual type by means of the
corresponding Listener interfaces.
With the naming convention (type) get (property) , void (property) ((type)),
implements (EventType)Listener, void add (EventType)ListenerO, and void
remove(eventTypeListener)O, etc., a builder tool can, for example, analyze
(introspection) the bean with the help of the Java Reflection API with respect to its
properties and the possibility of binding it to events. The tool can place the user
in a position to manipulate the bean visually. Thus the JavaBeans specification
concentrates essentially on the description of the program interface for:
19
Chapter 2
20
CHAPTER 3
The Architecture of
Enterprise JavaBeans
They contain the application logic used by the client programs. Enterprise
Beans reside in an EIB container, which makes a run-time environment available
to them (so that, for example, they can be addressed by client programs via
the home and remote interfaces and have the possibility of communication
among one another via the local home and local interfaces, so that life-cycle
management can be provided). The EJB container is linked to services via the
standard programming interface, services that are available to the bean (for
example, access to databases via JDBC, access to a transaction service via rrA,
and access to a message service via JMS). The EJB container is installed (possibly
in addition to other containers) in an application server.
We shall now go into the details of the individual components of the
architecture and their interrelationships.
The Server
The server is the fundamental component of the EJB architecture. Here we are
deliberately not speaking of an EIB server. Actually, it should be called a I2EE
server. Sun Microsystems' strategy in relationship to enterprise applications
in the framework of the J2EE platform involves Enterprise JavaBeans to a
considerably greater extent in the full portfolio of Java-based programming
interfaces and products than was the case in version 1.0 of the Enterprise
JavaBeans specification.
The specification of Enterprise JavaBeans in version 2.1 does not define any
sort ofrequirement on the server Oust as in versions 1.0 and 1.1). The reason for
this is presumably their stronger integration into the Java 2 platform, Enterprise
Edition (see Figure 3-2).
A J2EE-conforming server is a run-time environment for various containers
(of which one or more can be EJB containers). Each container, in turn, makes
a run-time environment available for a particular type of component. Creators
of Java application servers tend more and more to support the J2EE platform.
There is scarcely a producer who offers a pure EJB server. Many suppliers of
databases, transaction monitors, or CORBA ORBs have meanwhile begun to
support Enterprise JavaBeans.
In the environment of the J2EE platform (and thus indirectly in the EJB
architecture) the server component has the responsibility of providing basic
functionality. This, includes, for example:
• Thread and process management (so that several containers can offer their
services to the server in parallel);
• Support of clustering and load sharing (that is, the ability to run several
servers cooperatively and to distribute client requests according to the load
on each server to obtain the best-possible response times);
22
The Architecture ofEnterprise JavaBeans
--
B"--··
,,-
......
- • .....
Information
System
~
23
Chapter 3
• The API ofJAXR and JAX-RPC 1.0 (Java XML Remote Procedure Calls);
A provider of a Java application server may offer additional services via the
standard interface. Some producers offer, for example, a generic service interface
particular to the producer by means of which specially developed services (such
as a logging service or user management) can be offered. If an Enterprise Bean
uses such proprietary services, then it cannot simply be placed in any available
container.
The EJB container provides Enterprise Beans a run-time environment,
and also offers the Enterprise Beans particular services at run-time, via the
above-mentioned (static) programming interfaces. We now would like to examine
the most important aspects of both domains (that of the run-time environment
as well as that of provided services).
24
The Architecture ofEnterprise JavaBeans
25
Chapter 3
Bean on another computer is not essentially different for the client from the use
of objects that are located in the same address space.
For distributed communication between the various parties, Java Remote
Method Invocation (Java RMI) is used. To achieve interoperability among applica-
tion servers supplied by different manufacturers the EJB specification prescribes
support for the communications protocol of the CORBA specification, IIOp, for
an EJB container that conforms to specifications. Distributed communication
thus takes place over the protocol RMI-IIOP (RMI over IIOP). In no case does the
developer of an Enterprise Bean have to worry about the bean being able to be
accessed from outside. This is the sole task of the EJB container.
This book assumes that the reader is already familiar with the techniques of
remote method invocation (or else see [13] and [4] for information on RMI). In
particular, the reader should understand the notions of stub and skeleton.
Since version 2.0 of the Enterprise JavaBeans specification the client has had
the ability to communicate with an Enterprise Bean via the Local interface. In
many applications it is necessary that Enterprise Beans, all of which are installed
in the same EJB container (aggregation of components), communicate with one
another. In version 1.1 of the EJB specification this means a remote call to a
component located in the same address space. The overhead of the RMI protocol
is unnecessary, and it leads to a degradation of performance. The advantage of
using local interfaces is that RMI is thereby completely ignored. Local interfaces
can then be sensibly used only if client and Enterprise Bean are located in the
same address space of a Java virtual machine. The location of the Enterprise Bean
is thus no longer transparent to the client. Transparency of location applies only
to EJB components that are called over the remote interface. Furthermore, the
semantics of a method call to a component are altered when a local interface is
used. With calls to the local interface, parameters are passed via call by reference,
while calls to the remote interface use call by value.
The various chapters on various types of beans will deal extensively with the
difference between the remote and local interfaces and will delve deeply into the
viewpoint of the client with respect to an Enterprise Bean.
26
The Architecture ofEnterprise ]avaBeans
Persistence (Service)
The EJB container provides the beans, via the naming and directory services,
the possibility of accessing database connections. Beans can thereby themselves
ensure that their state is made persistent. However, the specification of Enterprise
JavaBeans provides for a mechanism by which the state of certain Enterprise Bean
types can be made persistent automatically. (We shall return to this mechanism
in Chapter 5, "Entity Beans.")
As a rule, in the case of automatic storage of the state of Enterprise Beans by
the EJB container the data are made persistent in a database. One can imagine
other EJB containers that provide persistence mechanisms that place the data
in other storage systems (for example, in the file system or electronic archives).
There is also the possibility of developing EJB containers that make use of the
interfaces of other application systems in order to read or write data from or to
that location. Thus, for example, the data in an old main-frame system can be
bound by means of special EJB containers to component-oriented systems (the
container then acts to a certain extent as a wrapper for the old systems).
However, what is really at issue is that in the case of automatic persistence of
an Enterprise Bean, the bean couldn't care less where the data are stored. The EJB
container takes on the task of ensuring that the data are stored and remain in a
consistent state. Thus a particular bean can be installed in various EJB containers
that support varying storage systems as persistence medium. For the Enterprise
Bean the persistence remains transparent. It doesn't know where its data are
stored or where the data come from that the EJB container uses to initialize it.
27
Chapter 3
Message (Service)
With version 2.0 of the specification of Enterprise JavaBeans the EJB container
is obligated to integrate a message service via JMS-API (Java Message Service).
With the definition of a new bean type-the message-driven bean-the message
service is integrated into the EIB container in a significant way. The development
28
The Architecture ofEnterprise JavaBeans
29
Chapter 3
30
The Architecture o/Enterprise JavaBeans
plays no role when the Enterprise Bean itself looks after persistence or when the
components possess no persistent data.
In most cases a database is used for storing data. In spite of the ANSI SQL
standard the databases of different producers are not one hundred percent
compatible with one another. For example, they use different key words in the
syntax of their query languages. It is usual that particular database functions
that distinguish one database from those of other producers are usable only
with proprietary extensions of the standard query language SQL. The persistence
manager is supposed to catch these difficulties as well. Depending on the
implemented database, a specialized persistence manager can be used that is
able to deal with the peculiarities of the database system.
A further responsibility of the persistence manager is the formulation of
search queries. With knowledge of the mapping of the data and of the peculiarities
of the storage medium in use it can translate abstract search queries into concrete
search queries. For the formulation of abstract search queries for finding EJB
components the specification of Enterprise JavaBeans offers a query language
called EJB-QL (Enterprise JavaBeans Query Language). EJB-QL was introduced in
version 2.0 of the EJB specification and is further enhanced in version 2.1.
The persistence manager and the query language EJB-QL are dealt with
extensively in Chapter 5.
Enterprise Beans
Enterprise Beans are the server-side components used in the component
architecture of Enterprise JavaBeans. They implement the application logic
on which the client programs rely. The functionality of the server and the EJB
container ensures only that beans can be used. Enterprise Beans are installed in
an EJB container, which offers them an environment at run time in which they
can exist. Enterprise Beans rely implicitly or explicitly on the services that the EJB
container offers:
31
Chapter 3
Session beans model ordinary processes or events. For example, this could be
the entering of a new customer in an enterprise resource planning system (ERP),
the execution of a booking in a booking system, or setting a production plan
based on open orders. Session beans can be viewed as an extension of the client's
arm toward the server. This point of view is supported by the fact that a session
bean is a private resource of a particular client.
Entity beans, on the other hand, represent objects in the real world that
are associated with particular data, such as a customer, a booking account, or a
product. An instance of a particular entity bean type can be used simultaneously
by several clients. Session beans usually operate on data represented by entity
beans.
32
The Architecture o/Enterprise JavaBeans
33
Chapter 3
34
The Architecture ofEnterprise JavaBeans
Remote Interface
The remote in!erface defines those methods that are not offered externally
by a bean. The methods of the remote interface thus reflect the functionality
that is expected or demanded by the components. The remote interface
must be derived from javax.ejb.EJBObject, which in turn is derived from
java. rmi. Remote. All methods of the remote interface must declare the exception
java. rmi. RemoteException. See listing 3-1.
package ejb.bankaccountj
import java.rmi.RemoteExceptionj
import javax.ejb.EJBObjectj
public interface BankAccount extends EJBObject
{
Ilascertain account number
public String getAccNumber()
throws RemoteExceptionj
Ilascertain account description
public String getAccDescription()
throws RemoteExceptionj
Ilascertain account balance
public float getBalance()
throws RemoteExceptionj
Ilincrease account balance
public void increaseBalance(float amount)
throws RemoteExceptionj
Ilreduce account balance
public void decreaseBalance(float amount)
throws RemoteExceptionj
}
35
Chapter 3
Home Interface
The home interface must be derived from javax.ejb.EJBHome (in this interface
is to be found the method for deleting a bean; it does not need to be separately
declared). EJBHome, for its part, is likewise derived from javax.rmi.Remote. In
the home interface as well all methods declare the triggering of an exception of
type java. rmi. RemoteExeption. As in the case of the remote interface, everything
points to the distributed character and the embedding in the BJB framework. See
Listing 3-2.
package ejb.bankaccountj
import java.rmi.RemoteExceptionj
import javax.ejb.CreateExceptionj
import javax.ejb.EJBHomej
import javax.ejb.FinderExceptionj
public interface BankAccountHome extends EJBHome
{
Ilgenerate an account
public BankAccount create(String accNo,
String accDescription,
float initialBalance)
throws CreateException, RemoteExceptionj
Bean Classes
Bean classes implement the methods that have been declared in the home and
remote interfaces (with the exception of the findByPrimaryKey method), without
actually implementing these two interfaces. The signatures of the methods of the
remote and home interfaces must agree with the corresponding methods in the
bean class. The bean class must implement an interface that depends on its type,
and indeed, it must be javax. ejb. EntityBean, javax. ejb.MessageDrivenBean, or
j avax. ej b. Session Bean. The bean implements neither its home nor its remote
36
The Architecture ofEnterprise JavaBeans
package ejb.bankaccount;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContextj
import javax.ejb.RemoveExceptionj
public abstract class BankAccountBean implements EntityBean {
private EntityContext theContextj
public BankAccountBean() {
}
//the create method of the home interface
public String ejbCreate(String accNo,
String accDescription,
float initialBalance)
throws CreateException
{
setAccountNumber(accNo)j
setAccountDescription(accDescription);
setAccountBalance(initialBalance);
return null;
}
public void ejbPostCreate(String accNo,
String accDescription,
float initialBalance)
throws CreateException
{
}
//abstract getter/setter methods
public abstract String getAccountNumber();
public abstract void setAccountNumber(String acn);
public abstract String getAccountDescription();
public abstract void setAccountDescription(String acd);
public abstract float getAccountBalance();
public abstract void setAccountBalance(float acb);
37
Chaprer3
38
The Architecture ofEnterprise JavaBeans
Listing 3-4. Example ofa primary key class for multipart keys.
package ejb.custom:
public class CustomAccountPK implements java.io.Serializable
{
public String clientNumber:
public String accountNumber:
public CustomAccountPK() {
}
public int hashCode() {
return clientNumber.hashCode() A
accountNumber.hashCode():
}
39
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Die seltsamen
Geschichten des Doktor Ulebuhle
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: German
Doktor Ulebuhle
Ein
Jugend- und Volksbuch
von
Bruno H. Bürgel
1920
Der Bauer ist ein Pfiffikus. Er schiebt den Strohhut in den Nacken
und überlegt. Wo das gesteckt hat, kann noch mehr stecken, sagt er
zu sich, und so gräbt er im Schweiße seines Angesichts immer tiefer
auf seinem Acker und sieht, daß da unten alles Asche ist, Asche, die
der feuerspeiende Berg wohl vor vielen Jahrhunderten ausgeworfen
hat. Einen niedlichen Handspiegel findet er noch, und ganz unten
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com