Preface

The need for persistence is a prerequisite for any enterprise application, and the case is no different for applications written in the Java programming language. A chunk of any typical Java application consists of code that is responsible for storing and retrieving the application-specific data to some type of storage facility so that it can be retrieved and used at a later time.

Java is an object-oriented language, and developers inherently work with objects that, at any time, have states represented by member fields. From the developers perspective, persistence focuses on taking the application-specific information assets, which in fact is just state in these objects, and making them available beyond the lifetime of the virtual machine process. In short, data should be available once the Java virtual machine has exited.

The realization of this notion by developers can take many shapes: extracting and storing the state in a file or in a database using JDBC, using Java serialization and storing the binary representation of the entire object, or the more common enterprise approach of leveraging the facilities of an application server via EJBs to name a few. Irrespective of the technique and the varying degree of complexity involved, each of these approaches has one common conceptual characteristic: the dependence on the developer to extract state information from the objects when it needs to be saved and re-create that state in the object representation when needed by the application.

Now there is a new alternative—Java Data Objects (JDO)—that is well placed to change the way developers have traditionally perceived persistence in their applications. JDO is a standard developed under the auspices of the Java Community Process by a number of industry participants. The JDO specifications were the realization of an effort to satisfy the need for a transparent persistence mechanism in Java that would satisfy two orthogonal visions at the same time. One aimed to provide a standard programming interface between application code and the underlying persistent stores like databases and file systems in a manner similar to JDBC; the other aimed to simplify secure and scalable application development by providing a Java-centric mechanism that would allow the manipulation and traversal of persistent objects. JDO satisfies, in fact excels, at both. With JDO, developers can concentrate on designing applications around the intended purpose—to solve business problems—rather than around the mechanics of persistence infrastructures.

JDO is fast gaining momentum and acceptance in the community as the preferable means to introduce persistence in Java applications. Developers are learning to appreciate the simplicity and power of this technology, and architects are pleased at the reduced development time. In this book, we not only guide the reader in understanding JDO itself, but help readers learn how to apply this technology effectively in real-world applications.

Audience

JDO is a new technology, but it is one that holds great promise. If you are an architect, a developer, or even a manager who is involved with persistence in Java and would like to gain an insight into this technology, then this book is for you.

The driving goal of this author team is to combine their wealth of experience into a single accessible and unified resource and give the community a definitive and authoritative source to turn to for JDO technology. The team strives to provide leading edge and practical examples that illustrate how JDO can be applied to existing applications and new architecture initiatives so that readers can have a clear perspective of this new technology. We hope that professionals using Java in any measure, from simple programs to complex enterprise applications, find this book valuable. Where additional detail is required, this book provides the stepping-stone and points out additional sources of information.

In keeping with the vision of Java itself, this book attempts to stay vendor- and platform-neutral. Possible implementation strategies may be discussed occasionally, but the goal of the author team is not to discuss intricate details, recommend, or push any specific vendor product.

What This Book Is About

This book is about:

  • Everything JDO, in that the book provides an in-depth explanation about the technology

  • Applying JDO in applications ranging from standalone programs to J2EE components

  • The best practices in designing and developing applications that use JDO

Part One—Introduction

Chapter 1: JDO Overview

Java Data Objects is a new standard for persistence in Java applications. JDO is well placed to change the fundamental way in which architects and developers approach the design and development of persistence in Java applications. This chapter gives you an insight into the concepts around which JDO is centered.

Chapter 2: Object Persistence Fundamentals

Chapter 2 looks at what's technically behind object persistence. It explains and compares different ways to implement persistence frameworks. It takes a broad view of the JDBC-based object-relational mapping solutions and outlines the effort of implementing such a framework from scratch.

Part Two—The Details

Chapter 3: Getting Started with JDO

This chapter explains the basics of how JDO works and how to use JDO to create, read, update, and delete persistent objects. It introduces some of the advanced concepts behind JDO and aims to provide sufficient understanding to allow a Java programmer to develop an application using JDO.

Chapter 4: Lifecycles

This chapter discusses the lifecycle of objects and the reasons why state changes can be meaningful to the application developer. A closer look is taken at mandatory and optional states of instances, the methods to gather information about states, and methods that lead to state transitions.

Chapter 5: Developing with JDO

This chapter looks at fundamental JDO concepts and all the classes and APIs defined by the JDO specification. It explains each of the methods for interfaces like the PersistenceManager, the JDOHelper, and I18NHelper classes, overviews JDO exception classes, and the classes and interfaces in the service provider interface package.

Chapter 6: Finding Your Data

This chapter discusses the query facility provided by JDO specification. The techniques surrounding the retrieval and querying of the underlying datatstore using the API and the JDOQL (JDO Query Language) are discussed with detailed examples.

Chapter 7: Architecture Scenarios

This chapter outlines the different types of application architectures that can be used with JDO. It covers when to use JDO versus JDBC, different types of datastores that can be used with JDO, using JDO with multi-tier applications, and using multi-threaded programming with JDO.

Part Three—J2EE

Chapter 8: JDO and the J2EE Connector Architecture

This chapter explains how JDO can be used in conjunction with J2EE via the J2EE Connector Architecture (JCA). After a brief introduction to JCA, this chapter looks at how JCA fits together with JDO and how they can be used together to build J2EE applications.

Chapter 9: JDO and Enterprise JavaBeans (EJB)

This chapter looks at the Enterprise JavaBeans (EJB) component model and its relationship to JDO. It addresses various implementation topics and provides extensive source code examples. The goal of this chapter is not to simply show 'how' to code EJB and JDO together, but also to help you decide if the combination of these two APIs makes sense for you.

Chapter 10: Security

This chapter defines the different levels of security, their requirements, and their objectives. It looks at the Reference Enhancer, and examines the rules and measures defined by JDO to secure an application. Finally, the chapter looks at application-level security and how J2EE and JDO work together regarding security.

Chapter 11: Transactions

This chapter looks at some fundamental concepts around transactions in Java, the transaction capabilities included in JDO, and how they can be used in standalone applications and in conjunction with Java Transaction APIs (JTA) in managed environments. It also outlines design considerations and practices when using JDO in a transactional manner.

Part Four—The Conclusion

Chapter 12JDO and Java Database Connectivity (JDBC)

This chapter reviews the JDBC API, gives a brief overview of relational databases, looks at the history of JDBC, and provides an introduction to the new JDBC 3.0 API. The second part of the chapter compares JDBC with JDO, discusses features and differences of each, and highlights common misconceptions.

Chapter 13: Best Practices

This chapter provides some suggestions, usage guidelines, and best practices for using JDO successfully in typical real-world enterprise business applications.

Chapter 14: Current Status and the Road Ahead

This chapter provides the reader with a possible roadmap and the direction that JDO is likely to take. Features covered in this chapter are in no way guaranteed to make it into JDO 2.0, nor do they represent the limit of new features that may be considered. Rather, this chapter aims to give some insight into what may appear in future revisions of the JDO specification.

Chapter 15: Case Study

This chapter discusses a complete working example of the “Core JDO Library” to put come context around material covered in this book and to give the reader an insight into how applications can be developed with JDO. The “Core JDO Library” application is an implementation of a couple of use cases to explain basic and advanced JDO features. It is also meant to explain concepts mentioned in the previous chapters such as two-tier and n-tier applications. The chapter is divided into smaller sections that can be used as cook-book style recipes.

Appendix A: JDO States

Appendix B: JDO Metadata XML DTD

Appendix C: JDOQL BNF

Appendix D: PersistenceManagerFactory Quick Reference

Appendix E: JDO Vendors

What This Book Is Not About

This book is not about:

  • Learning Java: This book is Java-focused and assumes that the reader is familiar with the Java programming language. This book is not a tutorial on Java or data structures in Java, nor is it a guide on how to implement different programming algorithms in Java.

  • Object databases: This book is about JDO, and though the specifications may be drawn from the wealth of experience and knowledge in the Object Data Management Group, this book is not about the Object Data Management Group (ODMG) specifications or about using object databases.

  • Development processes and methodology: Although UML notation is used where appropriate, this book does not suggest any particular programming technique or methodology to follow in Java projects.

Related Information

The J2EE technologies cited in this book are described in their specifications:

Additionally, the following resources may be helpful to the readers:

Conventions Used

This book has four distinct authors. In an attempt to remain consistent throughout the book, the authors have chosen to adopt the following conventions regarding terminology:

  • Persistence capable class: This term is used to indicate a class that implements the PersistenceCapable interface specified in the JDO API.

  • Persistent object: This term indicates an instance of a persistence capable class that is persistent.

  • Java object: This term indicates the general concept of a Java object instance. The object may or may not follow the standard JavaBeans conventions.

  • Transient instance: This term is indicates an instance of any class.

  • Field: The term is used to refer to the instance variables of a class. Rather than calling them members, member variables, or attributes, they are generically referred to as fields.

  • Datastore: This term is used to refer to the persistent mechanism used by a JDO implementation. The terms datastore and underlying datastore are used interchangeably. The term database is used only in the context of talking specifically about a relational database or object database.

  • JDO implementation: Rather than JDO runtime or JDO vendor, the term JDO implementation refers to an implementation of the JDO specification.

About the Authors

Sameer Tyagi

Sameer Tyagi is employed as an Enterprise Java Architect for Sun Microsystems and works at the Java Center in Burlington, MA. He has eight years of experience in information technology and has co-authored many books in different areas of Java technology. He also writes regularly for Java Pro, Java World, and Java Developers Journal. Sameer can be reached at [email protected].

Keiron McCammon

Keiron is the CTO for Versant Corporation. He has worked in the IT industry for more than ten years, principally applying object-oriented technologies and techniques for solving business problems. He has hands-on experience in C/C++/Java as well as Corba/J2EE. As the CTO of Versant, Keiron is responsible for defining the product strategy and direction. He has worked with strategic customers in the financial and telecommunications arenas, aiding in the development of distributed object solutions utilizing Java, J2EE, and Versant technologies. Keiron is a member of the JDO expert group (JSR 12) and presents regularly at Java and J2EE conferences and seminars on JDO and J2EE application architecture and development.

Michael Vorburger

Michael currently holds the title of Chief Software Architect at Vertical*I, an enterprise software company focusing on providing solutions to the life sciences industries. Following early drafts of the JDO standard, he was inspired to implement a similarly architected in-house persistence service, which is currently being re-implemented based on standard JDO. He has been giving feedback and exchanging questions on the JDO expert mailing list.

Heiko Bobzin

Heiko Bobzin is a member of the JDO expert group (JSR 12). He led the JDO and ODMG 3.0 implementation at Poet Software, a vendor of object-oriented databases. Prior to joining Poet, he developed a universal communications library including Java, Delphi, VB, and C++ bindings, a TCP stack, ISDN drivers, fax server, and ported the GNU C++ compiler to Microware's OS-9. He presented at Java One 2000, ICJD San Jose, New York in 2001, and many other conferences in the United States and Germany. You can reach him at [email protected].

About the Reviewers

The contents of the Core JDO book were made available to the general public for the purposes of review. All material was posted at http://www.theserverside.com to allow the community to participate in the review and editing of the content. Many comments and suggestions have made it into the final manuscript. In other words, this book has followed a sort of “open source approach” for an open technology.

The authors would like to thank all the people who helped in the reviewing process and provided their valuable feedback, in particular Ken Egervari, Chin Nelson, Christian Romberg, David Jencks, Jakimovski Robert, Justin Walsh, John Broglio, James McGovern, Neelan Choksi, and Jean-Louis Marechaux.

The authors would also like to thank all the people at theserverside.com, in particular Nitin Bharti and Floyd Marinescu for hosting the chapters and facilitating the review process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset