The Body Project

This is our first real project which creates persistent objects. Persistent objects are those whose life span exceeds the life time of the program that created them. We will have an abstract class body, which can be any geometrical body (we will have cubes and cylinders for starters), and each body can identify itself and tell you its surface and volume.


Note: This version uses the standard oonewdb tool to create the new databases rather than a home-grown utility ( the now obsolete create.c utility) to create the database files in the federation. If you already used the old version, please get this new one, or change the Makefiles accordingly.

The Abstract Body Class

The body class is defined in the body.ddl file. The most important thing here is the class definition, which reads
class body : public ooObj {
which says that body inherits from (is a) persistent object. Body is a fully virtual class and cannot be instantiated, but all derived classes inherit the member functions as well as its persistence-capability.


Cubes and Cylinders

Now its time to look at the derived classes, cube.ddl and cylinder.ddl. They inherit from body, and thus become persistent objects as well.


What is DDL?

If you kept wondering why the files were called .ddl, ddl stands for "data definition language". There is a processor which looks at the DDL file, and creates the appropriate header files needed to give the classes their persistence-capability. In addition, the schema (the information about an object which the database must maintain) is defined and added to the federation file at this point. From there on, the database "knows" about this type of objects.


Creating Persistent Objects

All these definitions being made, a program can now work with the persistent classes, and create persistent objects. The add program adds a cube and a cylinder to the database each time it is invoked, and the ooRead program reads what's in the database.

As you might expect, typing make in the Body directory creates a database called "Bodies" in the federation, and creates both the add and ooRead utilities.

You can add to the database using the add program, and review what you have done with the ooRead program:

ribm01 % add
------- Cube:
Volume:  15.625
Surface: 37.5
Type:    Cube
------- Cylinder:
Volume:  62.83
Surface: 87.962
Type:    Cylinder
ribm01 %
ribm01 %
ribm01 % ooRead

 ------------------
Type:    Cube
Volume:  15.625
Surface: 37.5
 ------------------
Type:    Cylinder
Volume:  62.83
Surface: 87.962
 ------------------

Now how does this work? Well, we have seen that the DDL files are processed by the ddl processor, adding a lot of code (have a look at the generated cube_ref.h and cube_ddl.C files!) which gives the classes their persistence-capability. Now the code

ooHandle(body) cu,cy;
...
cu = new cube(2.5);
creates a new (persistent) object of type cube in our "default" database (like a default directory), which is our previously created "Bodies" database. This is "committed" to the database in the end with the call
if( oovTopTrans.commit() != oocSuccess )
  cout << "transaction commit error" << endl;
and now the objects are persistent, that is, you can get them back in another program as if they were actually created there.

... to be continued.


MLP Sept 07, 1997