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.

Overview of Navigational Access<br />

and enables you to access and modify the object’s attributes and follow references<br />

from that object to other objects. Your application also controls when modified<br />

objects are written back to the database server.<br />

OCCI requires only that you dereference the REF in the same way you would<br />

dereference any <strong>C++</strong> pointer. Dereferencing the REF transparently materializes the<br />

object as a <strong>C++</strong> class instance.<br />

Continuing the Address class example from the previous section, assume that the<br />

user has added the following method:<br />

string Address::getState()<br />

{<br />

return state;<br />

}<br />

To dereference this REF and access the object's attributes and methods:<br />

string state = addr_ref->getState(); // -> pins the object<br />

The first time Ref (addr_ref) is dereferenced, the object is pinned, which is<br />

to say that it is loaded into the object cache from the database server. From then on,<br />

the behavior of operator -> on Ref is just like that of any <strong>C++</strong> pointer (T<br />

*). The object remains in the object cache until the REF (addr_ref) goes out of<br />

scope. It then becomes eligible for garbage collection.<br />

Now that the object has been pinned, your application can modify that object.<br />

Manipulating Object Attributes<br />

Manipulating object attributes is no different from that of accessing them as shown<br />

in the previous section. Let us assume the Address class has the following user<br />

defined method that sets the state attribute to the input value:<br />

void Address::setState(string new_state)<br />

{<br />

state = new_state;<br />

3-16 <strong>Oracle</strong> <strong>C++</strong> <strong>Call</strong> <strong>Interface</strong> Programmer’s <strong>Guide</strong><br />

Note: This section deals with a simple pin operation involving a<br />

single object at a time. For information about retrieving multiple<br />

objects through complex object retrieval, see the section Overview<br />

of Complex Object Retrieval on page 3-19.

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

Saved successfully!

Ooh no, something went wrong!