Java and Object-Relational Mapping
This example uses the ODMG Java Binding and the ODMG Object Query Language (OQL). Other query languages for object-relational mapping products would be similar. Notice that all the code is Java, with the exception of the query string. You will not find a database sub-language in this example. The part in blue relates to the animation of transparent persistence. More information on the ODMG specification. Note that the same code would used for object databases. Transparent persistent interfaces work with both object database or object-relational mapping products.
import org.odmg.*; import java.util.Collection;Implementation impl = new com.vendor.odmg.Implementation(); Database db = impl.newDatabase(); Transaction txn = impl.newTransaction();try { db.open("addressDB", Database.OPEN_READ_WRITE); txn.begin();// perform query OQLQuery query = new OQLQuery( "select x from Person x where x.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(); db.close(); }//exception handling would go here ...
Related Articles
More on the general topic: How to Access Data in a Relational Database