Click here to view in Java NamescopesName scopes are designed primarily for individual lookup; you can find a named object by looking up its name in the scope of the appropriate scope object. carObj.nameObj(cont, "Car"); //name the object in the scope of the cont //where cont is the handle to the container carObj.lookupObj(cont, "Car"); //to look up and assign to the carObj the object named "Car" in the cont scope objects.ddl
class Car : ooObj
{
public:
int VIN;
void setVin(int vinNum)
{
ooUpdate();
VIN = vinNum;
}
int returnVin()
{
return VIN;
}
};
class Part : ooObj
{
public:
int partNum;
void setPartNum(int num)
{
ooUpdate();
partNum = num;
}
int returnPartNum()
{
return partNum;
}
};
createObj.cpp
#include <iostream>
using namespace std;
#include <ooObjy.h>
#include "objects.h"
int main(int argc, char* argv[])
{
int returnval = 0;
ooObjy::startup();
char *bootfile = "test.boot";
char *dbName = "testDB";
char *contName = "testCont";
ooConnection *connection = ooObjy::getConnection(bootfile);
ooSession *session = connection->createSession("main_session");
try
{
session->begin(oocUpdate);
ooHandle(ooFDObj) fd;
fd.exist(bootfile, oocUpdate);
ooHandle(ooDBObj) db;
if (db.exist(fd, dbName));
else
{
db = new ooDBObj(dbName);
}
ooHandle(ooContObj) cont;
if (cont.exist(db, contName, oocUpdate));
else
{
cont = new(db, 4, 0, contName) ooContObj;
}
ooHandle(Car) carObj;
carObj = new(cont) Car();
carObj.nameObj(cont, "Car"); //name object "Car" in scope of cont
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;
}
Updating an ObjectTo update an object, you call the functions from the object handle. ooHandle(Car) carObj; //declare object handle carObj = ... //instantiate car handle carObj->setVin(); //call function from handle
update.cpp
#include <iostream>
using namespace std;
#include <ooObjy.h>
#include "objects.h"
int main(int argc, char* argv[])
{
int returnval = 0;
ooObjy::startup();
char *bootfile = "test.boot";
char *dbName = "testDB";
char *contName = "testCont";
ooConnection *connection = ooObjy::getConnection(bootfile);
ooSession *session = connection->createSession("main_session");
try
{
session->begin(oocUpdate);
ooHandle(ooFDObj) fd;
fd.exist(bootfile, oocUpdate);
ooHandle(ooDBObj) db;
if (db.exist(fd, dbName));
else
{
db = new ooDBObj(dbName);
}
ooHandle(ooContObj) cont;
if (cont.exist(db, contName, oocUpdate));
else
{
cont = new(db, 4, 0, contName) ooContObj;
}
ooHandle(Car) obj;
obj.lookupObj(cont, "Car");
carObj->setVin(23);
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;
}
Deleting an ObjectTo delete an object, you call the ooDelete function and pass in the object handle. ooDelete(obj); //where obj is the handle to the object you're deleting //obj can be handle to a database, container, or an object
Using the database created from the example above, you can lookup an object and delete it. update.cpp
#include <iostream>
using namespace std;
#include <ooObjy.h>
#include "objects.h"
int main(int argc, char* argv[])
{
int returnval = 0;
ooObjy::startup();
char *bootfile = "test.boot";
char *dbName = "testDB";
char *contName = "testCont";
ooConnection *connection = ooObjy::getConnection(bootfile);
ooSession *session = connection->createSession("main_session");
try
{
session->begin(oocUpdate);
ooHandle(ooFDObj) fd;
fd.exist(bootfile, oocUpdate);
ooHandle(ooDBObj) db;
if (db.exist(fd, dbName));
else
{
db = new ooDBObj(dbName);
}
ooHandle(ooContObj) cont;
if (cont.exist(db, contName, oocUpdate));
else
{
cont = new(db, 4, 0, contName) ooContObj;
}
ooHandle(Car) obj;
obj.lookupObj(cont, "Car");
ooDelete(carObj)
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;
}
|
|||
