10.12.2012 Views

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

Overview of Navigational Access<br />

The following example shows how to modify the state attribute of the object, addr:<br />

addr_ref->setState("PA");<br />

As explained earlier, the first invocation of the operator -> on Ref loads the<br />

object if not already in the object cache.<br />

Marking Objects and Flushing Changes<br />

In the example in the previous section, an attribute of an object was changed. At<br />

this point, however, that change exists only in the client-side cache. The application<br />

must take specific steps to ensure that the change is written to the database.<br />

Marking an Object as Modified (Dirty)<br />

The first step is to indicate that the object has been modified. This is done by calling<br />

the markModified method on the object (derived method of PObject). This<br />

method marks the object as dirty (modified).<br />

Continuing the previous example, after object attributes are manipulated, the object<br />

referred to by addr_ref can be marked dirty as follows:<br />

addr_ref->markModified()<br />

Recording Changes in the Database<br />

Objects that have had their dirty flag set must be flushed to the database server for<br />

the changes to be recorded in the database. This can be done in three ways:<br />

■ Flush a single object marked dirty by calling the method flush, a derived<br />

method of PObject.<br />

■ Flush the entire object cache using the Connection::flushCache method. In<br />

this case, OCCI traverses the dirty list maintained by the object cache and<br />

flushes all the dirty objects.<br />

■ Commit a transaction by calling the Connection::commit method. Doing so<br />

also traverses the dirty list and flushes the objects to the database server. The<br />

dirty list includes newly created persistent objects.<br />

Object Programming 3-17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!