Subsections
The C++ binding maps the EYEDB object model into C++ by introducing
a generic API and a tool to generate a specific C++ API from
a given schema, built upon the generic API.
Each class in the EYEDB object model is implemented as a C++
class within the C++ API: there is a one-to-one mapping between
the object model and the C++ API.
There are two types of runtime objects: persistent runtime objects and
transient runtime objects.
A runtime object is persistent if it is tied to a database object.
Otherwise, it is transient.
By default, EYEDB does not
provide an automatic synchronisation between persistent runtime objects
and database objects.
When setting values on a persistent runtime object, we do not modify
the tied database object.
One must call the store method on the persistent runtime object
to update the tied database object.
Note that any persistent runtime object manipulation must be done
in the scope of a transaction.
To illustrate object manipulations, we introduce a simple concrete
example using the schema-oriented C++ API, based on the previous ODL
example construct:
// connecting to the EyeDB server
eyedb::Connection conn;
conn.open();
// opening database dbname
personDatabase db(dbname);
db.open(&conn, eyedb::Database::DBRW);
// beginning a transaction
db.transactionBegin();
// creating a Person
Person *p = new Person(&db);
// setting attribute values
p->setCstate(Sir);
p->setName(name);
p->setAge(age);
p->getAddr()->setStreet("voltaire");
p->getAddr()->setTown("paris");
// creating two cars
Car *car1 = new Car(&db);
car1->setBrand("renault");
car1->setNum(18374);
Car *car2 = new Car(&db);
car2->setBrand("ford");
car2->setNum(233491);
// adding the cars to the created person
p->addToCarsColl(car1);
p->addToCarsColl(car2);
// storing all in database
p->store(eyedb::RecMode::FullRecurs);
// committing the transaction
db.transactionCommit();
A few remarks about this code:
- the statement Person *p = new Person(&db) creates a
transient runtime object. This runtime object is not tied to any
database object until the store method has been called.
- all the selector and modifier methods such as setName,
getAddr, addToCarsColl have been generated by the EYEDB
ODL compiler from the previous ODL construct.
- the eyedb::RecMode::FullRecurs argument to the store
method allows the user for storing each object related the calling instance:
so the runtime object car1 and car2 within the cars
collection will be automatically stored using the store method
with this argument.
- the call to transactionCommit ensures that the database changes
will be kept in the database.
EyeDB manual