Chapter 3. JDO Architecture

3.1. JDO Exceptions

The diagram below illustrates the relationships between the primary components of the JDO architecture.

The example below illustrates how the JDO interfaces interact to execute a query and update persistent objects.

Example 3.1. Interaction of JDO Interfaces

// get a persistence manager factory using the jdo helper 
PersistenceManagerFactory factory = 
    JDOHelper.getPersistenceManagerFactory (System.getProperties ());

// get a persistence manager from the factory
PersistenceManager pm = factory.getPersistenceManager ();

// updates take place within transactions
Transaction tx = pm.currentTransaction ();
tx.begin ();

// query for all employees who work in our research division
// and put in over 40 hours a week average
Extent extent = pm.getExtent (Employee.class, false);
Query query = pm.newQuery ();
query.setCandidates (extent);
query.setFilter ("division.name == 'Research' && avgHours > 40");
Collection results = (Collection) query.execute ();

// give all those hard-working employees a raise
Employee emp;
for (Iterator itr = results.iterator (); itr.hasNext ();)
{
    emp = (Employee) itr.next ();
    emp.setSalary (emp.getSalary () * 1.1);
} 

// commit the updates and free resources
tx.commit ();
pm.close ();
factory.close ();

The remainder of this document explores the JDO interfaces in detail. We present them in roughly the order that you will use them as you develop your application.

3.1. JDO Exceptions

The diagram below depicts the JDO exception architecture. Runtime exceptions such as NullPointerExceptions and IllegalArgumentExceptions aside, JDO components throw nothing but JDOExceptions of one type or another.

The JDO exception hierarchy should be self-explanatory. Consult the JDO Javadoc for details.