87
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans

Enterprise JavaBeans

Embed Size (px)

DESCRIPTION

Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software. Objectives. Define client-server and multi-tier architecture Discuss the benefits and issues of distributed architectures Define software components - PowerPoint PPT Presentation

Citation preview

Page 1: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Enterprise JavaBeans

Page 2: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 1:Introduction to Server-Side Component

Software

Page 3: Enterprise JavaBeans

Objectives

• Define client-server and multi-tier architecture• Discuss the benefits and issues of distributed

architectures• Define software components• Discuss server-side component architecture

and architecture solutions• Define J2EE technologies• Define EJB technology

Page 4: Enterprise JavaBeans

Client-Server andMulti-Tiered Architectures

• Scalability• Extensibility• Security• Issues concerning distributed architectures

– Complexity– Communication/bandwidth– Maintenance costs

Page 5: Enterprise JavaBeans

CentralizedMainframe Architecture

Page 6: Enterprise JavaBeans

Two-TierArchitecture

Page 7: Enterprise JavaBeans

Three-TierArchitecture

Page 8: Enterprise JavaBeans

SoftwareComponents

• Component architectures– Component development tools– Container– Maintenance deployment tools

Page 9: Enterprise JavaBeans

ComponentArchitecture Solutions

• .NET Enterprise Architecture• CORBA• J2EE

Page 10: Enterprise JavaBeans

J2EETechnologies

• EJB• RMI/RMI-IIOP• JNDI• JDBC• JTA/JTS• JMS

• JSP• IDL• JavaMail• Connectors• XML

Page 11: Enterprise JavaBeans

EnterpriseJavaBeans

• Differences between JavaBeans and Enterprise JavaBeans

• EJB development tasks– J2EE product provider– Bean developer– Application assembler– Deployer– System administrator– Tool provider

Page 12: Enterprise JavaBeans

Summary

Define client-server and multi-tier architecture Discuss the benefits and issues of distributed

architectures Define software components Discuss server-side component architecture

and architecture solutions Define J2EE technologies Define EJB technology

Page 13: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 2:Overview of the Enterprise JavaBeans

Framework

Page 14: Enterprise JavaBeans

Objectives

• Define an EJB server’s main components• Discuss EJB and client interaction• Identify EJB container services• Describe home objects and EJB objects• Compare session beans and entity beans• Define a deployment descriptor• Identify the EJB-JAR file

Page 15: Enterprise JavaBeans

EJBArchitecture

• Primary components– EJB-compliant server– EJB-compliant container– Home object (bean factory)– EJB object (remote interface)– EJB

Page 16: Enterprise JavaBeans

Example ofEJB Architecture

Page 17: Enterprise JavaBeans

Client Interactionwith Enterprise JavaBeans

Page 18: Enterprise JavaBeans

EJBContainer Services

• Distributed transaction management• Persistence• Security• Component resource and life cycle

management• Remote accessibility• Transparent location of components• Identification of components

Page 19: Enterprise JavaBeans

The EJBHome Object

• Location transparency

Page 20: Enterprise JavaBeans

TheEJB Object

Stubs

Skeletons

Page 21: Enterprise JavaBeans

Types ofEnterprise JavaBeans

• Session beans– Stateful– Stateless

• Entity beans

Page 22: Enterprise JavaBeans

DeploymentDescriptors

• An XML document that describes the properties of an EJB

Page 23: Enterprise JavaBeans

TheEJB-JAR File

• Contains the class files for a bean, its home and remote interfaces, and the deployment descriptors

Page 24: Enterprise JavaBeans

Summary

Define an EJB server’s main components Discuss EJB and client interaction Identify EJB container services Describe home objects and EJB objects Compare session beans and entity beans Define a deployment descriptor Identify the EJB-JAR file

Page 25: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 3:Creating Session Beans

Page 26: Enterprise JavaBeans

Objectives

• Define the methods of the SessionBean interface

• Describe the EJBContext and the SessionContext interfaces

• Contrast stateful and stateless session beans• Explain how to write business methods for a

session bean• Discuss the enterprise bean’s life cycle

Page 27: Enterprise JavaBeans

Objectives (cont’d)

• Create a session bean• Define the EJBHome and EJBObject interfaces

and their methods• Discuss the superclass for the home and

remote interfaces• Describe system and application exceptions• Deploy and connect to a session bean

Page 28: Enterprise JavaBeans

Creating theEnterprise Bean Class

• ejbCreate methods• The SessionBean interface• The EJBContext interface• The SessionContext interface

Page 29: Enterprise JavaBeans

Stateless andStateful Session Beans

• Stateless session beans– Do not keep track of any information from

one method call to the next• Stateful session beans

– Can change their state during a conversation with a client

Page 30: Enterprise JavaBeans

Writing Business Methods for an Enterprise Bean

• Each EJB must declare the business methods that define the work that the EJB is designed to perform

Page 31: Enterprise JavaBeans

The Home Interface

• Extends EJBHome• Provides mechanisms to create and remove

EJB components

Page 32: Enterprise JavaBeans

The EJB Object

• Extends the EJBObject interface

Page 33: Enterprise JavaBeans

Exceptions in EJB

• System exceptions• Application exceptions

Page 34: Enterprise JavaBeans

Example:A Session Bean

• The Teller bean class• The Teller remote interface• The Teller home interface

Page 35: Enterprise JavaBeans

The LibraryApplication

• The Book entity bean• The Patron entity bean• The CheckOutRecord entity bean• The CheckOut session bean• The CheckIn session bean

Page 36: Enterprise JavaBeans

LibraryDBSchema

Page 37: Enterprise JavaBeans

Introduction toEJB Deployment

• The deployment descriptor– DD XML tags

• Environment data– Environment property XML tags– Accessing environment data

• Using bean references– EJB reference XML tags– Using the EJB reference

• Using resource factories– Factory resource XML tags

Page 38: Enterprise JavaBeans

AdditionalDeployment Concepts

• Assembler/deployer roles with the deployment descriptor

• EJB deployment in an EJB server

Page 39: Enterprise JavaBeans

Summary

Define the methods of the SessionBean interface

Describe the EJBContext and the SessionContext interfaces

Contrast stateful and stateless session beans Explain how to write business methods for a

session bean Discuss the enterprise bean’s life cycle

Page 40: Enterprise JavaBeans

Summary (cont’d)

Create a session bean Define the EJBHome and EJBObject interfaces

and their methods Discuss the superclass for the home and

remote interfaces Describe system and application exceptions Deploy and connect to a session bean

Page 41: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 4: Entity Beans

Page 42: Enterprise JavaBeans

Objectives

• Discuss entity beans and their persistence management techniques

• Identify the methods of the EntityBean and EntityContext interfaces

• Define primary keys and their use• Describe the mechanics involved in entity

beans• Use finder methods• Write an entity bean and its required

interfaces

Page 43: Enterprise JavaBeans

What Is an Entity Bean?

• The EntityBean interface• The EntityContext interface• Primary keys

Page 44: Enterprise JavaBeans

Entity BeanArchitecture

• Creating entity beans• Invoking business methods on entity beans• Swapping entity beans• Invoking remove( ) on an entity bean• Life cycle of an entity bean instance

Page 45: Enterprise JavaBeans

Life Cycle of anEntity Bean Instance

Page 46: Enterprise JavaBeans

Bean-ManagedPersistence

• Using JDBC• Using a resource factory to connect to a

database

Page 47: Enterprise JavaBeans

UsingResource Factories

Page 48: Enterprise JavaBeans

Entity Bean Methods

• The ejbCreate( ) method• The ejbPostCreate( ) method• The ejbRemove( ) method• The ejbLoad( ) method• The ejbStore( ) method

Page 49: Enterprise JavaBeans

UsingFinder Methods

• The ejbFindByPrimaryKey( ) method• Multiple row finders

Page 50: Enterprise JavaBeans

The Remote Interface

• All remote interfaces extend javax.ejb.EJBObject

Page 51: Enterprise JavaBeans

The Home Interface

• The Account entity bean

Page 52: Enterprise JavaBeans

Summary

Discuss entity beans and their persistence management techniques

Identify the methods of the EntityBean and EntityContext interfaces

Define primary keys and their use Describe the mechanics involved in entity

beans Use finder methods Write an entity bean and its required

interfaces

Page 53: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 5:Enterprise JavaBeans Clients

Page 54: Enterprise JavaBeans

Objectives

• Use JNDI to obtain a reference to the home object

• Instantiate an EJB instance using the home object

• Call an enterprise bean's business methods• Remove an enterprise bean• Write an EJB client

Page 55: Enterprise JavaBeans

Using JNDI

Page 56: Enterprise JavaBeans

Creatingan EJB Instance

• Invocation of business methods

Page 57: Enterprise JavaBeans

Summary

Use JNDI to obtain a reference to the home object

Instantiate an EJB instance using the home object

Call an enterprise bean's business methods Remove an enterprise bean Write an EJB client

Page 58: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 6:Container-Managed

Persistence

Page 59: Enterprise JavaBeans

Objectives

• Discuss entity beans and CMP• Explain the benefits and disadvantages of

using CMP• Describe the primary key as it relates to CMP• Define an ejbCreate() method that uses

CMP• Write the requisite methods for an entity bean

to use CMP

Page 60: Enterprise JavaBeans

Introduction to Container-Managed Persistence (CMP)

• Benefits– Less code needed– Optimization techniques– More portable– Fewer bugs

• Disadvantages– Less flexibility– Inaccessible code

Page 61: Enterprise JavaBeans

ThePrimary Key

• Primary key class– Must be serializable– Must be of a legal value type in RMI-IIOP

Page 62: Enterprise JavaBeans

EJBMethods and CMP

• ejbCreate()• ejbRemove()• ejbLoad()• ejbStore()• Other methods• Finder methods

Page 63: Enterprise JavaBeans

TheDeployment Descriptor

• EJB requirements• DD XML tags

Page 64: Enterprise JavaBeans

The Deployment Descriptor and CMP

• Example: A CMP entity bean– The EmployeeEJB bean class– The home interface– The remote interface

Page 65: Enterprise JavaBeans

Summary

Discuss entity beans and CMP Explain the benefits and disadvantages of

using CMP Describe the primary key as it relates to CMP Define an ejbCreate() method that uses

CMP Write the requisite methods for an entity bean

to use CMP

Page 66: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 7:Transactions in

Enterprise JavaBeans

Page 67: Enterprise JavaBeans

Objectives

• Define transactions and explain their use• Distinguish transaction participants• Define transaction properties• Explain the EJB transactional model• Describe distributed transactions• Define transaction isolation levels• Discuss EJB transaction attributes

Page 68: Enterprise JavaBeans

What Are Transactions?

• Operations or series of operations that are treated as single units of work

• Transactional management

Page 69: Enterprise JavaBeans

Participantsin Transactions

• Transactional objects or applications• Transaction managers• Resources• Resource managers

Page 70: Enterprise JavaBeans

Propertiesof Transactions

• Atomicity• Consistency• Isolation• Durability

Page 71: Enterprise JavaBeans

EJBTransactional Models

• Flat transactional model• Nested transactional model

Page 72: Enterprise JavaBeans

FlatTransactional Model

Page 73: Enterprise JavaBeans

NestedTransactional Model

Page 74: Enterprise JavaBeans

DistributedTransactions

• Two-phase commits• Transparent transaction control

– Transaction context

Page 75: Enterprise JavaBeans

Isolation Levels

• Strict– Each concurrent transaction is isolated

from all other transactions• Nonstrict

– Increased transactional performance– Possibility of corrupted data

Page 76: Enterprise JavaBeans

Transactions in EJB

• Transaction demarcation• Container-managed transactions

– Attributes• Defining CMT in the DD• Setting CMT in Deploytool

Page 77: Enterprise JavaBeans

Container-Managed Transactions

• Container-managed transaction attributes• Which methods require transaction attributes?• The setRollbackOnly( ) and getRollbackOnly( ) methods

• Defining CMT in the DD• Setting CMT in Deploytool

Page 78: Enterprise JavaBeans

Bean-ManagedTransactions

• UserTransaction interface– Properties– Methods

• Setting BMT in the DD• BMT and stateful session beans• BMT and stateless session beans

Page 79: Enterprise JavaBeans

Summary

Define transactions and explain their use Distinguish transaction participants Define transaction properties Explain the EJB transactional model Describe distributed transactions Define transaction isolation levels Discuss EJB transaction attributes

Page 80: Enterprise JavaBeans

Copyright © 2002 ProsoftTraining. All rights reserved.

Lesson 8:Enterprise JavaBeans Security

Page 81: Enterprise JavaBeans

Objectives

• Define users in EJB security• Discuss principals in EJB security• Identify roles in EJB security• Describe the DD’s role in EJB security• Explain the EJB container’s role in EJB

security

Page 82: Enterprise JavaBeans

Defining Users,Principals and Roles

• Overview of EJB security– Authentication– Authorization

• Authorization in EJB code

Page 83: Enterprise JavaBeans

Example: Users,Principals and Roles

Page 84: Enterprise JavaBeans

Security and the Deployment Descriptor

• The bean developer and the DD• The application assembler and the DD• The deployer and the DD

Page 85: Enterprise JavaBeans

Summary

Define users in EJB security Discuss principals in EJB security Identify roles in EJB security Describe the DD’s role in EJB security Explain the EJB container’s role in EJB

security

Page 86: Enterprise JavaBeans

Enterprise JavaBeans

Introduction to Server-Side Component Software

Overview of the Enterprise JavaBeans Framework

Creating Session Beans Entity Beans

Page 87: Enterprise JavaBeans

EnterpriseJavaBeans

Enterprise JavaBeans Clients Container-Managed Persistence Transactions in Enterprise JavaBeans Enterprise JavaBeans Security