Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: Good introduction to JDO

Good introduction to JDO

Tutorial Details:

Persist data with Java Data Objects, Part 1
Persist data with Java Data Objects, Part 1
By: By Jacek Kruszelnicki
Grasp the qualities behind an ideal persistence layer
"Everything should be made as simple as possible, but not simpler."
Albert Einstein
he need to persist data created at runtime is as old as computing. And the need to store object-oriented data cropped up when object-oriented programming became pervasive. Currently, most modern, nontrivial applications use an object-oriented paradigm to model application domains. In contrast, the database market is more divided. Most database systems use the relational model, but object-based data stores prove indispensable in many applications. Plus, we also have legacy systems that we often need to interface to.
This article identifies the issues associated with data persistence in transactional middleware environments, such as J2EE (Java 2 Platform, Enterprise Edition), and shows how Java Data Objects (JDO) solves some of those issues. This article provides an overview, not a detailed tutorial, and is written from the viewpoint of an application developer, not a JDO implementation designer.
Read the whole series on Java Data Objects:
Part 1. Grasp the qualities behind an ideal persistence layer
Part 2. Sun JDO vs. Castor JDO
Those Java developers, designers, and J2EE architects who work on systems that must store data in relational or object databases, or other storage media should read this article. I assume you have a basic knowledge of Java and some familiarity with object-relational issues and terminology.
Transparent persistence: Why bother?
More than a decade of continuous attempts to bridge object-oriented runtime and persistence point to several important observations (listed in order of importance):
Abstracting away any persistence details and having a clean, simple, object-oriented API to perform data storage is paramount. We don't want to handle persistence details and internal data representation in data stores, be they relational, object-based, or something else. Why should we deal with low-level constructs of the data-store model, such as rows and columns, and constantly translate them back and forth? Instead, we need to concentrate on that complex application we were required to deliver by yesterday.
We want to use the plug-and-play approach with our data stores: We want to use different providers/implementations without changing a line of the application source code -- and perhaps without modifying more than a few lines in the appropriate configuration file(s). In other words, we need an industry standard for accessing data based on Java objects, one that plays a role similar to the one JDBC (Java Database Connectivity) plays as an industry standard for accessing SQL-based data.
We want to use the plug-and-play approach with different database paradigms -- that is, we want to switch from a relational database to an object-oriented one with minimal changes to the application code. Though nice to have, in practice, this capability is often not required.
One comment here: While relational databases enjoy the biggest market presence by far, providing a unified persistence API and allowing data-store providers to compete on implementation strengths makes sense, regardless of the paradigm these providers use. This approach might eventually help level the playing field between the two dominant database vendor groups: the well-entrenched relational camp and the struggling-for-market-share object-oriented camp.
The three discoveries listed above lead us to define a persistence layer, a framework that provides a high-level Java API for objects and relationships to outlive the runtime environment's (JVM) lifespan. Such a framework must feature the following qualities:
Simplicity
Minimal intrusion
Transparency, meaning the framework hides the data-store implementation
Consistent, concise APIs for object storage/retrieval/update
Transaction support, meaning the framework defines transactional semantics associated with persistent objects
Support for both managed (e.g., application server-based) as well as unmanaged (standalone) environments
Support for the necessary extras, such as caching, queries, primary key generation, and mapping tools
Reasonable licensing fees -- not a technical requirement, but we all know that poor economics can doom an excellent project
I detail most of the above qualities in the following sections.
Simplicity
Simplicity rates high on my list of required traits for any software framework or library (see this article's opening quote). Developing distributed applications is already hard enough, and many software projects fail because of poor complexity (and, by extension, risk) management. Simple is not synonymous with simplistic; the software should have all the needed features that allow a developer to do his/her job.
Minimal intrusion
Every persistent storage system introduces a certain amount of intrusion into the application code. The ideal persistence layer should minimize intrusion to achieve better modularity and, thus, plug-and-play functionality.
For the purpose of this article, I define intrusion as:
The amount of persistence-specific code splattered across the application code
The need to modify your application object model by either having to implement some persistence interface -- such as Persistable or the like -- or by postprocessing the generated code
Intrusion also applies to object-oriented database systems and, although usually less of an issue there compared to relational data stores, it can vary significantly among ODBMS (object-oriented database management system) vendors.
Transparency
The persistent layer transparency concept is pretty simple: the application uses the same API regardless of the data-store type (data storage-type transparency), or the data-store vendor (data storage-vendor transparency). Transparency greatly simplifies applications and improves their maintainability by hiding data-store implementation details to the maximum extent possible. In particular, for the prevalent relational data stores, unlike JDBC, you don't need to hardcode SQL statements or column names, or remember the column order returned by a query. In fact, you don't need to know SQL or relational algebra, because they're too implementation specific. Transparency is perhaps the persistence layer's most important trait.
Consistent, simple API
The persistence layer API boils down to a relatively small set of operations:
Elementary CRUD (create, read, update, delete) operations on first-class objects
Transaction management
Application- and persistence-object identities' management
Cache management (i.e., refreshing and evicting)
Query creation and execution
An example of a PersistenceLayer API:
public void persist(Object obj); // Save obj to the data store.
public Object load(Class c, Object pK); // Read obj with a given primary key.
public void update(Object obj); // Update the modified object obj.
public void delete(Object obj); // Delete obj from the database.
public Collection find(Query q); // Find objects that satisfy conditions of our query.
Transaction support
A good persistence layer needs several elementary functions to start, commit, or roll back a transaction. Here is an example:
// Transaction (tx) demarcation.
public void startTx();
public void commitTx();
public void rollbackTx();
// Choose to make a persistent object transient after all.
public void makeTransient(Object o)
Note: Transaction demarcation APIs are primarily used in nonmanaged environments. In managed environments, the built-in transaction manager often assumes this functionality.
Managed environments support
Managed environments, such as J2EE application servers, have grown popular with developers. Who wants to write middle tiers from scratch these days when we have excellent application servers available? A decent persistence layer should be able to work within any major application server's EJB (Enterprise JavaBean) container and synchronize with its services, such as JNDI (Java Naming and Directory Interface) and transaction management.
Queries
The API should be able to issue arbitrary queries for data searches. It should include a flexible and powerful, but easy-to-use, language -- the API should use Java objects, not SQL tables or other data-store representations as formal query parameters.
Cache management
Cache management can do wonders for application performance. A sound persistence layer should provide full data caching as well as appropriate APIs to set the desired behavior, such as locking levels, eviction policies, lazy loading, and distributed caching support.
Primary key generation
Providing automatic identity generation for data is one of the most common persistence services. Every decent persistence layer should provide identity generation, with support for all major primary key-generation algorithms. Primary key generation is a well-researched issue and numerous primary key algorithms exist.
Mapping, for relational databases only
With relational databases, a data mapping issue arises: the need to translate objects into tables, and to translate relationships, such as dependencies and references, into additional columns or tables. This is a nontrivial problem in itself, especially with complex object models. The topic of object-relational model impedance mismatch reaches beyond this article's scope, but is well publicized. See Resources for more information.
The following list of extras related to mapping and/or relational data stores are not required in the persistence layer, but they make a developer's life much easier:
A GUI (graphical user interface) mapping tool
Code generators: Autogeneration of DDL (data description language) to create database tables, or autogeneration of Java code and mapping files from DDL
Primary key generators: Supporting multiple k


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Good introduction to JDO

View Tutorial:
Good introduction to JDO

Related Tutorials:

Displaying 1 - 50 of about 825 Related Tutorials.

JDO - Java Data Objects Tutorials
. This JDO tutorial gives you through introduction to JDO, starting from... JDO - Java Data Objects Tutorials, JDO Java Data Object, JDO Tutorial JDO - Java Data Objects Tutorials
 
JDO UNPLUGGED - PART 1
.". With this brief introduction, we will see how to actually use JDO... JDO - Java Data Objects Tutorials, JDO Java Data Object, JDO Tutorial, JDO UNPLUGGED - PART I JDO UNPLUGGED - PART I
 
JDO Implementations
JDO Implementations JDO Implementations...;    To build application using Java JDO technology, we need the JDO implementation. Here we have listed all commercial and non-commercial
 
JSF Introduction - An Introduction to JSF Technology
JSF Introduction,JSF Introduction,JSF Introduction Tutorial,Java Server Faces Introduction,Introduction to Java Server Faces JSF Introduction - An Introduction to JSF Technology
 
JDO UNPLUGGED - PART II
JDO - Java Data Objects Tutorials, JDO Java Data Object, JDO Tutorial, JDO UNPLUGGED - PART II JDO UNPLUGGED - PART II...;       The JDO examples can be tested
 
Introduction to Components
Java: Introduction to Components Java NotesIntroduction to Components Swing Components You can... Swing classes provide the tools that help you build a good graphical user
 
Loops - Introduction
Java: Loops - Introduction Java NotesLoops - Introduction The purpose of loop... {}. However, many programmers think it is a good idea to always use braces
 
Introduction to XSLT
Introduction to XSLT Introduction to XSLT              ... good one (Open sources), such as MSXML4, Saxon, and Xalan, XT, Oracle. Most
 
Web Hosting Guide. Introduction to Domain Name
Web Hosting Guide. Introduction to Domain Name Introduction to Domain Name   ..., there is a good chance your technical contact will have to become involved
 
AN INTRODUCTION TO JSTL
AN INTRODUCTION TO JSTL AN   INTRODUCTION ... of this tutorial on JSTL, the author gives a brief introduction to JSTL and shows why and how.... ( Carefully note the version , however!).    It is good to start
 
Free Web Hosting - Why Its not good Idea
Free Web Hosting - Why Its not good Idea Free Web Hosting - Why Its not good Idea    ...; This article shows you why Free Web Hosting is not good Idea
 
Ruby on Rails-Introduction
Ruby on Rails-Introduction Ruby on Rails-Introduction         ... on object oriented programming. The good thing about this programming language
 
Burning Bridges is Bad, But Firewalls are Good
Burning Bridges is Bad, But Firewalls are Good Burning Bridges is Bad, But Firewalls are Good            
 
iBatis-Showing all data from database
framework like Hibernate, JDO and EJB that maps objects to SQL statements. It is a lightweight framework and persistence API good for persisting POJOs( Plain Old Java Objects). iBatis is different from Hibernate, JDO since it uses stored
 
Introduction
Introduction Introduction                           What
 
Introduction to the JDBC
Introduction to the JDBC Introduction to the JDBC ...;  Introduction
 
Java Data Objects
JDO,What is JDO JDO - Java Data Objects...;    This section gives you brief description of JDO, features and benefits of JDO specification. The Java Data Objects or JDO for short
 
EJB Books
Filled with practical advice for good design and performance and plenty of useful... practices using Ant, JUnit testing strategies, using Java Data Objects (JDO... them more efficiently using JBuilder 7.0. Beginning with an introduction to beans
 
Introduction to JSP

 
Introduction to JSP Scriptlets
Introduction to JSP Scriptlets INTRODUCTION TO JSP SCRIPTLETS          ... are pageContext, application,config and exception. INTRODUCTION
 
Introduction to JSP Declaratives Declarations
Introduction to JSP Declaratives Declarations INTRODUCTION TO JSP DECLARATIVES                    
 
WebTycho Guidelines
Java Notes: Grading Criteria Java Notes: WebTycho Guidelines Good practices Code Corner Turn on Classroom Awareness Chats sessions Frequent exercises Have students post something
 
Objective C Introduction
Objective C Introduction Objective C Introduction          ...;    This section provides you the basic introduction about
 
Brief Introduction to the Web Application development
Brief Introduction to the Web Application development Brief Introduction to the Web Application development
 
Introduction to JSP tags JSP Directives
Introduction to JSP tags JSP Directives INTRODUCTION TO JSP TAGS                      
 
Associations and Joins
includes a brief introduction about Associations and Joins along with examples... the Nullable foreign keys since these keys do not require good practice
 
Introduction to the JSP Java Server Pages
with working source code. Introduction to JSP Java Server Pages... by the engine to serve the requests.     Introduction... introduction to JSP Declaratives JSP Declaratives begins with <
 
Events -- Introduction
Java: Events -- Introduction Java NotesEvents -- Introduction Events come from User Controls When you define a user interface, you will usually have
 
Introduction to MySQL
Introduction to MySQL Introduction to MySQL            ... introduction of MySQL database. Everything from installation to the administration
 
Methods - Introduction
Java: Methods - Introduction Java NotesMethods - Introduction Method = Function = Procedure = Subroutine = Subprogram The word method is commonly used in Object-Oriented
 
Introduction to Dojo
Introduction to Dojo, Dojo Introductionm, Dojo toolkit Introduction to Dojo                      
 
Tomcat an Introduction
Tomcat an Introduction Tomcat an Introduction                           
 
Introduction to JSP
Introduction to JSP Introduction to JSP                          
 
JFreeChart - An Introduction
JFreeChart Introduction JFreeChart - An Introduction                     
 
SQL-introduction
SQL Tutorial SQL-introduction                           SQL
 
Introduction to XSL
Introduction to XSL Introduction to XSL                          
 
Introduction to Java
Introduction to Java Introduction to Java                          
 
Introduction to RCFaces
Introduction to RCFaces Introduction to RCFaces                        
 
Introduction to the JSTL
JSTL, Java Server Pages Standard Tag Library, JSP JSTL Introduction to the JSTL                   
 
XML: An Introduction
XML XML: An Introduction                           What
 
Dojo Tutorial
you will be able to develop good applications using Dojo framework. This advanced Dojo tutorial covers: Introduction to DOJO
 
Introduction To Enterprise Java Bean(EJB). Developing web component.
Introduction To Enterprise Java Bean(EJB). Developing web component. Developing web component...     Introduction To Java Beans
 
Introduction To Enterprise Java Bean(EJB). WebLogic 6.0 Tutorial.
EJB Tutorial - Introduction To Enterprise Java Bean(EJB) with WebLogic server...     Introduction...: Introduction to Distributed Applications
 
Introduction to Apache Myfaces and Tomahawk
Introduction to Apache Myfaces and Tomahawk   Introduction to Apache Myfaces and Tomahawk                
 
INTRODUCTION TO JSP SCRIPTLETS
Introduction to JSP Scriptlets INTRODUCTION TO JSP SCRIPTLETS          ... are pageContext, application,config and exception. INTRODUCTION
 
Introduction to Graphs and Charts
Introduction to Graphs and Charts Introduction to Graphs and Charts                   
 
Random numbers - Introduction
Java: Random numbers - Introduction Java NotesRandom numbers - Introduction When to use random numbers There are many types of programs that use random numbers. Game programs use
 
INTRODUCTION TO JSP DECLARATIVES
Introduction to JSP Declaratives Declarations INTRODUCTION TO JSP DECLARATIVES                    
 
Introduction to Collections API
About Collections,Collection Java,Collection API,Introduction to Collections API Introduction to Collections API             
 
Introduction to Collections Framework
Introduction to Collections Framework, Advantages and Disadvantages of the Collection Framework Introduction to Collections Framework         
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.