Click here to view in Java
Connecting to the database.
ooConnection *connection = ooObjy::getConnection("test.boot");
For more information on connections visit our FAQ. Using a session.
session = connection->createSession("Main Session");
session->begin(oocUpdate); // Start a new transaction in update mode
............... // perform database operations
session->commit(); // Commit the transaction
For more information on sessions visit our FAQ. Creating a database.
ooHandle(ooDBObj) db = new ooDBObj("testDB");
For more information on handles or databases visit our FAQ. Creating a container.ooHandle(ooContObj) cont = new(db, 4, 0, "testCont") ooContObj; //where db is the handle to the database in which to create the container For more information on containers visit our FAQ. Creating an object.ooHandle(ooObj) obj = new(cont) ooObj; //where cont is the handle to the container in which to create the object For more information on objects visit our FAQ. Simple application.simpleapp.cpp
#include <iostream>
using namespace std;
#include <ooObjy.h>
int main(int argc, char* argv[])
{
int returnval = 0;
//ooObjy::setLoggingOptions(oocLogAll, oocTrue, oocFalse); //enable session logging for debug
ooObjy::startup();
char *bootfile = "test.boot"; //insert bootfile name here
char *dbName = "testDB"; //insert database name here
char *contName = "testCont"; //insert container name here
ooConnection *connection = ooObjy::getConnection(bootfile);
ooSession *session = connection->createSession("main_session"); //insert session name for log or '0' for default
try
{
session->begin(oocUpdate);
ooHandle(ooFDObj) fd;
fd.exist(bootfile, oocUpdate); //open in update mode
ooHandle(ooDBObj) db; //open/create db
if (db.exist(fd, dbName));
else
{
db = new ooDBObj(dbName);
}
ooHandle(ooContObj) cont; //open/create cont
if (cont.exist(db, contName, oocUpdate));
else
{
cont = new(db, 4, 0, contName) ooContObj;
}
ooHandle(ooObj) obj;
for (int i = 0; i < 100; i++)
{
obj = new(cont) ooObj;
}
session->commit();
}
catch(ooException &error)
{
cerr << error.what() << endl;
session->abort();
returnval = 1;
}
catch(...)
{
cerr << "unknown error" << endl;
session->abort();
returnval = 1;
}
ooObjy::shutdown();
return returnval;
}
|
|||
