ebook img

Using and Understanding Java Data Objects PDF

444 Pages·2003·10.099 MB·English
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 Using and Understanding Java Data Objects

Using and Understanding Java Data Objects DAVIDEZZIO atft APress Media, LLC Using and Understanding Java Data Objects Copyright.© 2003 by David Ezzio Originally published by Apress in 2003 All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN 978-1-59059-043-0 ISBN 978-1-4302-0767-2 (eBook) DOI 10.1007/978-1-4302-0767-2 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Technical Reviewers: Regis Le Brettevillois, John Mitchell, Abe White Editorial Directors: Dan Appleman, Gary Cornell, Martin Streicher, Karen Watterson, John Zukowski Assistant Publisher: Grace Wong Project Manager: Tracy Brown Collins Copy Editor: Ami Knox Production Editor: Julianna Scott Fein Composition: Susan Glinert lndexer: Valerie Robbins Proofreader: Elizabeth Berry Cover Designer: Kurt Krames Production Manager: Kari Brooks Manufacturing Manager: Tom Debolski The information in this book is distributed onan "as is" hasis, without warranty. Although every precaution bas been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this bookis available to readers at http: 1/ 'IMtl.apress.com in the Downloads section. This book is dedicated to my wife, Theresa, and our daughters, Pearly and Sarah. A man is a fish who swims in the sea ofa woman's love. Contents at a Glance About the Author ................................................................................................. xi About the Technical Reviewers .................................................................. xiii Acknowledgments ...................................................................................................x v Introduction ...................................................................................................... xvii Chapter 1 Basic Concepts in JDO .......................................................... 1 Chapter 2 Queries ........................................................................................ 37 Chapter 3 The Persistence Manager .................................................... 75 Chapter 4 Transactions and Caching ................................................ 103 Chapter 5 Enhanced Classes and Managed Fields ........................ 143 Chapter 6 Factories That Produce Persistence Managers ........................................................ 185 Chapter 7 Helpers, Callbacks, and Exceptions .......................... 227 Chapter 8 Using JDO to Learn More .................................................. 269 Chapter 9 Using JDO in a Swing Application .............................. 301 Chapter 10 Using JDO in a Web Application ................................... 321 Chapter 11 Using JDO in Enterprise JavaBeans ............................ 359 Glossary ............................................................................................................... 377 Appendix Large UML Diagrams ............................................................ 387 Index ...................................................................................................................... 403 v Contents About the Author .......................................................................................... xi About the Technical Reviewers ...................................................... xiii Acknowledgments ............................................................................................. xv Introduction ................................................................................................. xvii Chapter Basic Concepts in JDO ................................................. 1 1 The Persistence Services of JDO ................................................................. 3 Managed and Unmanaged Objects ..................................................................... 7 The Ten Management States of Data Objects ......................................... 17 Identity and the Uniqueness Requirement .............................................. 21 Sununary ................................................................................................................... 36 Chapter 2 Queries ................................................................................... 37 The Extent Interface ....................................................................................... 37 The Design of JDO, s Query Service ........................................................... 41 The Query Interface ......................................................................................... 41 Factory Methods That Produce Query Objects ....................................... 48 The Syntax of the JDO Query Filter .................................... ~ ................... 49 Query Variables .................................................................................................. 55 Ordering Results ................................................................................................ 60 Using or Ignoring the Cache in a Query ................................................ 62 SQL Queries That Can Be Mapped to JDOQL .............................................. 64 Using SQL When JDOQL Is Not Sufficient ................................................ 71 How JDO and JDOQL Help the Development Process .............................. 72 Summary ................................................................................................................... 73 vii Contents Chapter 3 The Persistence Manager .......................................... 75 The Handling of null Values in Method Parameters .......................... 76 Obtaining and Closing a Persistence Manager ..................................... 77 Controlling JDO's Management of Data Objects ................................... 78 Controlling the Cache ..................................................................................... 89 Getting and Constructing Identity Objects ......................................... 95 Fetching an Application Data Object by Identity ............................ 97 Factory Methods in the Persistence Manager ....................................... 98 Getting the Persistence Manager's Transaction ................................. 98 The Properties of a Persistence Manager .............................................. 99 Summary .................................................................................................................. 101 Chapter 4 Transactions and Caching ..................................... 103 Transactions ....................................................................................................... 104 JDO's Transaction Interface ...................................................................... 108 How the Transactional Properties Control State Transitions ................................................................... 122 The Optional Transient-Transactional Feature ................................. 133 JCA, JTA, and JDO Transactions ............................................................... 135 JDO' s Cache of Persistent Objects and Their State ...................... 137 Summary .................................................................................................................. 141 Chapter 5 Enhanced Classes and Managed Fields ......... 143 Which Application Classes Should Be Enhanced? ............................... 143 Managed and Unmanaged Fields .................................................................... 144 Enhancement ......................................................................................................... 148 The JDO Metadata .............................................................................................. 166 Summary .................................................................................................................. 182 Chapter 6 Factories That Produce Persistence Managers ................................................ 185 The PersistenceManagerFactory Interface ............................................ 185 Obtaining a Persistence Manager ............................................................. 186 Obtaining a Persistence Manager Factory ............................................ 188 Closing a Persistence Manager Factory ................................................ 194 Obtaining a Connection Factory ............................................................... 195 Examining a JDO Implementation ............................................................... 195 viii Contents Configuring a Persistence Manager Factory ....................................... 198 Configuring Connections to the Datastore ......................................... 198 JDO's Support for Container-Managed Transactions ........................ 199 JDO's Support for Bean-Managed Transactions ................................... 201 Using JDO in CMT Session Beans ............................................................... 201 On Returning Serialized Data Objects from Business Methods ............................................................................ 208 Using JDO in Entity Beans with BMP ...................................................... 209 Using JDO in BMT Session Beans ............................................................... 220 Using JDO in Message-Driven Beans ......................................................... 225 Summary ................................................................................................................. 225 Chapter 7 Helpers, Callbacks, and Exceptions ........... 227 The JDOHelper Utility Class ...................................................................... 227 The InstanceCallbacks Interface ............................................................. 234 The Exceptions of JDO ................................................................................... 249 Summary ................................................................................................................. 267 Chapter 8 Using JDO to Learn More ........................................ 269 The Ant Build Scripts ................................................................................... 270 Getting Started ................................................................................................ 271 Hello, JDO! ......................................................................................................... 276 Interrogating the PersistenceManagerFactory ................................... 278 Consuming Java at the MegaCups Company .............................................. 280 The Console User Interface ........................................................................ 283 Querying the Small Town Library ............................................................. 284 Monitoring the State of Persistent Apples ....................................... 289 Using the Commercial Implementations .................................................. 298 Summary ................................................................................................................. 300 Chapter 9 Using JDO in a Swing Application ................. 301 Building the Rental Swing Application ................................................ 301 Requirements for the Prototype Reservation System ...................... 302 Testing the Rental Swing Client ............................................................. 306 Encountering Conflicting Changes in the Rental Swing Client ................................................................................ 308 Designing the Rental Swing Application .............................................. 310 Summary ................................................................................................................. 319 ix Contents Chapter 10 Using JDO in a Web Application ...................... 321 Configuring the Build Environment for Tomcat ................................. 321 Building the Rental Web Application .................................................... 323 Using the Rental Web Application ........................................................... 325 General Design Issues for Web Applications ..................................... 332 The MVC Pattern in the Rental Web Application ............................... 333 Designing the Use of JDO in a Web Application ............................... 334 The One-PM-per-Request Design .................................................................. 339 The One-PM-per-Session Design .................................................................. 354 The One-PM-per-Update Design .................................................................... 355 Summary .................................................................................................................. 357 Chapter 11 Using JDO in Enterprise JavaBeans .............. 359 Configuring the Build Environment for JBoss ................................... 360 Building the Rental Enterprise Application ..................................... 365 Design of the Rental Enterprise Application ................................... 367 Using JDO with other Types of EJBs ....................................................... 373 Summary .................................................................................................................. 375 Glossary ............................................................................................................ 377 Appendix Large UML Diagrams ..................................................... 387 Index .................................................................................................................... 403 X About the Author David Ezzio wrote his first application, which analyzed French elections, for a college professor in the sixties. After a detour through philosophy and other pursuits, he has worked with software teams building desktop applications, character recognition software, and Internet-related software. He has worked exclusively with Java since 1997 and is a Sun Certified Java Developer. Dave founded his consulting practice, Yankee Software, in 1988 and helped found MaineJUG in 2001. He is a member of the JDO 1.0 maintenance group. Dave holds a bachelor's degree in mathematical logic from Yale University and a master's degree in philosophy from the University of Chicago. In his free time, Dave hikes, rides his bicycle, reads history, and sails his Laser Tipp ity. An occasional cook, he currently takes pride in his popovers. He lives in Maine. His e-mail address is dezzio@ysoft. com. xi

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.