Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: OCCI Connection Pool on Oracle RAC

Re: OCCI Connection Pool on Oracle RAC

From: <jose_luis_fdez_diaz_news_at_yahoo.es>
Date: 5 Oct 2005 07:28:01 -0700
Message-ID: <1128522481.456880.257610@f14g2000cwb.googlegroups.com>

I have found help in "http://forums.oracle.com". Here is the example that I have got there:

 #include <occi.h>

using namespace std;
using namespace oracle::occi;

typedef struct
{

Connection *occiconn;
char data[50];
} CtxStruct;

sb4 my_tafcb(dvoid *svchp, dvoid *envhp, dvoid *fo_ctx, ub4 fo_type, ub4 fo_event)
{

cout << "fo_type = " << fo_type << "," << "fo_event = " << fo_event << endl;

switch (fo_event)
{

case OCI_FO_BEGIN :
{

cout << "Server down ... failover starting, type = " << fo_type << endl;
CtxStruct *ctx = (CtxStruct *)fo_ctx;
cout << "Context data = " << ctx->data << endl; break;
}

case OCI_FO_ERROR :
{

cout << "Retrying again..." << endl;
//sleep(5);
return OCI_FO_RETRY;
}

case OCI_FO_ABORT :
{

cout << "Failover not possible!Aborted" << endl; break;
}

case OCI_FO_END :
{

cout << "Failover completed successfully" << endl; cout << "Reexecuting Alter session commands" << endl;

//get the OCCI connection object from the ctx CtxStruct *ctx = (CtxStruct *)fo_ctx;
Connection *conn = ctx->occiconn;

Statement *stmt2 = conn->createStatement("alter session set nls_date_format='dd-month'");
stmt2->execute();
conn->terminateStatement(stmt2);
break;
}
//OCI_FO_REAUTH need not be handled since OCCI does not support //multiple sessions on a single server handle }
return 0;

}

main()
{

try
{

Environment *env = Environment::createEnvironment(); Connection *conn = env->createConnection("scott","tiger", "testtaf");

Statement *stmt = conn->createStatement("alter session set nls_date_format='dd-month'");
stmt->execute();

//set the TAF handler
//need Error handle for OCIAttrSet
OCIEnv *envhp = env->getOCIEnvironment(); OCIError *errhp = (OCIError *)0;
OCIHandleAlloc((dvoid *)envhp, (dvoid **)&errhp, OCI_HTYPE_ERROR, 0, 0);

//set the TAF handler on the server handle CtxStruct ctx;
ctx.occiconn = conn;
strcpy(ctx.data, "CONNECTION 1");
OCIServer *svrhp = conn->getOCIServer();

OCIFocbkStruct foc;
foc.callback_function = (OCICallbackFailover)my_tafcb; foc.fo_ctx = (void *)&ctx;
OCIAttrSet(svrhp, (ub4)OCI_HTYPE_SERVER, (dvoid *)&foc, (ub4)0,
(ub4)OCI_ATTR_FOCBK, errhp);

stmt = conn->createStatement("Select to_char(sysdate) From Emp"); ResultSet *rs = stmt->executeQuery();

int r = 0;

while (r++ < 5)
{

rs->next();
cout << rs->getString(1) << endl;
}

cout << "5 rows fetched...Stop and restart instance" << endl; string s;
cin >> s;

cout << "Continuing fetch..." << endl;

while (rs->next())
cout << rs->getString(1) << endl;

stmt->closeResultSet(rs);
conn->terminateStatement(stmt);

env->terminateConnection(conn);
Environment::terminateEnvironment(env);

} catch (SQLException &ex)
{

cout << ex.getMessage() << endl;
}
}

Regards,
Jose Luis. Received on Wed Oct 05 2005 - 09:28:01 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US