Organization of This Book Conventions Used in This Book Comments and Questions About the Philosophers Acknowledgments Part I: Data Architecture Chapter 1... This unique book covers E
Trang 2Organization of This Book
Conventions Used in This Book Comments and Questions
About the Philosophers
Acknowledgments
Part I: Data Architecture
Chapter 1 Elements of
Trang 3Management
Trang 4Part II: Persistence Models
Trang 55.3 The EJB 2.0 CMP Model 5.4 Beyond CMP
Trang 6Frameworks?
8.2 Persistence Approach
8.3 Persistence Operations 8.4 Searches
8.5 Beyond the Basics
Part III: Tutorials
Chapter 9 J2EE Basics
Trang 812.6 Inheritance Colophon
Index
Index SYMBOL Index A
Trang 9Index K Index L Index M Index N Index O Index P Index Q Index R Index S Index T Index U Index V Index W Index X
Trang 11Publisher : O'ReillyPub Date : May 2003ISBN : 0-596-00522-9Pages : 286
Unlike other books on this topic, which focus on a single
way to do things, Java
Database Best Practices takes
you through a wide variety of different ways to store and
Trang 12access data, enabling you to learn which "persistence model"
is most appropriate for each type of application This unique book covers Enterprise
JavaBeans, Java Data Objects, the Java Database Connectivity API (JDBC) and other, lesser- known options.
Trang 14Publisher : O'Reilly
Pub Date : May 2003ISBN : 0-596-00522-9Pages : 286
Copyright
Dedication
Preface
Audience
Organization of This Book
Conventions Used in This Book
Comments and Questions
About the Philosophers
Acknowledgments
Part I: Data Architecture
Trang 15Chapter 1 Elements of Database Applications Section 1.1 Database Application Architectures Section 1.2 Component Models
Section 1.3 Persistence Models
Chapter 2 Relational Data Architecture
Section 2.1 Relational Concepts
Section 2.2 Modeling
Section 2.3 Normalization
Section 2.4 Denormalization
Section 2.5 Object-Relational Mapping
Chapter 3 Transaction Management
Section 3.1 Transactions
Section 3.2 Concurrency
Section 3.3 JDBC Transaction Management Section 3.4 Transaction Management Paradigms Part II: Persistence Models
Chapter 4 Persistence Fundamentals
Section 4.1 Patterns of Persistence
Section 4.2 A Guest Book Application
Trang 16Chapter 5 EJB CMP
Section 5.1 Which CMP Model to Use? Section 5.2 The EJB 1.0 CMP Model Section 5.3 The EJB 2.0 CMP Model Section 5.4 Beyond CMP
Chapter 6 EJB BMP
Section 6.1 EJBs Revisited
Section 6.2 BMP Patterns
Section 6.3 State Management
Section 6.4 Exception Handling
Chapter 7 JDO Persistence
Section 7.1 JDO or EJB?
Section 7.2 Basic JDO Persistence
Section 7.3 EJB BMP with JDO
Chapter 8 Alternative Persistence Frameworks Section 8.1 Why Alternative Frameworks? Section 8.2 Persistence Approach
Section 8.3 Persistence Operations
Section 8.4 Searches
Trang 17Section 8.5 Beyond the Basics
Part III: Tutorials
Chapter 9 J2EE Basics
Section 9.1 The Platform
Section 9.2 Java Naming and Directory Interface Section 9.3 JavaServer Pages
Section 9.4 Remote Method Invocation
Section 9.5 Enterprise JavaBeans
Chapter 10 SQL
Section 10.1 Background
Section 10.2 Database Creation
Section 10.3 Table Management
Section 10.4 Data Management
Trang 18Section 12.2 Enhancement Section 12.3 Queries Section 12.4 Changes Section 12.5 Transactions Section 12.6 Inheritance Colophon
Index
Trang 19Copyright © 2003 O'Reilly & Associates,Inc
Printed in the United States of America
Published by O'Reilly & Associates, Inc.,
1005 Gravenstein Highway North,
Sebastopol, CA 95472
O'Reilly & Associates books may bepurchased for educational, business, orsales promotional use Online editions arealso available for most titles
(http://safari.oreilly.com) For more
information, contact our
corporate/institutional sales department:
Trang 20(800) 998-9938 or
corporate@oreilly.com
Nutshell Handbook, the Nutshell
Handbook logo, and the O'Reilly logo areregistered trademarks of O'Reilly &Associates, Inc Java and all Java-basedtrademarks and logos are trademarks orregistered trademarks of Sun
Microsystems, Inc., in the United Statesand other countries O'Reilly &
Associates, Inc is independent of SunMicrosystems The licenses for all theopen source tools presented in this bookare included with the online examples.Many of the designations used by
manufacturers and sellers to distinguishtheir products are claimed as trademarks
Trang 21Where those designations appear in thisbook, and O'Reilly & Associates, Inc wasaware of a trademark claim, the
designations have been printed in caps orinitial caps The association between theimage of a taguan and the topic of Javadatabase best practices is a trademark ofO'Reilly & Associates, Inc
While every precaution has been taken inthe preparation of this book, the publisherand authors assume no responsibility forerrors or omissions, or for damages
resulting from the use of the informationcontained herein
Trang 22To my beautiful wife, Monique, and the child she carries.
Trang 23It is never too late to become
reasonable and wise; but if the
insight comes late, there is always more difficulty in starting the
change.
Immanuel Kant, Prolegomena to
Any Future Metaphysics
Java database programming has grownmuch more complex than it was in 1996when I wrote the first edition of my book
Database Programming with JDBC and Java (O'Reilly & Associates) The J2EE
platform did not exist Distributed
Trang 24programming was RMI, JDBC was
simple, and transaction management andpersistence did not exist in the Java
vocabulary Database programming in
1996 was quite simply JDBC
programming
To place database programming in a world context, I spent much of that bookintroducing ways to build robust
real-persistence models and manage
transactions using only the JDBC API Asyou can imagine, you had to do a lot ofthings for yourself that developers nowtake for granted in the Java platform.The Java world has certainly changedsince then Not only does Java provide
Trang 25you with a persistence model, it providesyou with three different persistence
models built right into the core J2EEplatform Outside the J2EE platform is thepopular JDO persistence model In
addition, many tools exist to enable you toeffectively use third-party and custompersistence models All of these choicespresent a problem for database
programmers that simply did not exist in1996: what are the best approaches todatabase programming with the Javalanguage?
This book seeks to aid the Java developer
in appreciating the different approachesJava provides for database programming
It helps you assess what approaches fit
Trang 26which problems, and what the bestpractices are under each model.
Trang 27This book is not an introductory text It isalso not a tutorial on any particular API It
is, instead, a description of the best
practices for using a database to drive avariety of Java application architectures
It assumes you have at least a passingfamiliarity with one or more of the Javaenterprise APIs, as well as SQL You donot, however, need to be an expert in all
of them To help you with any holes inyour knowledge of these tools, I provide afew tutorial chapters at the end of thebook
Trang 28Organization of This Book
This book is divided into three distinctsections The first two sections are themeat of this book: best practices for Javadatabase architecture and development.The first section focuses on the
architecture aspect and the second section
on the development aspect
Part I
Chapter 1 is an overview of the art ofdatabase programming It examines thevarious tools and skills needed for
database programming and covers
common database application
Trang 29architectures The chapter is mostly
review material for experienced databaseprogrammers
Chapter 2 tackles one of the more difficultaspects of database programming,
especially for the object-oriented
programmer: data architecture This
chapter begins with relational theory andcovers critical topics such as
normalization and object-relational
modeling It is a very important chapterfor database programmers of all levels ofexperience
Though relational architecture is one ofthe more difficult aspects of database
programming, transaction management is
Trang 30where database programmers make most
of their mistakes Chapter 3 covers
transactions and transaction management
Part II
The second section begins with an
overview of persistence concepts In
short, persistence is the practice of saving
application state to a data store Chapter 4
introduces this practice with an eye onusing relational databases as your datastore for Java applications
Chapter 5 through Chapter 8 go into thebest practices for different Java
persistence models Chapter 5 begins with
Trang 31container-managed persistence under theEnterprise JavaBeans component
modelfor Versions 1 and 2 Chapter 6
tackles the other EJB persistence model,bean-managed persistence Chapter 7
dives into an evolving, popular
persistence model, Java Data Objects.Finally, Chapter 8 looks at alternatives tothe standard Java persistence models
Trang 32with the subject in several, but not all, ofthe tutorial chapters The tutorial chaptersprovide the basic knowledge necessary tounderstand key concepts used in the firsttwo sections Don't look to any of thetutorial chapters to make you an expert inits subject matter I have provided
tutorials on the J2EE platform (Chapter
9), SQL (Chapter 10), JDBC (Chapter
11), and JDO (Chapter 12)
I recommend reading the first two sections
in order, breaking that order only to refer
to a tutorial chapter for a subject on whichyou lack familiarity
Trang 33Conventions Used in This Book
The following typographical conventionsare used in this book:
Italic
Used for filenames and directorynames, programs, compilers, tools,utilities, URLs, emphasis, and firstuse of a technical term
Constant width
Trang 34Used in code examples and to showthe contents of files Also used fortags, attributes, and environmentvariable names appearing in the text.
Constant width italic
Used as a placeholder to indicate anitem that should be replaced with anactual value in your program
Constant width bold
Used to highlight a particular section
or change in code, such as a custom
Trang 35tag or a change in a transaction.
Trang 36Comments and Questions
Please address comments and questions
concerning this book to the publisher:
O'Reilly & Associates, Inc
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States
or Canada)
(707) 829-0515 (international/local)(707) 829-0104 (fax)
There is a web page for this book, which
lists errata, examples, or any additional
information You can access this page at:
http://www.oreilly.com/catalog/javadtabp
Trang 37To comment or ask technical questionsabout this book, send email to:
bookquestions@oreilly.com
For more information about books,conferences, Resource Centers, and theO'Reilly Network, see the O'Reilly website at:
http://www.oreilly.com
Trang 38About the Philosophers
Daniel Dennett (Chapter 1)
Dennett, who teaches at Tufts
University, is probably my favoritephilosopher His books are actuallywell written, which is a rare qualityamong philosophy texts His worksrun the spectrum of philosophy, buthis greatest influence lies in thephilosophies of mind and science Ifyou want a fun philosophy book toread that does not require you to be a
philosopher, pick up his book Elbow
Room If you are looking for
Trang 39something more weighty, but equally
accessible, read Darwin's
Dangerous Idea.
René Descartes (Chapter 2)
Though he lived from 1596 until
1650, Descartes's writings mark thebeginning of modern philosophy Hewas a French philosopher who
emphasized a solipsistic approach toepistemology He is the author of thefamous quote "Cogito, ergo sum," or
"I think, therefore I am."
Trang 40Donald Davidson (Chapter 3)
Donald Davidson is among the mostimportant philosophers of the late20th century He is particularlyinfluential in the philosophy of
language and action theory He iscurrently a professor at the
University of California, Berkeley
My senior thesis at Bates Collegewas based on his writings
Ludwig Wittgenstein (Chapter 4)
Ludwig Wittgenstein was a Germanphilosopher who lived from 1889until 1951 His primary contributions
Trang 41to philosophy were in the philosophy
of language He once wrote that
"philosophy is a battle against thebewitchment of our intelligence bymeans of language."
Friedrich Nietzsche (Chapter 5)
Nietzsche, who lived in Germanyfrom 1844 until 1900, is likely themost controversial "serious"
philosopher His writings have
influenced nearly every kind of
philosophy but have had their
greatest impactboth positive andnegativein the area of ethics
Trang 42Martin Heidegger (Chapter 6)
Heidegger, another 20th-centuryGerman philosopher, made popularthe movement started by EdmundHusserl known as phenomenology.Phenomenology attempts to
understand things as they presentthemselves rather than to appeal tosome sort of essential nature hiddenfrom us This movement eventuallyled to the most popularly knownphilosophical movement,
existentialism
Trang 43David Kolb (Chapter 7)
David Kolb was my major adviser atBates College in Lewiston, Maine,where he is a Charles A Dana
Professor of Philosophy He haswritten extensively on Hegelianphilosophy and nonlinear writing inphilosophy
Immanuel Kant (Preface, Chapter 8)
Immanuel Kant may be the mostinfluential philosopher of the secondmillennium He was a German
philosopher who lived from 1724until 1804 He emphasized a rational
Trang 44approach to all philosophical
pursuits This rationalism has had itsgreatest impact in the area of ethics,where moral principles are,
according to Kant, derived entirelyfrom reason
David Hume (Chapter 9)
David Hume was an 18th-centuryScottish philosopher who wrote on arange of philosophical subjects He
is largely responsible for the school
of philosophy known as empiricism
Trang 45Ruth Garrett Millikan (Chapter 10)
Ruth Garrett Millikan is a professor
of philosophy at the University ofConnecticut She is an influentialmodern philosopher in the
philosophy of language and
epistemology
Noam Chomsky (Chapter 11)
Born in 1928, Noam Chomsky isperhaps the most famous livingphilosopher While often known forhis political activismespeciallyduring the Vietnam erahis greatestcontributions to philosophy lie in the
Trang 46philosophy of language.
Jean-Paul Sartre (Chapter 12)
Sartre was a novelist, a philosopher,and a member of the French
Resistance during World War II As
a philosopher, he is best known asthe force behind the existentialismmovement Existentialism goes
beyond phenomenology in its claimsabout the essential nature of things.While phenomenology claims that weshould not appeal to an essentialnature of a thing in order to
understand it, existentialism says that
no such essential nature exists A
Trang 47thing is exactly as it presents itself.
Trang 48So much work other than that of the authorgoes into putting together a solid book.First of all, Brett McLaughlin's editingskills and general Java knowledge havebeen critical to keeping me in line Alsocritical to the book was the contribution of
Chapter 8 on alternative persistence
frameworks by Justen Stepka I am notmuch of a fan of leaving the core platform,
so this book would have been incompletewithout his contribution
Several people contributed to reviewingthis book: Nick Kokotovich, Justen
Stepka, and Henri Yandell In addition,Monique Girgis, Andy Oram, and John