Enterprise JavaBeans 3.1



Similar documents
Java EE 7: Back-End Server Application Development

rpaf KTl enterprise EJB 3.1 Cookbook I I flv* IV I I professional expertise distilled

Developing Java Web Services

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

WEB SERVICES. Revised 9/29/2015

How To Write A Nosql Database In Spring Data Project

Java Web Services Training

JVA-561. Developing SOAP Web Services in Java

Module 13 Implementing Java EE Web Services with JAX-WS

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

JavaScript Patterns. Stoyan Stefanov. O'REILLY' Beijing Cambridge Farnham Koln Sebastopol Tokyo

Web Services Development for IBM WebSphere Application Server V7.0. Version: Demo. Page <<1/10>>

JAX-WS Developer's Guide

Table of Content. Introduction to ObjectDB and JPA. Object Model: Types, Entities, Primary Keys. Database Connections

JAVA API FOR XML WEB SERVICES (JAX-WS)

OptimalJ Foundation. PSM EJB Model. Roadmap. What is the EJB model? EJB model as a PSM model Mapping the EJB model Model elements and code generation

Expert One-on-One J2EE Design and Development

Application Developer s Guide

Component Middleware. Sophie Chabridon. INT - INF Department - Distributed Systems team 2006

Contents 1 Overview 2 Introduction to WLS Management Services iii

How To Write A Web Framework In Java

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

Developing Web Services Applications

EJB & J2EE. Component Technology with thanks to Jim Dowling. Components. Problems with Previous Paradigms. What EJB Accomplishes

How To Protect Your Computer From Being Hacked On A J2Ee Application (J2Ee) On A Pc Or Macbook Or Macintosh (Jvee) On An Ipo (J 2Ee) (Jpe) On Pc Or

JSR 91 - OSS Trouble Ticket API Final Overview

The end. Carl Nettelblad

Principles and Foundations of Web Services: An Holistic View (Technologies, Business Drivers, Models, Architectures and Standards)

Chapter 4. Architecture. Table of Contents. J2EE Technology Application Servers. Application Models

FUSE-ESB4 An open-source OSGi based platform for EAI and SOA

ucosminexus Application Server and BPM/ESB Platform Terminology Guide Y99(E)

FIFTH EDITION. Oracle Essentials. Rick Greenwald, Robert Stackowiak, and. Jonathan Stern O'REILLY" Tokyo. Koln Sebastopol. Cambridge Farnham.

SOA Fundamentals For Java Developers. Alexander Ulanov, System Architect Odessa, 30 September 2008

RESIN APPLICATION SERVER JAVA EE 6 WEB PROFILE

Oracle WebLogic Server

Beginning POJOs. From Novice to Professional. Brian Sam-Bodden

Web Services in Oracle Fusion Middleware. Raghu Kodali Consulting Product Manager & SOA Evangelist Oracle Fusion Middleware Oracle USA

PL/SQL Programming Workbook

Software Development using MacroMedia s JRun

Web Service Development Using CXF. - Praveen Kumar Jayaram

PERFORMANCE EVALUATION OF JAVA OBJECT-RELATIONAL MAPPING TOOLS HASEEB YOUSAF. (Under the Direction of John A. Miller)

Listeners. Formats. Free Form. Formatted

Building and Using Web Services With JDeveloper 11g

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

APAC WebLogic Suite Workshop Oracle Parcel Service Overview. Jeffrey West Application Grid Product Management

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

rpafi/jl open source Apache Axis2 Web Services 2nd Edition using Apache Axis2 Deepal Jayasinghe Create secure, reliable, and easy-to-use web services

JAVA IN A NUTSHELL O'REILLY. David Flanagan. Fifth Edition. Beijing Cambridge Farnham Köln Sebastopol Tokyo

Redbooks Paper. WebSphere Application Server V5 Architecture. Carla Sadtler

Web Services Technologies Examples from the Mainstream

JAVA API FOR XML WEB SERVICES INTRODUCTION TO JAX-WS, THE JAVA API FOR XML BASED WEB SERVICES (SOAP, WSDL)

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

Chapter 5 Application Server Middleware

A Framework for Prototyping J2EE Replication Algorithms

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

professional expertise distilled P U B L I S H I N G EJB 3.1 Cookbook Richard M. Reese Chapter No.7 "EJB Security"

Windows PowerShell Cookbook

Cloud Architecture Patterns

Introduction to WebSphere Process Server and WebSphere Enterprise Service Bus

Reusing Existing * Java EE Applications from Oracle SOA Suite

JBoss SOAP Web Services User Guide. Version: M5

A standards-based approach to application integration

JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

WebSphere Training Outline

Java EE 6 Ce qui vous attends

JAVA r VOLUME II-ADVANCED FEATURES. e^i v it;

Das Spring Framework - Einführung in leichtgewichtige J2EE Architektur. Jürgen Höller. Organized by:

ActiveVOS Server Architecture. March 2009

TIBCO Business Studio iprocess Implementation Guide. Software Release February 2012

JSR 91 - Trouble Ticket API Final Overview

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Business Process Execution Language for Web Services

Oracle PL/SQL Programming

Object-Oriented Databases db4o: Part 2

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Closer Look at Enterprise Service Bus. Deb L. Ayers Sr. Principle Product Manager Oracle Service Bus SOA Fusion Middleware Division

T Network Application Frameworks and XML Web Services and WSDL Tancred Lindholm

Hadoop: The Definitive Guide

Announcements. Comments on project proposals will go out by in next couple of days...

}w!"#$%&'()+,-./012345<ya

Spring Data JDBC Extensions Reference Documentation

Java and J2EE (SCJA Exam CX ) 50 Cragwood Rd, Suite 350 South Plainfield, NJ 07080

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

JBOSS ESB. open source community experience distilled. Beginner's Guide. Enterprise. Magesh Kumar B

DEPLOYMENT ARCHITECTURE FOR JAVA ENVIRONMENTS

1 What Are Web Services?

NetBeans IDE Field Guide

No.1 IT Online training institute from Hyderabad URL: sriramtechnologies.com

WebLogic Server 11g Administration Handbook

Oracle Fusion Middleware

FHE DEFINITIVE GUIDE. ^phihri^^lv JEFFREY GARBUS. Joe Celko. Alvin Chang. PLAMEN ratchev JONES & BARTLETT LEARN IN G. y ti rvrrtuttnrr i t i r

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Learning ios Programming

Grid Computing. Web Services. Explanation (2) Explanation. Grid Computing Fall 2006 Paul A. Farrell 9/12/2006

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Programming Flash Communication Server

FREE ONLINE EDITION. (non-printable free online version) If you like the book, please support the author and InfoQ by. purchasing the printed book:

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

Transcription:

SIXTH EDITION Enterprise JavaBeans 3.1 Andrew Lee Rubinger and Bill Burke O'REILLY Beijing Cambridge Farnham Koln Sebastopol Tokyo

Table of Contents Preface xv Part I. Why Enterprise JavaBeans? 1. Introduction 3 The Problem Domain 3 Breaking Up Responsibilities 3 Code Smart, Not Hard 6 The Enterprise JavaBeans 3.1 Specification 8 Review 10 2. Component Types 11 Server-Side Component Types 12 Session Beans 12 Message-Driven Beans (MDBs) 15 Entity Beans 16 The Java Persistence Model 17 The Model Isn't Everything 17 3. Container Services 19 Dependency Injection (DI) 20 Concurrency 21 Instance Pooling/Caching 21 Transactions 23 Security 23 Timers 24 Naming and Object Stores 24 Interoperability 25 Lifecycle Callbacks 25 Interceptors 26 v

Platform Integration 27 Bringing It Together 27 4. Developing Your First EJBs 29 Step 1: Preparation 29 Definitions 29 Naming Conventions 32 Conventions for the Examples 32 Step 2: Coding the EJB 33 The Contract 33 The Bean Implementation Class 34 Out-of-Container Testing 35 Integration Testing 36 Summary 39 Part II. Server-Side Component Models 5. The Stateless Session Bean 43 The XML Deployment Descriptor 45 SessionContext 46 EJBContext 47 The Lifecycle of a Stateless Session Bean 49 The Does Not Exist State 50 The Method-Ready Pool 50 Example: The EncryptionEJB 52 The Contract: Business Interfaces 53 Application Exceptions 54 Bean Implementation Class 55 Accessing Environment Properties (Injection and Lookup) 57 Asynchronous Methods 60 6. The Stateful Session Bean 63 The Lifecycle of a Stateful Session Bean 64 The Does Not Exist State 65 The Method-Ready State 65 The Pa.ssivated State 66 Example: The FileTransferEJB 68 The Contract: Business Interfaces 69 Exceptions 70 Bean Implementation Class 70 POJO Testing Outside the Container 74 Integration Testing 77 vi Table of Contents

7. The Singleton Session Bean 81 Concurrency 82 Shared Mutable Access 84 Container-Managed Concurrency 86 Bean-Managed Concurrency 87 Lifecyele 87 Explicit Startup 87 Example: The RSSCacheEJB 88 Value Objects 89 The Contract: Business Interfaces 92 Bean Implementation Class 92 8. Message-Driven Beans 97 JMS and Message-Driven Beans 98 JMS as a Resource 98 JMS Is Asynchronous 99 JMS Messaging Models 100 Learning More About JMS 103 JMS-Based Message-Driven Beans 103 @MessageDriven 103 The Lifecyele of a Message-Driven Bean 108 The Does Not Exist State 109 The Method-Ready Pool 109 Connector-Based Message-Driven Beans 111 Message Linking 114 Session Beans Should Not Receive Messages 114 The JMS APIs 115 Example: The StatusUpdateEJBs 118 Part III. EJB and Persistence 9. Persistence: EntityManager 127 Entities Are POJOs 128 Managed Versus Unmanaged Entities 130 Persistence Context 130 a Packaging Persistence Unit 133 The Persistence Unit Class Set 135 Obtaining an EntityManager 136 EntityManagerFactory 137 Obtaining a Persistence Context 138 Interacting with an EntityManager 140 Example: A Persistent Employee Registry 141 Tableof Contents vii

A Transactional Abstraction 141 Persisting Entities 142 Finding and Updating Entities 144 Removing Entities 147 refresh () 148 containso and clear() 148 flush() and FlushModeType 148 Locking 149 unwrapo and getdelegate() 149 10. Mapping Persistent Objects 151 The Programming Model 152 The Employee Entity 152 The Bean Class 152 XML Mapping File 154 Basic Relational Mapping 155 Elementary Schema Mappings 155 Primary Keys 157 @Id 157 Table Generators 158 Sequence Generators 159 Primary-Key Classes and Composite Keys 160 Property Mappings 164 Transient 164 @Basic and FetchType 164 Lob 166 Temporal 166 Enumerated 167 Embedded Objects 167 11. Entity Relationships 171 The Seven Relationship Types 171 One-to-One Unidirectional Relationship 173 One-to-One Bidirectional Relationship 176 One-to-Many Unidirectional Relationship 178 Many-to-One Unidirectional Relationship 181 One-to-Many Bidirectional Relationship 182 Many-to-Many Bidirectional Relationship 184 Many-to-Many Unidirectional Relationship 187 Mapping Collection-Based Relationships 188 Ordered List-Based Relationship 188 Map-Based Relationship 189 Detached Entities and FetchType 190 viii Table of Contents

Cascading PERSIST 191 192 MERGE 192 REMOVE 193 REFRESH 193 ALL 193 When to Use Cascading 194 12. Entity Inheritance 195 Single Table per Class Hierarchy 196 Advantages 198 Disadvantages 198 Table per Concrete Class 199 Advantages Disadvantages Table per Subclass 200 Advantages 203 Disadvantages 203 Mixing Strategies 203 Nonentity Base Classes 203 13. Queries, the Criteria API, and JPAQL 205 Query API 206 Parameters 208 Date Parameters 209 Paging Results 209 Hints 210 FlushMode 210 JPAQL Abstract Schema Names 211 Simple Queries Selecting Entity and Relationship Properties 213 Constructor Expressions 215 The IN Operator and INNER JOIN 215 LEFT JOIN 216 Fetch Joins 217 Using DISTINCT 217 The WHERE Clause and Literals 218 The WHERE Clause and Operator Precedence 218 The WHERE Clause and Arithmetic Operators 219 The WHERE Clause and Logical Operators 219 The WHERE Clause and Comparison Symbols 219 The WHERE Clause and Equality Semantics 220 200 200 211 212 Table of Contents ix

The WHERE Clause and BETWEEN 221 The WHERE Clause and IN 221 The WHERE Clause and IS NULL 222 The WHERE Clause and IS EMPTY 223 The WHERE Clause and MEMBER OF 223 The WHERE Clause and LIKE 224 Functional Expressions 224 The ORDER BY Clause 228 Bulk UPDATE and DELETE 229 Native Queries 230 Scalar Native Queries 230 Simple Entity Native Queries 230 Complex Native Queries 231 Named Queries 232 Named Native Queries 233 14. Entity Callbacks and Listeners 235 Callback Events 235 Callbacks on Entity Classes 236 Entity Listeners 237 Default Entity Listeners 238 Inheritance and Listeners 238 Part IV. Container Services 15. Security 243 Authentication and Identity 244 Authorization 245 Example: A Secured School 246 The Business Interface 246 Assigning Method Permissions 247 Programmatic Security 249 The RunAs Security Identity 251 16. JNDI, the ENC, and Injection 255 Global JNDI 255 The JNDI ENC 256 What Can Be Registered in the JNDI ENC? 257 How Is the JNDI ENC Populated? 257 How Are Things Referenced from the ENC? 258 Reference and Injection Types 264 EJB References 264 x Table of Contents

EntityManagerFactory References 266 EntityManager References 269 Resource References 271 Resource Environment and Administered Objects 275 Environment Entries 275 Message Destination References 277 17. Transactions 279 ACID Transactions 279 Example: The BlackjackEJB 281 Helper EJBs for Testing Transactions 283 Is the BlackjackEJB Atomic? 284 Is the BlackjackEJB Consistent? 285 Is the BlackjackEJB Isolated? 285 Is the BlackjackEJB Durable? 285 Declarative Transaction Management 286 Transaction Scope 286 Transaction Attributes 287 Transaction Propagation 293 Isolation and Database Locking 298 Dirty, Repeatable, and Phantom Reads 298 Database Locks 299 Transaction Isolation Levels 300 Balancing Performance Against Consistency 301 Optimistic Locking 302 Programmatic Locking 303 Nontransactional EJBs 303 Explicit Transaction Management 304 Transaction Propagation in Bean-Managed Transactions 307 Heuristic Decisions 308 UserTransaction 309 Status 310 EJBContext Rollback Methods 312 Exceptions and Transactions 313 Application Exceptions Versus System Exceptions 313 Transactional Stateful Session Beans 318 The Transactional Method-Ready State 320 Conversational Persistence Contexts 321 18. Interceptors 323 Intercepting Methods 323 Interceptor Class 325 Applying Interceptors 327 Table of Contents xi

Interceptors and Injection 331 Intercepting Lifecycle Events 333 Custom Injection Annotations 333 Exception Handling 335 Aborting a Method Invocation 336 Catch and Rethrow Exceptions 336 Interceptor Lifecycle 338 Bean Class @Aroundlnvoke Methods 338 19. Timer Service 341 Example: A Batch Credit Card Processing System 342 The Business Interface 343 javax.ejb.scheduleexpression and @javax.ejb.schedule 344 The Bean Implementation Class 345 The TimerService 347 The Timer 348 Transactions 350 Stateless Session Bean Timers 351 Message-Driven Bean Timers 352 20. EJB 3.1: Web Services Standards 355 Web Services Overview 355 XML Schema and XML Namespaces 356 XML Schema 356 XML Namespaces 361 SOAP 1.1 368 Web Services Styles 369 Exchanging SOAP Messages with HTTP 370 Now You See It, Now You Don't 370 WSDL1.1 371 The <definirions> Element 372 The <porttype> and <message> Elements 374 The <cypes> Element 375 The <binding> and <service> Elements 377 UDDI 2.0 379 From Standards to Implementation 380 21. EJB 3.1 and Web Services 381 Accessing Web Services with JAX-RPC 381 Generating JAX-RPC Artifacts from WSDL 382 Calling a Service from an EJB 387 The <service-ref> Deployment Element 388 The JAX-RPC Mapping File 389 xii Table of Contents

Defining a Web Service with JAX-RPC 391 The WSDL Document 392 The Service Endpoint Interface 393 The Stateless Bean Class 393 The Deployment Files 394 Using JAX-WS 396 The @WebService Annotation 396 The @WebMethod Annotation 397 The SOAPBinding Annotation 398 The @WebParam Annotation 399 The @WebResult Annotation 400 The @OneWay Annotation 401 Separating the Web Services Contract 401 The Service Class 402 The Service Endpoint Interface 403 The @WebServiceRef Annotation 403 Other Annotations and APIs 405 JAXB 405 Taking JAXB Further 407 Conclusion 407 PartV. Examples A. FirstEJB Example 415 B. Stateless Session EJB: Encryption Example 429 C. Stateful Session EJB: FTP Client Example 453 D. Singleton Session EJB: RSS Cache Example 505 E. Message-Driven EJB: Status Update Listeners Example 527 F. Java Persistence APIs: Employee Registry Example 557 G. Security: Secured School Example 643 H. Transactions: Blackjack Game Example 663 I. Interceptors: TV Channel Service Example 691 Tableof Contents xiii

J. Timer Service: Credit Card Processor Example 719 Index 727 xiv Table ofcontents