In this write up we shall see what does it take to develop applications using Versant’s Object Oriented Database. I have been involved in developing and debugging applications with Versant as the database for bit over an year and this write up is just a recap of the kind of work I have been doing with Versant using its C++ libraries. There are options to use other languages like Java, but I’ve used C++.
NOTE: This write up is only contains the approach with brief reference to its C++ API classes. It does not describe the C++ API in detail. For that you would need to get your hands on the Versant Usage Manual and Versant Reference Manual for C++.
Definitions
Firstly what is an Object Oriented database ?
Object Oriented database (a.k.a Object database) allows its user to represent information as Objects. The schema is created as a set of classes and the instances of the class are persisted into the database and are called objects. The advantage of using an Object database is its easy to represent classes you have designed into the database directly. You could use all the advantages of object oriented(-ness) for your database objects. You could design base classes and derive classes with more special functionality. And invoke virtual methods on the base-class (after loading them from the database) which could invoke a derived class functions. And use complex object composition to represent one object holding other objects.
(Also See: http://en.wikipedia.org/wiki/Object_database)
Some Basics of Versant
Before we begin developing applications we need to be aware of some concepts, classes, tools, and procedures that Versant provides its users/developers.
Concepts
Once you have your persistent classes ready (we will see how to get these classes later). You could stream the schema into the database. And then populate them with data (object instances).
Query Language
All queries to the versant database are written in a propreitary query language called VQL (Versant Query Language). You could refer to the reference manual to learn about this.
Internal Representation
Each object is uniquely identified by OID (Object Identifier). An OID is a numeric string that takes the form of “dd.nn.nnnn” where dd, nn and nnnn are integers. Example -
1.0.4941,
32.36.43204 … etc.
Concept of Transaction and Writes
When modifying the object instances in the database using the APIs, we could begin a transaction and start modifying the data, each of the data we modify we mark it as dirty. And at the end if the transaction is committed only that data which was marked dirty actually gets written to the database.
Templates and Prerequisites
Many of the Versant’s C++ API classes makes extensive use of Templates (parameterized classes). If you are not familiar with C++ templates you could just do a quick read up on the basics of it. As we would only use the already provided template classes it shouldn’t be that hard.
Types of Objects
Objects in versant can be
Persistent — those ones which were / can be saved to the database.
Transient — those which only reside in memory.
Versioned Objects — Objects could be versioned. You could have a persistent object and create newer versioned objects based on the base/parent object. You could have a version tree of the objects.
What Versant Persistent Classes can Encapsulate?
Versant Persistent classes can encapsulate the portable data types that are shown below and other persistent classes, collection classes. However it cannot encapsulate enums, unions, and C style pointers or C++ references. If you want to indicate you want to refer to another class as a link, then you should use Link<type> classes of Versant.
Important Versant Classes
PObject : Is the base-most class. For any persistent Versant Object. This has methods -
acquirelock — acquire a lock on itself,
as — method to down-cast to a more specific derived class
operator new — Creates a new persistent object for any sub-type. There are some helper macros for this like – O_NEW_PERSISTENT
delete — delete itself from memory and database based on the type of object it is (destructor is called).
releaseobj — release the object from memory.
PVirtual (inherits from PObject) : This class has methods for hashing and searching.
Read the rest of this entry »