Agenda Fuzzy Wuzzy Differences between regular client DB access - - PowerPoint PPT Presentation

agenda
SMART_READER_LITE
LIVE PREVIEW

Agenda Fuzzy Wuzzy Differences between regular client DB access - - PowerPoint PPT Presentation

The Beginner s Guide To EJB s with JBoss: Quick and Free Cedrick W. Johnson Catylist, Inc. javadude@cedrick.net Agenda Fuzzy Wuzzy Differences between regular client DB access Introductions and Entity access EJB Lingo


slide-1
SLIDE 1

The Beginner’s Guide To EJB’s with JBoss: Quick and Free

Cedrick W. Johnson Catylist, Inc. javadude@cedrick.net

slide-2
SLIDE 2

Agenda

Fuzzy Wuzzy

Introductions

EJB Lingo Entity Bean Defined Types of Entity

Beans:

Fine Coarse O/E, etc….

Differences between

regular client DB access and Entity access

CMP & BMP Side by side Entity Bean Intricacies Performance Increases Review Resources Demonstration

slide-3
SLIDE 3

About The Presenter

Cedrick Johnson Cavenger Systems

CTO, co-founder (old co.)

Technology

Evangelist and 100% Geek

slide-4
SLIDE 4

Some EJB “Lingo”

Session Beans

A business process

(verb)

Stateful and

Stateless

Value Objects Local Interfaces

(NEW IN 2.0!)

Entity Beans

A data object (noun) CMP BMP Finder Methods

EJB-QL (NEW IN 2.0

TOO!!!!)

slide-5
SLIDE 5

Entity Bean Defined

A bean that is used to represent a ROW of

data within a database

BMP and CMP Entity Beans

BMP = harder, but allows for more control over

your SQL code

CMP = easier, but can sometimes be TOO easy

A REUSABLE “component” of your software

application that allows for access to a data resource

slide-6
SLIDE 6

Types of Entity Beans: Fine- Grained

Usually a client accesses these beans

via each of the bean’s accessor methods.

Client calls each of the get/set methods

for reading/manipulating data

Fine for small applications or for

beginners

slide-7
SLIDE 7

Types of Entity Beans: Coarse Grained

A client accesses these beans by using a

Value Object, an object that contains the fields that represent the EJB’s accessor methods

Client makes ONE call, gets the VO, then

makes changes to the VO and resubmits

More suitable for performance-critical

applications (as we will see later)

slide-8
SLIDE 8

Comparison: Entity Beans vs. Traditional DB Access Methods

Each client eats up a DB

connection

Business logic resides

  • n either client or DB

Single point of failure,

little or no reusable components

  • Connections to the DB are

handled by the container

  • Business logic can now

reside in an server-side EJB = reusability

  • Clustering provides

redundancy

  • Somewhat complicated to

begin learning/implementing properly

Traditional Entity

slide-9
SLIDE 9

CMP and BMP Differences

No client SQL Code

(faster to develop)

Plug and play with

database

No DB access code

to deal with

More control over

queries

Semi-Plug and play

with DB

Less new learning

(reuse and extend

  • ld JDBC

code/components)

Container Bean

slide-10
SLIDE 10

How is a EB mapped to a row?

Container obtains all the rows in a

database, then creates a Remote interface “handle” to that row in the database.

100 Rows, 100 “handles” 1000 Rows, 1000 “handles”

slide-11
SLIDE 11

How do you add new rows with Entity Beans?

Clients can call the create() method on

the Entity Bean’s REMOTE interface… This tells the container to invoke ejbCreate() within your EJB to perform the operations needed.

MyEntityRemote.create(new Integer(1), “Hello”);

MyEntityEJBImpl.ejbCreate(new Integer(1), “Hello”);

Container

slide-12
SLIDE 12

How do you modify existing rows with Entity Beans?

Usually you need to find the data, then

set the attributes on the retrieved row. Container manages the update

For better performance, use a Value

Object

MyEJB ejb = home.findByPrimaryKey(1); ejb.setName(“Alfred”);

slide-13
SLIDE 13

Modifying Existing Rows with a Value Object

public PersonVO getPerson() { PersonVO lPerson = null; MyEJBRemote ejb = null; try { ejb = ejbHome.findByPrimaryKey(1); lPerson = ejb.getPersonVO(); } catch ……. return lPerson; }

slide-14
SLIDE 14

Are We Awake????

slide-15
SLIDE 15

Modifying Existing Rows with a Value Object

ID NAME Client Application

ejb.findByPrimaryKey(1);

slide-16
SLIDE 16

Modifying Existing Rows with a Value Object

ID NAME Client Application

ejb.findByPrimaryKey(1);

ID = 1 NAME = Alfred

PersonVO New VO()

slide-17
SLIDE 17

Modifying Existing Rows with a Value Object

ID NAME Client Application

ID = 1 NAME = Alfred

PersonVO

set() get()

slide-18
SLIDE 18

Modifying Existing Rows with a Value Object

ID NAME Client Application

ID = 1 NAME = Alfred

PersonVO

set() get()

ejb.updateUser(1);

slide-19
SLIDE 19

Modifying Existing Rows with a Value Object

ID NAME Client Application

ID = 1 NAME = Alfred

PersonVO

set() get()

slide-20
SLIDE 20

Modifying Existing Rows with a Value Object

ID NAME Client Application Values are now persisted in the database

slide-21
SLIDE 21

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

ejb.findByPrimaryKey(1);

slide-22
SLIDE 22

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

ejb.findByPrimaryKey(1);

MyEJB Remote

slide-23
SLIDE 23

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

ejb.findByPrimaryKey(1);

MyEJB Remote

ID = 1 NAME = Alfred

MyEJB

slide-24
SLIDE 24

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

MyEJB Remote

ID = 1 NAME = Alfred

MyEJB

slide-25
SLIDE 25

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

MyEJB Remote

ID = 1 NAME = Alfred

MyEJB

ejb.create(1, “CHANGEME”)

slide-26
SLIDE 26

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

ejb.create(1, “CHANGEME”)

slide-27
SLIDE 27

Modifying Existing Rows with a Remote Interface

ID NAME Client Application

ejb.findByPrimaryKey(1);

MyEJB Remote

ID = 1

NAME = CHANGEME

MyEJB

slide-28
SLIDE 28

EJB Performance

  • YES! EJB’s are slow compared

to other methods of access

  • BUT: Optimization is key to

achieving maximum performance and scalability

  • If you use EJB’s, you must

architect systems from the ground up with proper design decisions, else it WILL be slow. Use Value Objects Use Local Interfaces Lazy Instantiation Session or Message

Driven Bean façades, etc.

slide-29
SLIDE 29

EJB Performance

Serialization

Use the transient keyword for fields not being serialized Smaller transport (value) objects that transmit only data you

need

“Coarse Grained” Network calls Garbage Collection

Null out references to objects that are no longer needed

Cached Row Sets and a Updater EJB

Client gets a row set, disconnects (Disconnected DS)

performs operations, then “publishes” that RS to a listener EJB which performs the necessary DB updates/checking

slide-30
SLIDE 30

5 10 15 20 25 30 35 40 45 50 Time (seconds) Iterations

CMP Optimized SE+VO (Local Interface) vs CMP FG Entity

FG CMP SE+VO CMP (L) FG CMP 2.1 1.7 3.7 6.6 12.3 24.5 48.9 SE+VO CMP (L) 0.25 0.66 1.5 3.8 6.7 14.2 24.4 1 2 3 4 5 6 7

slide-31
SLIDE 31

5 10 15 20 25 30 35 40 45 50 Time (seconds) Iterations

CMP Optimized Remote Interface SE+VO vs. FG Entity

FG CMP SE+VO CMP (R) FG CMP 2.1 1.7 3.7 6.6 12.3 24.5 48.9 SE+VO CMP (R) 0.39 1.05 2.27 4.6 9.9 19.2 36.6 1 2 3 4 5 6 7

slide-32
SLIDE 32

Review

EJB is NOT all there

is to J2EE

Evaluate project

needs

Not needed for small

applications, usually

Investigate and

learn!!

Why do we use EJB? What is an entity bean Entity Bean Types Differences between

DAO and EJB data access

CMP & BMP: Side by

Side

Performance Issues

slide-33
SLIDE 33

Resources To Get You Started

  • JBuilder 5/6 (NOW WITH UML!!!)
  • http://www.borland.com/jbuilder
  • Sybase EAServer 4.1 Developer Edition
  • http://www.sybase.com/products/easerver
  • JBoss Open Source App Server
  • http://www.jboss.org
  • Orion App Server
  • BEA Weblogic App Server
  • http://www.bea.com
  • Eclipse IDE
  • www.eclipse.org
  • Your local EJB nut
  • The presenter
slide-34
SLIDE 34

Resources To Get You Started (Continued)

  • The ServerSide
  • http://www.theserverside.com
  • The Middleware Company
  • http://www.middlewarecompany.com
  • JGuru Forums
  • http://www.jguru.com
  • AspectJ
  • http://www.aspectj.org
  • EJB Performance Measurements – November 2001 CJUG

Presenter- Maciej Zawadski

  • http://www.urbancode.com
slide-35
SLIDE 35

Demonstration

JBoss 3.0 Application Server JBoss Druid - CMP Generator Eclipse IDE No cards up my sleeve