C++ and Object-Relational Mapping

This example uses the ODMG C++ Binding and the ODMG Object Query Language (OQL). Other C++ bindings and query languages for object-relational mapping products would be similar. Notice that all the code is C++, 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.

d_Database db;
d_Transaction txn;
try {
    db.open("addressDB");
    txn.begin();
    // perform query
     d_OQL_Query query(
         "select x from Person x where x.name = \"Doug Barry\"");
    d_Bag<d_Ref<Person> >   allDougBarrys;
    d_oql_execute(query, allDougBarrys);
    d_Iterator<d_Ref<Person> > iter = allDougBarrys.create_iterator();
    // iterate over the results
    d_Ref<Person> p;
    while( iter.next(p) ){
       // do some addition processing on the person (not shown)
       // now traverse to the address object and update its value
       p->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

Related Fact Book

You may use this material for your work or classes. Reprint Policy. Be sure to check the menu at the left for other articles available on this site.

The Savvy Manager's Guide

Douglas K Barry is also the author of a book that explains Web Services, service-oriented architecture, and Cloud Computing in an easy-to-understand, non-technical manner.

Web Services, Service-Oriented Architectures, and Cloud Computing: The Savvy Manager's Guide

Web Services, Service-Oriented Architectures, and Cloud Computing: The Savvy Manager's Guide (Second Edition)

by with David Dick

This is a guide for the savvy manager who wants to capitalize on the wave of change that is occurring with Web Services, service-oriented architecture, and—more recently—Cloud Computing. The changes wrought by these technologies will require both a basic grasp of the technologies and an effective way to deal with how these changes will affect the people who build and use the systems in our organizations. This book covers both issues. Managers at all levels of all organizations must be aware of both the changes that we are now seeing and ways to deal with issues created by those changes.