JDO and Object-Relational Mapping
This example uses the Java Data Objects (JDO) Binding. Notice that all the code is Java. You will not find a database sub-language in this example. The part in blue relates to the animation of transparent persistence. Note that the same code would used for object databases. Transparent persistent interfaces work with both object database or object-relational mapping products.
import javax.jdo.*; import java.util.Collection;PersistenceManagerFactory pmf; // assume this variable is set pmf.setConnectionUserName(" "); pmf.setConnectionPassword(" "); pmf.setConnectionURL("database URL"); PersistenceManager pm = pmf.getPersistenceManager(); Transaction txn = pm.currentTransaction();txn.begin(); Collection people = pm.getExtent(Person.class, false);// perform query Query query = pm.newQuery(Person.class, people, "name == \"Doug Barry\""); Collection result = (Collection) query.execute(); Iterator iter = result.iterator();// iterate over the results while ( iter.hasNext() ) { Person person = (Person) iter.next();// do some addition processing on the person (not shown)// now traverse to the address object and update its value person.address.street = "13504 4th Avenue South"; }txn.commit();
Related Articles
More on the general topic: How to Access Data in a Relational Database