August 1, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Introduction to Java Data Objects (JDO)

  • February 5, 2003
  • By Lisa Oliver and Jeff Heaton
  • Send Email »
  • More Articles »

Java Data Objects (JDO) is a specification developed to enable transparent persistence of Java objects. It is a high-level API that allows applications to store Java objects in a transactional data store by following defined standards. Examples of traditional data stores are databases and files. This API can be used to access data on platforms such as desktops, servers, and embedded systems. JDO implementations can also be made to support cell phone, PDA, and other wireless technologies. In addition, JDO provides a means for treating data stored in a relational database as Java objects. JDO provides a standard means to define transactional semantics associated with these objects.

JDO was created under the direction of the Java Community Process and is documented as Java Specification Request 12 (JSAR 12). A group of experts from various companies were led by Craig Russell of Sun Microsystems and developed this specification. This began in 1999 and the final version (version 1.0) was released on April 30, 2002. Like many other Java technologies, Sun Microsystems has released a specification and a reference implementation. In addition, vendors are creating products to be compatible with JDO. Table 1 lists some of these vendors.

Table 1: JDO Vendors
Company Product Web Site Address
SolarMetric Kodo JDO Enterprise Edition, Kodo JDO Standard Edition www.solarmetric.com
Poet Software Corporation FastObjects www.fastobjects.com
LiBeLIS LiDO www.libelis.com
Hemisphere Technologies JDO Genie www.hemtech.co.za/jdo
ObjectFrontier Inc. FrontierSuite for JDO www.objectfrontier.com
Versant Versant enJin www.versant.com
Sun Microsystems, Inc. Reference Implementation www.java.sun.com
Object Industries GmbH JRelay www.objectindustries.com

JDO is also designed to easily be plugged into application servers. This allows JDO to accomplish many of the same functions provided by CMP entity EJBs. That is the ability to separate the JDBC and SQL code necessary to access the data stores from the objects that the program works with.

In this article, we will provide you with an overview of JDO and what it is used for. We will compare it to existing technologies and explain its role. We will discuss some of the reasons why JDO has been slow to be adopted into widespread mainstream use. We will also explain some of the exciting features that JDO offers which may allow it to enter widespread use.

Most new technologies are introduced to solve a specific problem. We will begin by explaining the problem that JDO seeks to solve.

The Problem

In object-oriented programming, when utilizing Java, data is transient, meaning that it usually only resides in memory and will be destroyed when the application ends. In developing many applications, this is a problem because a requirement or goal is for the data to remain persistent—meaning continuing to exist outside of the (single) application instance. Traditional data stores such as databases, files systems, and so forth are generally used for persisting data. In relational databases, data is stored in tables containing columns. Relationships are created between these tables. In Java, an object-oriented language, data is manipulated as objects. Clearly defined relationships between Java objects and database structures do not exist. As a result, programmers must create relationships between objects being utilized in their applications and the data stores the data actually resides in. Examples of existing options for persisting data include JDBC, SQLJ, EJBs, and java.util.Serializable.

Introduction to JDO

JDO allows developers to persist Java objects into traditional data stores. It supports transactions, queries, and the management of an object cache. JDO provides for transparent persistence for Java objects with an API that is independent of the underlying data store. JDO allows you to very easily store regular Java classes. JDOQL is used to query the database, which uses a Java-like syntax that can quickly be adopted by those familiar with Java. Together these features improve developer productivity. An added benefit is code portability across data stores and JDO implementations. To see an example of how JDO allows you to process data in terms of objects, consider the following example.

We will create a very simple student database. This database will contain the name, address, and department for each student. The actual class that you will use with JDO is simply a regular Java class that contains all of the attributes that you would like to store or the student. This class would look something like this:

public class Student {
  private String name;
  private String address;
  private String studentID;
  private String department;

  public Student(String name, String address, String studentID,
                String department) {
    this.name = name;
    this.address = address;
    this.studentID = studentID;
    this.department = department;
  }

  public String getName()
  {
    return name;
  }

  public String getAddress()
  {
    return address;
  }

  public String getStudentID()
  {
    return studentID;
  }

  public String getDepartment()
  {
    return department;
  }

  public void setName(String name)
  {
    this.name = name;
  }

  public void setAddress(String address)
  {
    this.address = address;
  }

  public void setStudentID(String studentID)
  {
    this.studentID = studentID;
  }

  public void setDepartment(String department)
  {
    this.department = department;
  }

}

This object could be queried by using a JDOQL filter. Such a filter might look something like this:

String filter = "name.startsWith(n)";

This query would look for every name that starts with the parameter n. The parameter n would be provided to the query before it ran. The syntax of JDOQL matches Java's syntax fairly closely. You are able to use the Java string functions as part of your query.

JDO is a technology that may replace other existing technologies that accomplish similar tasks. The two most obvious technologies are entity EJBs and JDBC. We will now compare JDO to these technologies.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel