Professional Documents
Culture Documents
CALL INTERFACE(OCCI)
Shankar Iyer,
Oracle India.
Session II Session IV
- Object Features - Interoperability with OCI
- MetaData access - OCCI Performance Tuning
- Demo application
-Q&A
OCCI library
Application
•libocci.so/libocci.a/oraocci9.dll
//create Environment
Environment *env = Environment::createEnvironment();
//use the Environment instance to create connections,
//database access
…
//terminate Environment by calling static method
//Environment::terminateEnvironment
Environment::terminateEnvironment(env);
Create Create
Create
Get Create
MetaData Statement
Get
Execute
ResultSet
Connection *conn=env->createConnection(“scott”,”tiger”,””);
//3rd parameter is db name/TNS alias
//ResultSet::setDataBuffer(colIndex,buffer,type,elemsize,
//lengths,ind,rc)
//OCCI_SQLT_STR for char buffer
rs->setDataBuffer(1, enames, OCCI_SQLT_STR, 20, elens, NULL,
NULL);
empnos[0] = 801;
empnos[1] = 802;
conn->commit();
conn->commit();
Terminology :-
- Object : a row/item in a object table
- Reference : logical pointer/address of a object.
Every object in a object table has a reference
Associative access :-
- use SQL
- create/fetch object values with Statement::setObject/Statement::getObject
and ResultSet::getObject
- no caching of objects since they are ‘values’
BFILE Bfile
BLOB Blob
CLOB Clob
DATE Date
REF Ref<attribute_type>
#Running OTT
$ ott attraccess=private code=cpp cppfile=empo.cpp hfile=emph.h
intype=emp.typ mapfile=empm.cpp userid=scott/tiger
#generates emph.h, empo.cpp, empm.h, empm.cpp
2.//Database type :-
create type employee as object
(
Addr Address, -- embedded object
);
//C++ class generated by OTT :-
class EmployeeT : public oracle::occi::PObject {
private:
AddressT *ADDR;
4.//Database type :-
create type contractemployee under employee -- inheritance
(
);
//C++ class generated by OTT :-
class ContractEmployeeT : public EmployeeT { //C++ inheritance
newemp->setEmpno(1000);
newemp->setEmpname(“JOHN W”);
stmt->setObject(1, dept);
stmt->executeUpdate();
Insert into a table with object type column
Statement *stmt = conn->createStatement(“ insert into
Region(Area, Dept) values (:1, :2) ”);
stmt->setString(1, “North”);
stmt->setObject(2, dept);
stmt->executeUpdate();
rs->next();//fetch
stmt->executeUpdate();
while (rs->next())
{
cout << “customer name : “ << rs->getString(1);
vector<string> phonenos;
getVector(rs, 2, phonenos);
for (int i = 0; i < phonenos.size(); i++)
cout << phonenos[i] << “,”;
}
Queue user Data + options Read Message Send Message Wait for
messages
//instantiate a Producer
Producer prod(conn);
prod.send(msg, “QUEUE1”);//enqueue the message
//now dequeue
Consumer cons(conn);
Message msg2 = cons.receive(“QUEUE1”, “RAW”, “SYS”);
//dequeue
Message msg2;
msg2 = cons.receive(“ANYQUEUE”,”ANYDATA”,”SYS”);//dequeue
//get value
AnyData msgany = msg2.getAnyData();
string stringmsg = msgany.getAsString();//use other getAsXXX
//now dequeue
Message recv = cons.receive(“ORDERSQUEUE”, “ORDERTYPE”, “SCOTT”);
//get the object from the message
OrderT *processorder = (OrderT *)recv.getObject();
//bind wstring
wstring name = //from input terminal
stmt->setUString(1, name);
Uses OCCI
//destroy pool
env->terminateConnectionPool(spool);
//create a statement
Statement *stmt = conn->createStatement(sqlquery);
//release the statement to cache with tag
conn->terminateStatement(stmt, “tagA”);
Scalability
- Use Stateless Connection pooling to get authenticated connections
- Use Connection pooling to use less number of physical connections
Ref<PurchaseOrder> poref;
//set COR prefetching to get Customer object also
poref.setPrefetch(“Customer”, 1);