ebook img

Beginning EJB 3 : Java EE 7 edition PDF

14 Pages·2013·0.48 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning EJB 3 : Java EE 7 edition

Beginning EJB 3 J8ava HEUH*Euna 7 «E—mdi| >t- i« on Jonathan Wetherbee Chirag Rathod Raghu Kodali Peter Zadrozny Apress* Contents Aboutthe Authors xxi Aboutthe Technical Reviewer xxiii Preface xxv Acknowledgments xxvii SChapter 1: Introduction to the EJBArchitecture 1 An Introductionto EJB 1 What IsEJB? 2 CoreFeaturesof theEJBDevelopment Model 2 Progression ofthe EJBSpec 4 EJB3SimplifiedDevelopment Model 5 DistributedComputingModel 7 How This Book Is Organized 8 Chapter 1:Introductiontothe EJB3Architecture 8 Chapter2:EJB Session Beans 8 Chapter 3:Entities andthe Java PersistenceAPI 9 Chapter4:Advanced Persistence Features 9 Chapter5:EJB Message-DrivenBeans 9 Chapter 6:EJB and Web Services 9 Chapter7:IntegratingSession Beans, Entities, Message-Driven Beans, andWeb Services 9 Chapter8:Transaction Support inEJB 9 Chapter9:EJB Performance andTesting 9 Chapter10: ContextsandDependencyInjection 10 vii CONTENTS Chapter11: EJBPackaging and Deployment 10 Chapter12: EJBClientApplications 10 Chapter13: Testing inan Embeddable EJBContainer 10 Getting Started 10 Downloadingthe NetBeans IDE 11 Installing NetBeans IDEandItsIntegratedGlassFishServer 12 Testing the NetBeans IDEandGlassFishInstallation 14 Administratingthe GlassFishApplication Server 19 Troubleshooting 20 Conclusion 23 Chapter2: EJB Session Beans 25 Introductionto Session Beans 25 Types of Session Beans 25 When DoYou Use Session Beans? 26 StatelessSession Beans 28 The Bean Class 28 The Business Interface 29 BusinessMethods 31 Dependency Injection 33 LifecycleCallbackMethods 33 Interceptors 34 Stateful Session Beans 36 The Bean Class 36 The Business Interface 37 BusinessMethods 38 Lifecycle CallbackMethods 39 Interceptors 40 ExceptionHandling 40 Singleton Session Beans 40 TheBean Class 40 TheBusinessInterface 42 viii CONTENTS BusinessMethods 42 LifecycleCallbackMethods 42 Concurrency Management 44 Error Handling 45 Timer Service 46 Calendar-BasedTime Expressions 47 Examples of Calendar-BasedTime Expressions 48 Timer Persistence 48 Client View for Session Beans 49 Compiling, Deploying,and Testingthe Session Beans 54 Prerequisites 54 Compiling theSession BeansandtheirClients 54 Deploying theSession BeansandtheirClients 56 Runningthe Client Programs 57 Conclusion 59 Chapter 3: Entities and the Java Persistence API 61 An Entity Example 62 A SimpleJavaBean: Customer.java 62 A SimpleEntity: Customer.java 63 An EntitywithDefaultsExposed: Customer.java 64 CodingRequirements 66 Entity DataAccess 67 PropertyName 67 Example:AnnotatingInstanceVariables 67 Example:AnnotatingPropertyAccessors 69 Declaringthe Primary Key 70 Simple Primary Key 70 CompositePrimary Key 71 Summary of Entity Examples 73 The PersistenceArchive 74 The persistence.xmlFile 74 ix CONTENTS The EntityManager 75 Persistence Context 75 Acquiringan EntityManagerInstance 75 Transaction Support 76 The Entity Life Cycle 77 The Life Cycleofa New Entity Instance 77 O/R Mapping 79 The ©TableAnnotation(Revisited) 79 The©ColumnAnnotation(Revisited) 80 Complex Mappings 81 Entity Relationships 81 ©OneToOne 81 ©OneToMany and©ManyToOne 82 ©ManyToMany 83 Lazyvs. EagerField Bindings 84 Cascading Operations 84 Java PersistenceQuery Language (JPQL) 85 ©NamedQuery and©NamedQueries 85 Binding Query Parameters 86 DynamicQueries 86 BulkUpdateand DeleteOperations 87 ComplexQueries 88 Persistencevs. Adaption 88 Forward Generation—Persistence 88 ReverseEngineering—Adaption 88 Which OneIsRightforYourProject? 88 ExampleApplication: CustomerOrderManager 88 Customer.java 89 Compiling, Deploying, and Testingthe JPA Entities 94 Openingthe SampleApplication 94 CreatingtheDatabaseConnection and SampleSchema 96 x CONTENTS Compiling the Entities,EJBs,andthe Client 97 Deployingthe JPAPersistence Unit,theEJB Module, and theServlet 97 Runningthe Client Programs 98 Conclusion 101 Chapter 4:Advanced Persistence Features 103 Mapping Entity Inheritance Hierarchies 104 Getting Started 104 Entity Inheritance MappingStrategies 105 Single-Table-per-Class Inheritance Hierarchy(lnheritanceType.SINGLE_TABLE) 107 Common BaseTablewithJoined SubclassTables (InheritanceType.JOINED) 119 Single-Table-per-OutermostConcreteEntity Class(lnheritanceType.TABLE_PER_CLASS) 122 ComparisonofO/RImplementation Approaches 125 Using Abstract Entities, Mapped Superclasses, and Non-Entity Classes inan InheritanceHierarchy 126 AbstractEntity Class 126 Mapped Superclass(©MappedSuperclass) 127 Non-entity Class 128 Non-entity Single-valueandCollection Fields 129 Polymorphic Relationships 132 RelationshipMapping 132 Polymorphic JPQL Queries 132 Using NativeSQLQueries 133 The QueryCriteriaAPI 133 Composite Primary Keysand Nested Foreign Keys 134 Using anEmbedded CompositeKey(OEmbeddedld) 135 ExposingCompositeKeyClass Fields Directlyonthe Entity Class(OldClass) 136 MappingRelationshipsThatUse Composite Keys 137 Supportfor Optimistic Locking (©Version) 138 Support forAutogenerated Primary KeyValues (©GeneratedValue) 139 Interceptors: Entity Callback Methods 141 xi CONTENTS Compiling, Deploying,and Testingthe JPAEntities 142 Prerequisites 142 Opening theSampleApplication 142 CreatingtheDatabase Connection 144 Compiling the Sources 145 Running theClient Programs 145 Testing the OtherPersistence Examples 147 Conclusion 147 MappingEntity Inheritance Hierarchies 148 UsingAbstract Entities,Mapped Superclasses, andNon-Entity Classes in an Inheritance Hierarchy 148 PolymorphicRelationships 148 PolymorphicJPQL Queries 148 UsingNativeSQL Queries 148 UsingtheQueryCriteria API 148 Composite Primary KeysandNestedForeign Keys 148 Support for Optimistic Locking 149 Support forAutogenerated PrimaryAutomatic KeyValues 149 Interceptors: Entity CallbackMethods 149 Chapter 5: EJB Message-Driven Beans 151 Message-OrientedArchitecture 151 WhatlsJMS? 151 MessagingApplication Architecture 152 Using MDBs 154 When DoYou Use MDBs? 154 MDBClasses 155 ConfigurationProperties 157 Dependency Injection inMDBs 159 LifecycleCallbackMethods 161 Interceptors 161 Exception Handling 162 ClientView 162 xii CONTENTS Compiling, Deploying, and Testing MDBs 165 Prerequisites 166 Compiling the Session BeansandMDBs 166 CreatingtheJMS andJavaMailResources 168 Deploying theSession Beans, MDBs,andtheirClients 172 Runningthe Client Programs 173 Conclusion 175 Chapter6: EJB and Web Services 177 WhatAreWeb Services? 177 UDDI 178 WSDL 178 SOAP 182 REST 183 When DoYouUseWeb Services? 185 JavaEE and Web Services 185 JAX-WS 185 JAX-RS 186 JAXB 186 JAXR 186 SAAJ 186 JSR181 187 EJB Stateless Session Beans as Web Services 187 Developinga NewWeb Service 187 Packaging, Deploying, andTestingWeb Services 190 Prerequisites 190 Compiling theSession Bean 190 Deployingthe Session Bean-BasedWeb Service 192 Testingthe CreditService 193 xiii CONTENTS Web Service ClientView 196 DevelopingaJavaClientThatAccessestheWeb Service 196 Session BeansasWeb Service Clients 203 Conclusion 204 Chapter 7: Integrating Session Beans, Entities, Message-Driven Beans, and Web Services 205 Introduction 205 Application Overview 205 Application Componentsand Services 206 The ShoppingCart Component 206 The Search FacadeComponent 206 The Customer Fagade Component 206 The OrderProcessingFagadeComponent 207 Persistence Services 207 The E-mailService 207 The Credit Service 207 TheOrder ProcessingService 207 The Wines OnlineApplication Business Process 207 In-Depth Component/Service Walkthrough 208 Persistence Services 209 TheCustomerFacadeComponent 209 TheSearch Fagade Component 211 The ShoppingCartComponent 212 TheOrderProcessing FagadeComponent 217 The OrderProcessingService 223 The E-mail Service 227 The Credit Service 228 The Database Schema : 228 Building, Deploying, and Testingthe Application 229 Prerequisites 229 Creatingthe Database Connection 230 xiv CONTENTS CreatingtheJMS and JavaMailResources 231 Openingthe SampleApplication 231 Configuringthe EJBWeb Service 232 [email protected] andthe user.properties File 232 Building, Deploying,andExecutingthe SampleApplication 233 The Servlet Output 236 TheResultingE-mail 236 Conclusion 237 Chapter8: Transaction Support in EJB 239 WhatIs a Transaction? 239 DistributedTransactions 240 TheACID Propertiesof aTransaction 240 TheJavaTransactionAPI (JTA) 241 TheTwo-PhaseCommit Protocol 241 Transaction Support in EJB 241 EJBTransaction Services 241 Session BeanTransactional Behavior inthe Service Model 242 Container-ManagedTransaction (CMT) Demarcation 242 Bean-ManagedTransaction (BMT) Demarcation 245 Implicit Commit vs. Explicit Commit 246 UsingTransactionswith JPA Entities 246 RelationshipBetweenEntities andaTransaction Context 247 Container-Managed vs.Application-ManagedPersistence Context 247 Transaction-Scoped Persistence Context vs.ExtendedPersistence Context 247 JTAvs. Resource-Local EntityManagers 248 Two Sample Scenarios 248 StatelessSessionBeanswithCMT Demarcation 248 Java Facade UsingApplication-Managed EntityManager 256 Filtering TestDataUsinga CMTSession Bean 259 Stateful Session Beans withBMTDemarcation and Extended Persistence Context 264 XV

Description:
Beginning EJB 3. 8. HUH* una. «—m. | >. -. « Java EE 7 Edition. Jonathan Wetherbee. Chi rag Rathod. Raghu Kodali. Peter Zadrozny. Apress*
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.