The C++ binding maps the EyeDBobject model into C++ by introducing a generic API and a tool to generate a specific C++ API based on a given schema, built on the generic API. The generic C++ API consists of about a hundred classes, such as some abstract classes such as the object and class classes and some more concrete classes such as the database and image classes. Each type 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.
For example, the object type in the EyeDBobject model is mapped to theeyedb::ObjectC++ class and the aggregate type is mapped to theeyedb::AgregatC++ class. To avoid writing the fully qualified type name (i.e. eyedb::type) every time, you can use the C++ directive using namespace eyedb.
Initialization
Note that all standard command line options recognized in theargc/argvarray are suppressed in this array byeyedb::init(int &argc, char *argv[]). Note that this statement is optional, because allEyeDBallocated resources, open databases, and connections are automatically released or closed in the exit() function.
Connection Setting-up
Although the exception error policy is not currently standard in EyeDB, we recommend using it: it makes the code clearer and safer. In the following examples, we use the exception error policy to avoid error handling noise in the introduced C++ code.
Database Opening
Transaction Management
A call toeyedb::Database::transactionCommit() means that all the operations performed in the transaction scope will be saved to the database, while a call toeyedb::Database::transactionAbort() means that all the operations are forgotten will become But the abortion at level 1 is without effect: it will not be performed; only the commit at level 0 will be executed. One can pass parameters to the transaction one is starting by setting an optional argument of typeeyedb::TransactionParams to the transactionStart method.
Schema and Class Manipulation
Object Manipulation
Creating Runtime Objects
Synchronizing Runtime Objects to Database Objects
A database identifier uniquely identifies a database, while an object number uniquely identifies an object in a database. The magic number, which is a randomly generated number, provides greater security in the object identification process.
Setting Attribute Values to a Runtime Object
Loading Database Objects
Getting Attribute Values from a Runtime Object
To get the spouse attribute value, we first need to get the spouse OID using theeyedb::attribute::getOid method on the spouse attribute.
Loading Database Objects using OQL
Releasing Runtime Objects
Note that this second way is more efficient, because only the person's name is returned by the server and not the entire object. The C++delete operator is prohibited: if you try to use this operator on anyeyedb::Objectinstance, you will get an error at runtime. Note that if you release a persistent runtime object, you do not release the associated database object.
Removing Database Objects
Generating a Schema-Oriented C++ API
Makefile.package: an example Makefile in compilepackage.cc and templatepackage.cc: make -f Makefile.package will compile and link the generated API files and templates. For example, to generate a schema-oriented C++ API in the tmp directory, prefixing runtime classes withpp, pinning C++ files with.cpp, we invokeeyedbodlas follows:
The Generated Code
The use of the generated files for the user methods is introduced in the chapter Methods and Triggers. For example, if an object loaded is of class Person , it will execute a new Person(db) to correctly construct the loaded object. Note that to use the generated schema-oriented API, it is not mandatory to use the generated database class: you can use the geneticeyedb::Database class; there are many cases where you will have no trouble.
But to avoid any potential problems, it is strongly recommended to use the generated database class. a root class which is the superclass of all generated classes except package and database classes. If its name is not given using the rootclass command-line option name, its name is Root. for each ODL class, a C++ class of the same name is created, optionally prefixed by a string if specified by the -class-prefix command-line option.
Constructors and Copy Operator
Down Casting Methods and Functions
There is another case where downcast methods and functions are used, namely when loading a database object. When loading a database object (for example aPersondatabaseobject) using theeyedb::Database::loadObject, we get a genericyedb::Objectinstance, not aPersoninstance nor aEmployeeinstance. Nevertheless, in case a Person database object is loaded, a Person persistent runtime object is correctly constructed by the generated API.
We strongly recommend that you use these safe downcasting methods and features instead of performing manual casting.
Selector Methods
The first selection method is to retrieve the entire attribute string value, while the second is to retrieve a specific character within that string value. Note that the return value cannot be a null pointer as this is a literal attribute fully contained in the instance. Since the collection is not ordered, the index of the element to get depends on the order of the load and is not specified.
These array-oriented methods are generated for user convenience, because it is somewhat easier to scan an array than to scan an unordered array. While ordering this collection, the index of the element to be retrieved is completely appropriate. When a string modifier is present for an attribute, all preceding selector methods change in the same way: for each dimension in the array, an index argument is added to the beginning of the selector method.
Modidier Methods
If the collection has not yet been created, this method call will create it using themagorderargument for its size order value.
Initialization
When an array modifier is present for an attribute, all preceding modifier methods are modified in the same way: for each dimension in the array, an index argument is added to the beginning of the selector method. For every method of an ODL class, there is a generated C++ method with the same name and corresponding type.
Database Opening
This section introduces some complete simple examples that can be found in the directoryprefix/share/doc/eyedb/examples. The first two programs listed here introduce the generic C++ API of EyeDB, while the next two programs present the generated schema-oriented C++ API through the simple schema example introduced in this chapter.
Generic Query Example
Generic Storing Example
Schema-Oriented Query Example
Schema-Oriented Storing Example
Simple Administration Example