Ejb 3[1].0 Architecture

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ejb 3[1].0 Architecture as PDF for free.

More details

  • Words: 2,788
  • Pages: 51
Enterprise JavaBeans™ 3.0 Technology Work in Progress Linda DeMichiel EJB Specification Lead Sun Microsystems java.sun.com/j2ee 1

SM

| 2004 JavaOne Conference | Session TS-1861

java.sun.com/javaone/sf

Goal of This Talk

Learn about the new EJB™ 3.0 technology

2

SM

| 2004 JavaOne Conference | Session TS-1861

Agenda Goals of EJB™ 3.0 Technology Overview of the Simplified EJB™ API Technology Drill Down Java™ Metadata Interface Software Session Bean Simplifications Access to the Environment Entity Beans Summary and Current Status Where to Get More Info at JavaOneSM Conference 3

SM

| 2004 JavaOne Conference | Session TS-1861

Primary Focus: Ease of Development

• Simplify EJB™ technology—make it easier to use

─ Simplified set of APIs ─ Eliminate deployment descriptor from developer’s view ─ Facilitate test-driven development ─ Improve developer productivity

• Capture broader range of developers ─ Make it simpler for average developer ─ Increase developer base, target more corporate developers

4

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Expert Group Agenda

• Define “Simplified API” for EJB™

3.0 technology • Critical examination of EJB™ technology complexity ─ “Data-mining” of common complaints, RFEs ─ Anti-patterns, etc.

• Focus on most common cases • Ensure EJB™ 2.0/2.1 APIs always available for more complex scenarios

─ Simplifications/enhancements to improve use of these APIs as well 5

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Expert Group Apache Software Foundation: Jeremy Boynes BEA: Seth W hite, Cedric Beust Borland: Jishnu Mitra E.piphany: Reza Behforooz Fujitsu-Siemens: Anton Vorsamer IBM: Jim Knutson IONA: Conrad O'Dea Jboss: Marc Fleury, Gavin King Nokia: Vic Zaroukian Novell: YongMin Chen Oracle: Michael Keith, Olivier Caudron Pramati: Hemant Khandelwal 6

SM

| 2004 JavaOne Conference | Session TS-1861

SAP: Harald Mueller SAS Institute: Rob Saccoccio SeeBeyond: Ugo Corda Sun Microsystems: Linda DeMichiel Sybase: Evan Ireland Tibco: Shivajee Samdarshi Tmax Soft: JaeW oong Chung, W oo Jin Kim Individuals: David Blevins Scott Crawford Olivier Ihns Richard Monson-Haefel Suneet Shah

EJB™ 3.0 Technology Overview: Metadata

• Leverage use of Java™ programming language metadata (JSR 175, part of J2SE™ 1.5 technology)

─ Reduce the number of artifacts programmer needs to produce ─ Eliminate need for developer to provide deployment descriptor

• “Configuration by exception” ─ Specification of defaults, including for metadata ─ Reduce need to specify common, expected behaviors and requirements on container

7

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Overview: Environment

• Simplification of access to bean’s environment and runtime context

─ Encapsulation of environment dependencies and JNDI access ─ Through metadata annotations ─ Dependency injection mechanisms

─ Simplification of access to other components

8

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Overview: POJO Beans

• Simplification of enterprise bean types ─ More closely resemble “POJOs”

• Elimination of requirement for EJB™ component interfaces

─ Use “POJIs” for session beans ─ No requirement for entity bean interfaces

• Elimination of requirement for Home interfaces • Elimination of requirement for callback interfaces

─ Allow selective implementation of callback methods

9

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Overview: CMP

• Simplification of container-managed persistence ─ POJO/JavaBeans™ architecture approach ─ Support use of new() ─ Allow for testing outside the container

• Support for light-weight domain modeling, including

─ Inheritance and polymorphism ─ Object-relational mapping metadata

• Elimination of need for data transfer objects and related anti-patterns

10

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology Overview: EJB™ QL

• Enhancements for EJB™ QL: ─ ─ ─ ─ ─ ─ ─

Bulk update and delete Projection (SELECT list) Subqueries Explicit inner and outer join operations Group by, Having Additional functions Dynamic queries

• + Support for native SQL queries

11

SM

| 2004 JavaOne Conference | Session TS-1861

Agenda Goals of EJB™ 3.0 Technology Overview of Simplified EJB™ API Drill Down Java™ Metadata Interface Session Bean Simplifications Access to the Environment Entity Beans Summary and Current Status Where to Get More Info at JavaOneSM Conference 12

SM

| 2004 JavaOne Conference | Session TS-1861

Java™ Programming Language Metadata Interface

• Annotations on classes, methods, fields, etc. ─ Embedded in source code ─ Compiled into class files ─ Available at runtime

• Annotations can be simple or complex (i.e., structured) • Annotations can use defaults • Annotation processors

─ Can: generate new files/classes ─ Cannot: alter source files or class files, inject base classes, interfaces, alter bytecodes, etc. 13

SM

| 2004 JavaOne Conference | Session TS-1861

Java™ Programming Language Metadata Interface

• Great enabling technology for EJB™ software ─ Generation of interface files ─ Elimination of deployment descriptors ─ Demarcation of injection and interpositioning points for container behavior

• Leverage defaulting in conjunction with metadata

─ Default values for annotation members ─ Metadata itself used for non-default cases

• Gives developer very simple-to-use and yet powerful capability

14

SM

| 2004 JavaOne Conference | Session TS-1861

Session Beans

• “Hello World” entry experience into EJB™ technology

─ Therefore our starting point for simplification….

15

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 2.1 Technology Stateless Session Bean public interface Calculator extends EJBObject { int add (int a, int b) throws RemoteException; int subtract (int a, int b) throws RemoteException; } public interface CalculatorHome extends EJBHome { Calculator create() throws CreateException, RemoteException; }

16

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 2.1 Technology Stateless Session Bean Class public class CalculatorBean implements SessionBean { private SessionContext ctx; public void setSessionContext(SessionContext s) {ctx = s;} public void ejbCreate() {} public void ejbActivate () {} public void ejbPassivate () {} public void ejbRemove () {} public int return a } public int return a } }

17

SM

add (int a, int b) + b;

{

subtract (int a, int b) { – b;

| 2004 JavaOne Conference | Session TS-1861

EJB™ 2.1 Technology Deployment Descriptor <session> <ejb-name>CalculatorEJB com.example.CalculatorHome com.example.Calculator <ejb-class>com.example.CalculatorBean <session-type>Stateless Container ... ... ...

18

SM

| 2004 JavaOne Conference | Session TS-1861

What’s Wrong With This Example? • Heavy-weight programmer view: ─ 3 classes + deployment descriptor

• Interfaces get in the way ─ ─ ─ ─

Create doesn’t create Remove doesn’t remove javax.ejb.SessionBean methods all unneeded here Add to code clutter

• Deployment descriptor ─ ─ ─ ─ 19

Awkward to produce Contains redundant information Structure doesn’t conform to that of bean classes Etc. SM

| 2004 JavaOne Conference | Session TS-1861

Same Example: EJB™ 3.0 Technology @Stateless public class CalculatorBean implements Calculator { public int add (int a, int b) return a + b; }

{

public int subtract (int a, int b) { return a – b; } } public interface Calculator { int add (int a, int b); int subtract (int a, int b); } 20

SM

| 2004 JavaOne Conference | Session TS-1861

Same Example With Generated Interface @Stateless public class CalculatorBean { public int add (int a, int b) return a + b; }

{

public int subtract (int a, int b) { return a – b; } }

21

SM

| 2004 JavaOne Conference | Session TS-1861

Same Example With Remote Access @Stateless @Remote public class CalculatorBean { public int add (int a, int b) return a + b; }

{

public int subtract (int a, int b) { return a – b; } }

22

SM

| 2004 JavaOne Conference | Session TS-1861

Deployment Descriptor

23

SM

| 2004 JavaOne Conference | Session TS-1861

Some Simplifications We Have Made

• Eliminated requirement for Home Interface ─ Not needed for session beans

• Business interface is a POJI ─ ─ ─ ─ ─

Bean can implement it or it can be generated Bean can have more than one business interface Can support remote access EJB(Local)Object removed from client view RemoteExceptions are removed from programmer and client view

• Eliminated requirement for unnecessary callback methods

─ Removed requirement to implement javax.ejb.SessionBean 24

SM

| 2004 JavaOne Conference | Session TS-1861

Simplification Through Use of Defaulting

• Minimize use of metadata ─ ─ ─ ─ ─ ─ ─

25

Defaulting of interface generation Defaulting of names Defaulting use of transaction management types Defaulting of transaction attributes Default use of unchecked methods Default use of caller identity Etc.

SM

| 2004 JavaOne Conference | Session TS-1861

Stateful Session Beans

• Don’t need Home or Component

interfaces either • Stateful Session Bean create is really initialization from programmer's point of view • Stateful Session Bean remove is important ─ However, metadata can be used instead

26

SM

| 2004 JavaOne Conference | Session TS-1861

Stateful Session Bean Example @Stateful public class MyShoppingCartBean { private String customer; public void startToShop (String customer){ this.customer = customer; ... } public void addToCart (Item item) { ... } @Remove public void finishShopping () { ... } }

27

SM

| 2004 JavaOne Conference | Session TS-1861

Under Evaluation

• @Service bean type ─ Stateless Session beans and Message-driven beans have much in common

• Single interface subsuming remote/local usages

─ Looked good initially, but simplification of persistence model may mean it won’t be simpler

• GenericSessionBean, GenericEntityBean,

GenericMessageDrivenBean abstract clases ─ Have convenience methods ─ Have callback methods stubbed out ─ More useful for beans written to “classic” API

28

SM

| 2004 JavaOne Conference | Session TS-1861

Simplified Access to Bean’s Environment

• Get JNDI APIs out of developer’s view ─ Not at all a good “hello world” experience

• Techniques/mechanisms 1) Declarative expression of dependencies in metadata 2) Container injection of resource entries, etc. 3) Simple programmatic lookup mechanisms

• Different usages, both have their place 1) Very simple; facilitates testability (especially setter injection techniques) 2) More flexible; dynamic 29

SM

| 2004 JavaOne Conference | Session TS-1861

Example @Stateless public class MySessionBean { @Resource(name=”myDB”) public DataSource customerDB; public void myMethod (String myString){ try { Connection conn = customerDB.getConnection(); ... } catch (Exception ex) {...} } } 30

SM

| 2004 JavaOne Conference | Session TS-1861

With Setter Injection @Stateless public class MySessionBean { private DataSource customerDB; @Resource(name=”myDB”) public void setDataSource(DataSource myDB) { customerDB = myDB; } public void myMethod (String myString){ ... Connection conn = customerDB.getConnection(); ... } } 31

SM

| 2004 JavaOne Conference | Session TS-1861

@Inject @Stateless public class MySessionBean { private DataSource customerDB; @Inject public void setCustomerDB(DataSource customerDB) { this.customerDB = customerDB; } public void myMethod (String myString){ ... Connection conn = customerDB.getConnection(); ... } }

32

SM

| 2004 JavaOne Conference | Session TS-1861

Injection

• Container can initialize instance variables at time bean is made available ─ “setEJBContext time”

• Setter injection is better technique ─ Also happens at “setEJBContext time” ─ Better testability ─ Considered constructor injection, but found it not as simple/flexible

• These techniques can be used to inject

ejbContext, EntityManager, resources, session beans, etc.

33

SM

| 2004 JavaOne Conference | Session TS-1861

Dynamic Lookup

• Adding lookup() method to ejbContext • Can use injection to get ejbContext • Useful for stateful session beans ... @Inject private void setSessionContext(SessionContext ctx) { this.ctx = ctx; } ... myShoppingCart = (ShoppingCart)ctx.lookup (“shoppingCart”); 34

SM

| 2004 JavaOne Conference | Session TS-1861

Client View

• Homes eliminated ─ With metadata, injection, easy lookup(), etc., Homes not needed for session beans (either stateless or stateful) ─ Stateless SessionBean homes not very useful anyway

• Stateful SessionBean homes have useful create methods

─ But: shifting functionality to “initialization” business method enables home to be eliminated ─ @Remove annotation completes the picture

35

SM

| 2004 JavaOne Conference | Session TS-1861

Entity Beans: Goals

• Simplify programming model • Improve modeling capabilities ─ Inheritance and polymorphism; O/R mapping

• • • •

Make instances usable outside the container Facilitate testability Remove need for data transfer objects (DTOs) BMP currently a non-goal ─ Will probably get minor improvements: use of metadata, etc.

• Resulted in some important changes 36

SM

| 2004 JavaOne Conference | Session TS-1861

Process We Went Through

• Looked at options and technologies • Sorted out priorities • Identified items that most need fixed ─ ─ ─ ─

Complexity Lack of testability outside the container Need for improved modelingand querying capabilities DTO issues

• Identified what we needed to preserve

─ EJB™ QL + enhancement of it ─ Container's ability to interpose and manage ─ Tx/security/caching/faulting control,...

37

SM

| 2004 JavaOne Conference | Session TS-1861

Process We Went Through (Cont.)

• Converged on self-consistent set of functionality ─ Serious exercise in prioritization ─ Meant removing a few things we liked

• Kept focus centered onobject/relational mapping

─ Non-relational databases, etc. a non-issue ─ Relational-db-centric ─ Follows direction of established object/relational mapping technologies such as Hibernate, Toplink, etc.

38

SM

| 2004 JavaOne Conference | Session TS-1861

POJO Entity Beans • Concrete classes (no longer abstract) • No required interfaces ─ No required business interfaces ─ No required callback interfaces

• Support new() • getter/setter methods ─ can contain logic (e.g., for validation, etc.)

• No exposure of instance variables outside bean class • Use Collection interfaces for relationships • Usable outside the EJB™ container ─ Means we needed to sacrifice CMRs 39

SM

| 2004 JavaOne Conference | Session TS-1861

Lifecycle Operations

• EntityManager serves as untyped “home” ─ Use to save, remove entity instances ─ Factory for queries

• Lifecycle operations ─ ─ ─ ─

new() create() remove() Detached instances ─ instances that exist outside of original transaction context ─ serialized to other tiers ─ merge() merges them back

40

SM

| 2004 JavaOne Conference | Session TS-1861

Example: What I Predicted a Year Ago public @entity abstract class CustomerBean { public abstract String getName(); public abstract void setName (String name); public abstract Account getAccount(); ... public String ejbCreate(String name) throws CreateException { setName(name); return null; } ... } // Home and Component IF definitions, etc. 41

SM

| 2004 JavaOne Conference | Session TS-1861

Example: EJB™ 3.0 Technology Entity Bean Today @Entity public class Customer { private Long id; private String name; private Address address; private HashSet orders = new HashSet(); @Id(generate=AUTO) public Long getID() { return id; } protected void setID (Long id) { this.id = id; } ...

42

SM

| 2004 JavaOne Conference | Session TS-1861

Example: EJB™ 3.0 Technology Entity Bean Today (Cont.) ... @OneToMany(cascade=ALL) public Set getOrders() { return orders; } public void setOrders(Set orders) { this.orders = orders; } // other business methods, etc. }

43

SM

| 2004 JavaOne Conference | Session TS-1861

Client View @Stateless public class OrderEntryBean { private EntityManager em; @Inject void setEntityManager(EntityManager em) { this.em = em; } public void enterOrder(int custID, Order newOrder){ Customer c = em.find(“Customer”, custID); c.getOrders().add(newOrder); newOrder.setCustomer(c); } // other business methods }

44

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ QL Enhancements

• • • • •

Bulk update and delete operations Projection list (SELECT clause) Group by, Having Subqueries (correlated and not) Additional SQL functions ─ UPPER, LOWER, TRIM, CURRENT_DATE, ...

• Dynamic queries • Polymorphic queries

45

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 2.1 Technology View Contractual view of components • Container specifies contracts ─ Interfaces ─ Callbacks ─ Deployment descriptor contract

• Beans written to contracts ─ Whether they need them or not

This is a very static viewpoint ─ It has a significant negative impact on application complexity

46

SM

| 2004 JavaOne Conference | Session TS-1861

EJB™ 3.0 Technology and Its Implications for EJB™ Technology Evolution

• View of the container as a service injection facility

─ Injection points specified through metadata ─ View of the container “disappears”

• View of “component” changes: ─ Classes that require/request services ─ Pick and choose what they need

• Contractual view becomes inverted ─ Bean does not implement predefined set of APIs ─ Instead, bean specifies what it needs

• More extensible architecture => our view of “container” evolves

47

SM

| 2004 JavaOne Conference | Session TS-1861

Summary and Status

• • • •

POJO-centric view of all enterprise beans POJIs required for session beans only Simplification of environment access Simplification of entity beans ─ Clear O/R mapping orientation ─ Improvement of query language capabilities

• Metadata is major enabling technology • Interesting implications for the future • Specification Early Draft is now available 48

SM

| 2004 JavaOne Conference | Session TS-1861

For More Information

• TS-2836 ─ EJB 3.0: Simplifying and Enhancing the Persistence Model ─ TS-2836 will also cover the new query language features we’ve added

• BOF-1864 ─ Enterprise JavaBeans™ 3.0 Technology Community Discussion ─ Come and meet members of the EJB™ 3.0 Technology Expert Group

49

SM

| 2004 JavaOne Conference | Session TS-1861

Q&A 50

SM

| 2004 JavaOne Conference | Session TS-1861

Enterprise JavaBeans™ 3.0 Work in Progress

Linda DeMichiel EJB Specification Lead Sun Microsystems java.sun.com/j2ee 51

SM

| 2004 JavaOne Conference | Session TS-1861

java.sun.com/javaone/sf

Related Documents

Ejb 3[1].0 Architecture
November 2019 3
Ejb
November 2019 25
Ejb
May 2020 13
Ejb
May 2020 11
Ejb
November 2019 22
Ejb
November 2019 25