Title: Enterprise JavaBeans Overview
1Enterprise JavaBeans Overview
- Presented by
- Eric Gudgion
2What are EJBs
- Enterprise JavaBeans are a server side standards
based component model. - Provides a frame work for methods, naming,
transactions, security, persistence, life-cycle. - Concentrate on business logic.
- Scalable architecture.
3Why Business Components?
- Separate Business Logic from Plumbing and Glue
- Separate Component Development from Assembly and
Deployment - Manage Software as Depreciable Business Assets
- Offer easy integration with business components
and enterprise data - Enable portability across platforms
4What are Enterprise JavaBeans (EJB)?
An EJB defines a component model for developing
and deploying Server-Side business objects.
- CHARACTERISTICS
- A Server-Side business Component
- Written in 100 Java
- Distributed over a network
- Always called by a Client
- Transactional
- Secure
- Two Types (Entity and Session)
5The Right Bean For the Job
DBMS
- Enterprise JavaBeans
- Distributed Components for assembling networked
applications - Server-side
- No GUI
- Core features methods, naming, transactions,
security, persistence, life-cycle - Separates business logic container
- JavaBeans
- Components for assembling local application
- Generally client-side
- Often GUI-oriented
- Core features methods, properties, events,
introspection, customization - Separates design runtime environments
6Architecture
7Technical View of an EJB Session(Analogy
Collect Phone Call)
8Session and Entity Beans
9Client side
// lookup home from JNDI AccountHome home
(AccountHome) jndiCtx.lookup("bank.accounts")
Account myAccount home.create(...) Account
momsAccount home.findByPrimaryKey() tx.begin
() momsAccount.withdraw(5000) myAccount.deposit(
5000) tx.commit()
10State Management Persistence
11Compare the 2 Types of EJBs
Session EJB
Entity EJB
- Analogous to a Shopping Cart
- Represents one User connection
- Can be Stateless (ex. simple query) or Stateful
(more typical for shopping cart) - Exists for life of Session only
- Not Persistent destroyed if server crashes
- Contains Business Logic
- May or may not be Transactional
- Analogous to an Item in the Cart
- Represents one row in a database
- Purely Stateful (represents the data)
- Exists beyond the Session
- Persistent
- Contains Business Logic
- May or may not be Transactional
12EJB Taxonomy
Enterprise JavaBeans
Entity Beans Component view of DB row or
object May be long-lived Primary key,
stateful 1-to-many relationship to
client(s) E.g., Customer, Order
- Session Beans
- TPM/OTM style
- Short-lived, no key
- 1-to-1 relationship to client
- Explicit DB access
- E.g., Bank Teller, E-Commerce
Server
Many EJB applications will use both!
Entity Beans
Session Beans
(via explicit JDBC when automated tools are
insufficient)
(Web shopping cart)
(Inventory agent)
(via O/R mapping)
Stateful
Stateless
Bean- Managed
Container- Managed
13Persistence
- Container (typically) handles object persistence
automatically. - Bean written is backing store independent.
- Containers for SQL DBMS, OODBMS, ORDBMS, file
system, directory service. - Deployment Descriptor properties hold
container-specific persistence properties, like
attribute-column mappings.
14Bean References
15Persistence DD Wizard Pane
16Persistence Deployment Descriptor
- (persistentStoreProperties
- persistentStoreType jdbc
- (jdbc
- tableName ejbAccounts
- dbIsShared false
- poolName ejbPool
- driverName weblogic.jdbc.jts.Driver
- (attributeMap
- EJBean attribute Database column
name - -------------------------------------
---- - accountId id
- balance bal
- ) end attributeMap
- ) end jdbc
- )
17Transactions
18Transactional Definition (ACID)
- Atomic, transactions are all or nothing, never
incomplete. - Consistent, always leave the system in a
consistent state. - Isolated, execute in a safe manner, without
effecting each other. - Durable, once completed and committed, survive a
system failure.
19Transaction Management
- Uses Java Transaction Service (JTS).
- EJB Server handles TX ID propagation.
- Declarative TX management through Deployment
Descriptor - Per-method and Bean-wide scope.
- EJB Container performs TX begin, commit, and
rollback, and provides 2PC semantics on beans
behalf.
20Transaction Control Descriptors
- TX_NOT_SUPPORTED - Bean does not have
transactions - any active transactions are suspended during
method call. - TX_REQUIRED - Transaction scope required, one is
created if the scope does not exist. - TX_SUPPORTS - If the client has transaction scope
the bean will use it, otherwise no scope is used. - TX_REQUIRES_NEW - Container creates new
transaction. - TX_MANDATORY - Transaction scope always required.
- TX_BEAN_MANAGED - Bean will manage its scope.
21Isolation Level Description
- TRANSACTION_READ_UNCOMMITTED - Can read
uncommitted data. - TRANSACTION_READ_COMMITTED - Cant read
uncommitted data. - TRANSACTION_REPEATABLE_READ - Cant change data
thats being read by another transaction. - TRANSACTION_SERIALIZABLE - Transaction has
exclusive read and update privileges.
22Transaction DD Wizard Pane
23Transaction DD
- (controlDescriptors
- (DEFAULT
- isolationLevel TRANSACTION_SERIALIZABLE
- transactionAttribute TX_MANDITORY
- )
- (buy
- isolationLevel TRANSACTION_SERIALIZABLE
- transactionAttribute TX_REQUIRED
- ) end buy
- ) end controlDescriptors
24Security
25EJB Security Management
- EJB Server propagates security context.
- Declarative security attributes in DD.
- Access control per-method and bean-wide
- SetUID functionality RunAsMode and
RunAsIdentity - Container enforces access control and sets beans
identity as described in DD
26WebLogic Real-World Security
- SSL protocol
- RSA Encryption
- X.509 Digital certificates
- Access Control List functionality
- Integrated with leading Internet security vendors
27Access Control DD Wizard Pane
28Deployment
29EJB Packaging
- EJB Jar file contains
- Deployment Descriptor (Serializable Entity or
Session Java Class) - Beans Home Remote Interfaces
- Beans Home Class Names
- Beans Implementation Code
- Environmental Properties
- Access Control Lists
- Transaction Control Descriptors
- Manifest File (Declares Descriptor as Bean)
- All Handled by Server Vendor!
30Deployment Descriptor
(EntityDescriptor beanHomeName
bank.accounts enterpriseBeanClassName
AccountBean homeInterfaceClassName
AccountHome remoteInterfaceClassName Account
)
31Summary
32Development Deployment Roles
- EJB provider (domain expert) writes bean
- Application assembler combines beans into a
system - Deployer knows a specific EJB environment
(server container) BEA WebLogic - EJB Server provider BEA WebLogic
- EJB Container provider BEA WebLogic partners
- System Administrator runs the EJB Server
Vendor-independent role
33EJB Benefits
- Concentrate on business logic.
- Higher-level semantics security, transactions,
persistence, naming. - Component System-Independent Components.
- Component roles bean writer, deployer,
server,container. - Scalable architecture.
34Helpful Tools
- StructureBuilder - www.webgain.com
- Rational Rose - www.rational.com
- Introscope - www.wilytech.com
- Visual Café - www.webgain.com
- Visual Age - www-4.ibm.com/software/ad/vjava
35Useful Books
- Title Enterprise JavaBeans
- Publisher OReilly ISBN 1-556592-605-6
- Author Richard Monson-Haefel
- Title Java Enterprise in a Nutshell
- Publisher OReilly ISBN 1-56592-483-5
- Author David Flanagan, Jim Farley, William
Crawford Kirs Magnusson - Title Mastering Enterprise JavaBeans and the
Java 2 Platform Enterprise Edition - Publisher Wiley ISBN 0-471-33229-1
- Author Ed Roman
36Internet Resources
- http//www.bea.com
- http//java.sun.com/products/ejb
- http//www.ejbnow.com
- http//www.jguru.com
- http//www.javadevelopersjournal.com
- news//www4.weblogic.com/weblogic.developer.intere
st.ejb