1. Trang chủ
  2. » Công Nghệ Thông Tin

Mastering Enterprise JavaBean Second Edition potx

672 172 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 672
Dung lượng 2,28 MB

Nội dung

Mastering Enterprise JavaBeans ™ Second Edition Thanks for downloading this file! This is a non-printable Adobe Acrobat PDF file and represents the complete Mastering EJB 2nd edition book. So why did we make the PDF non-printable? For a few reasons: 1) The intention of this PDF file is to give you free access to preview the book before buying it. 2) Any book that you printed wouldn't look nice. It would be ugly, unbound, and would lack a cover. 3) It costs more money in paper and toner to print the book than to buy it! Some people have told me that it's a bad idea to distribute this PDF, and that I will lose book sales as a result. I think they're wrong! I think that offering the book online will show people how great the book really is, and then they'll want to own it for themselves. So if you like this book, you can buy it right now on Amazon.com. Click here: http://www.amazon.com/exec/obidos/ASIN/0471417114/ref%3Dase%5Ftheserversidecom/002-9677343-9350405 Also, if you're just starting to learn about EJB, you may want to check out http://www.TheServerSide.com, which is a great web site to learn about the latest J2EE news. You also may want to check out The Middleware Company ( http://www.middleware-company.com ), which offers EJB training courses to take your knowledge to the next level. Click on the link above to find out more. Thanks again, and enjoy. -Ed Roman John Wiley & Sons, Inc. NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINGAPORE • TORONTO Wiley Computer Publishing Ed Roman Scott Ambler Tyler Jewell Mastering Enterprise JavaBeans ™ Second Edition Publisher: Robert Ipsen Editor: Robert M. Elliott Developmental Editor: Emilie Herman Managing Editor: John Atkins Associate New Media Editor: Brian Snapp Text Design & Composition: MacAllister Publishing Services, LLC Designations used by companies to distinguish their products are often claimed as trade- marks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should con- tact the appropriate companies for more complete information regarding trademarks and registration. This book is printed on acid-free paper. Copyright © 2002 by The Middleware Company. All rights reserved. Published by John Wiley & Sons, Inc. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copy- right Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, (212) 850-6011, fax (212) 850- 6008, E-Mail: permreq@wiley.com. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold with the understanding that the publisher is not engaged in professional services. If professional advice or other expert assistance is required, the services of a competent professional person should be sought. Library of Congress Cataloging-in-Publication Data: ISBN: 0-471-41711-4 Printed in the United States of America. 10 9 8 7 6 5 4 3 2 1 To my wonderful wife, Younhi. — Ed Roman Acknowledgments xix Preface xxi Introduction xxv About the Author xxxi Part One Overview 1 Chapter 1 Overview 3 The Motivation for EJB 4 Divide and Conquer to the Extreme 5 Component Architectures 12 Introducing Enterprise JavaBeans 13 Why Java? 14 EJB as a Business Solution 14 The EJB Ecosystem 16 The Bean Provider 17 The Application Assembler 17 The EJB Deployer 18 The System Administrator 19 The Container and Server Provider 19 The Tool Vendors 20 Summary of Roles 20 The Java 2 Platform, Enterprise Edition (J2EE) 22 The J2EE Technologies 23 Summary 26 Chapter 2 EJB Fundamentals 29 Enterprise Beans 29 Types of Beans 30 Distributed Objects: The Foundation for EJB 32 Distributed Objects and Middleware 34 Explicit Middleware 34 Implicit Middleware 35 What Constitutes an Enterprise Bean? 37 The Enterprise Bean Class 37 CONTENTS vii The EJB Object 38 The Home Object 44 The Local Interfaces 46 Deployment Descriptors 50 Vendor-Specific Files 51 Ejb-Jar File 51 Summary of Terms 52 Summary 54 Chapter 3 Writing Your First Bean 55 How to Develop an EJB Component 55 The Remote Interface 57 The Local Interface 58 The Home Interface 58 The Local Home Interface 59 The Bean Class 62 The Deployment Descriptor 66 The Vendor-Specific Files 67 The Ejb-jar File 67 Deploying the Bean 68 The Optional EJB Client JAR file 68 Understanding How to Call Beans 69 Looking up a Home Object 70 Running the System 74 The Server-Side Output 75 The Client-Side Output 75 Implementing Component Interfaces 75 A Solution 76 Summary 77 Part Two The Triad of Beans 79 Chapter 4 Introduction to Session Beans 81 Session Bean Lifetime 81 Session Bean Subtypes 82 Stateful Session Beans 82 Stateless Session Beans 83 Special Characteristics of Stateful Session Beans 84 Achieving the Effect of Pooling with Stateful Beans 85 The Rules Governing Conversational State 86 Activation and Passivation Callbacks 87 CONTENTS viii Method Implementation Summary 89 A Simple Stateful Session Bean 89 Life Cycle Diagrams for Session Beans 100 Summary 103 Chapter 5 Introduction to Entity Beans 105 Persistence Concepts 105 Java Object Serialization 106 Object-Relational Mapping 106 Object Databases 109 What Is an Entity Bean? 109 About the Files that Make up an Entity Bean 112 Features of Entity Beans 112 Entity Beans Survive Failures 112 Entity Bean Instances Are a View into a Database 113 Several Entity Bean Instances May Represent the Same Underlying Data 114 Entity Bean Instances Can Be Pooled 116 There Are Two Ways to Persist Entity Beans 118 Creation and Removal of Entity Beans 119 Entity Beans Can Be Found 121 You Can Modify Entity Bean Data without Using EJB 123 Entity Contexts 124 getEJBLocalObject() / getEJBObject() 124 getPrimaryKey() 125 Summary 126 Chapter 6 Writing Bean-Managed Persistent Entity Beans 127 Entity Bean Coding Basics 127 Finding Existing Entity Beans: ejbFind() 129 Bean-Managed Persistence Example: A Bank Account 136 Account.java 137 AccountLocal.java 138 AccountHome.java 138 AccountLocalHome.java 138 AccountPK.java 139 AccountBean.java 143 AccountException.java 156 Client.java 156 The Deployment Descriptor 156 The Container-Specific Deployment Descriptor 161 Setting up the Database 161 Running the Client Program 161 Server-Side Output 162 Client-Side Output 163 CONTENTS ix Putting It All Together: Walking through a BMP Entity Bean’s Life Cycle 163 Summary 166 Chapter 7 Writing Container-Managed Persistent Entity Beans 167 Features of CMP Entity Beans 167 CMP Entity Beans Are Subclassed 167 CMP Entity Beans Have No Declared Fields 168 CMP Get/Set Methods Are Defined in the Subclass 170 CMP Entity Beans Have an Abstract Persistence Schema 172 CMP Entity Beans Have a Query Language 173 CMP Entity Beans Can Have ejbSelect() Methods 175 Implementation Guidelines for Container-Managed Persistence 176 Container-Managed Persistence Example: A Product Line 180 Product.java 181 ProductLocal.java 182 ProductHome.java 182 ProductLocalHome.java 184 ProductPK.java 184 ProductBean.java 187 The Deployment Descriptor 191 The Container-Specific Deployment Descriptor 195 Client.java 196 Running the Client Program 196 The Life Cycle of a CMP Entity Bean 200 Summary 200 Chapter 8 Introduction to Message-Driven Beans 201 Motivation to Use Message-Driven Beans 201 The Java Message Service (JMS) 203 Messaging Domains 204 The JMS API 206 Integrating JMS with EJB 211 What Is a Message-Driven Bean? 212 Developing Message-Driven Beans 214 The Semantics 214 A Simple Example 215 Advanced Concepts 223 Message-Driven Bean Gotchas 225 Message Ordering 225 Missed ejbRemove() Calls 226 Poison Messages 228 CONTENTS x [...]... paradigm shift and career move for me What did Court say? Nothing profound, but simply, “You know Ed, this stuff is really what Enterprise JavaBeans is for.” xxi xxii P R E FA C E At first, I had no idea what he was talking about Enterprise JavaBeans? What’s that? Something like regular JavaBeans? Eventually, Court managed to explain to me what EJB was And once he explained it, I knew that Trilogy had to do... Handles Summary Part Three Advanced Enterprise JavaBeans Concepts Chapter 10 Transactions Motivation for Transactions Atomic Operations Network or Machine Failure Multiple Users Sharing Data Benefits of Transactions The ACID Properties Transactional Models Flat Transactions Nested Transactions Other Transactional Models Enlisting in Transactions with Enterprise JavaBeans Underlying Transaction System... understand this book While you’re reading this book, you may want to download the EJB specification, available on http://java.sun.com Goals for This Edition The first edition of this book came out in 1999 We had to make some tough calls when writing the second edition, and we are confident you’ll like them Here are our goals: ■ ■ To update the book for EJB 2.0 EJB 2.0 has many new useful features that we... let’s begin our exploration of Enterprise JavaBeans with Part 1, an introduction to EJB concepts and programming ABOUT THE AUTHOR Ed Roman is one of the world’s leading authorities on high-end middleware technologies He has been heavily involved with Sun Microsystems’ enterprise Java solutions from their inception, and has designed, built, and deployed a variety of enterprise applications, including... object expo, Java expo, and application development ONE PA R T Overview 2 OVERVIEW I n Part 1, we introduce the server-side development platform that is the Java 2 Platform, Enterprise Edition (J2EE), of which the Enterprise JavaBeans (EJB) component architecture is a vital piece J2EE is a conglomeration of concepts, programming standards, and innovations—all written in the Java programming language... covered: Chapter 1 is a tour of enterprise computing We’ll talk about components, distributed frameworks, and containers We’ll also introduce EJB and J2EE Chapter 2 moves onto the fundamentals of building an EJB system, including the tricky concept of request interception We’ll also look at the files that makeup an enterprise bean Chapter 3 shows you how to put together a simple enterprise bean We’ll also... EJBLocalObject EJBMetaData EJBObject EnterpriseBean EntityBean EntityContext Handle HomeHandle MessageDrivenBean MessageDrivenContext SessionBean SessionContext SessionSynchronization Exception Reference Transaction Reference Index 616 617 621 A C K N O W L E D G E M E N TS T his book has been a project spanning several years Many have commented that the first edition was one of the best technical... post them on TheServerSide.com to share with others Our goal is to increase our knowledge of EJB as a community, and together, we can do it Ed Roman I NTRO D U CTI O N T his book is a tutorial on Enterprise JavaBeans (EJB) It’s about EJB concepts, methodology, and development This book also contains a number of advanced EJB topics, giving you a practical and real-world understanding of the subject By... commented that the first edition was one of the best technical books they ever read What’s made this book a reality are the many people that aided in its development We took a big risk in developing the second edition of this book and decided to build the book on the Web We received feedback from around the world when writing this book, and thus we have an evolving list of contributors and reviewers The... resource management, and security We’ll look at each of the different parties that are involved in an EJB deployment We’ll also survey the J2EE server-side development platform Chapter 2 moves on to the Enterprise JavaBeans fundamentals We’ll look at the concept of request interception, which is crucial for understanding how EJB works We’ll also look at the different files that go into a bean and how they . Mastering Enterprise JavaBeans ™ Second Edition Thanks for downloading this file! This is a non-printable Adobe Acrobat PDF file and represents the complete Mastering EJB 2nd edition. SINGAPORE • TORONTO Wiley Computer Publishing Ed Roman Scott Ambler Tyler Jewell Mastering Enterprise JavaBeans ™ Second Edition Publisher: Robert Ipsen Editor: Robert M. Elliott Developmental Editor:. Vendors 20 Summary of Roles 20 The Java 2 Platform, Enterprise Edition (J2EE) 22 The J2EE Technologies 23 Summary 26 Chapter 2 EJB Fundamentals 29 Enterprise Beans 29 Types of Beans 30 Distributed

Ngày đăng: 29/06/2014, 10:20