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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Representing Objects in <strong>C++</strong> Applications<br />

Creating a Transient Object<br />

An instance of the transient object ADDRESS is created in the following manner:<br />

ADDRESS *addr_trans = new ADDRESS("MD", "94111");<br />

Creating Object Representations using the OTT Utility<br />

When your <strong>C++</strong> application retrieves instances of object types from the database, it<br />

needs to have a client-side representation of the objects. The Object Type Translator<br />

(OTT) utility generates <strong>C++</strong> class representations of database object types for you.<br />

For example, consider the following declaration of a type in your database:<br />

CREATE TYPE address AS OBJECT (state CHAR(2), zip_code CHAR(5));<br />

The OTT utility produces the following <strong>C++</strong> class:<br />

class ADDRESS : public PObject {<br />

protected:<br />

string state;<br />

string zip;<br />

public:<br />

void *operator new(size_t size);<br />

void *operator new(size_t size, const Session* sess, const string&<br />

table);<br />

string getSQLTypeName(size_t size);<br />

ADDRESS(void *ctx) : PObject(ctx) { };<br />

static void *readSQL(void *ctx);<br />

virtual void readSQL(AnyData& stream);<br />

static void writeSQL(void *obj, void *ctx);<br />

virtual void writeSQL(AnyData& stream);<br />

}<br />

These class declarations are automatically written by OTT to a header (.h) file that<br />

you name. This header file is included in the source files for an application to<br />

provide access to objects. Instances of a PObject (as well as instances of classes<br />

derived from PObjects) can be either transient or persistent. The methods<br />

writeSQL and readSQL are used internally by the OCCI object cache to linearize<br />

and delinearize the objects and are not to be used or modified by OCCI clients.<br />

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

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

Saved successfully!

Ooh no, something went wrong!