This article is from the Object-Oriented Technology FAQ, by Bob Hathaway rjh@geodesic.com with numerous contributions by others.
WHAT IS OOFILE?
OOFILE is a c++ framework. It can be used as a "traditional" ODBMS or can be
used to access a more traditional RDBMS or record-oriented database. The
current release is implemented with a Faircom c-tree Plus ISAM backend
on Mac and MS Windows. There would be very little difficulty in porting
this to any platform supported by Faircom, and we already have over 8
OS/compiler combinations in use (including 3 in-house).
Design Goals
- everything is native C++ with no (database) preprocessor required
- external interfaces to enable calling from Hypercard, Smalltalk etc.
- keep syntax very simple, familiar to 4GL users and not needing c++ gurus
- safe syntax that makes it hard to do the wrong thing by mistake, making
maximum use of c++ compiler type-checking
- implement with a choice of database engines for the backend
- integrate with a range of common application frameworks
- provide additional classes for managing gui interfaces to help construct
typical database applications, where features are not commonly part of
application frameworks
- use a widely available level of c++ (no RTTI, templates or exception handling)
WHO IS OUR MARKET
1) c++ developers (or wannabees) wanting an embedded database for writing
applications, probably working in combination with an application framework
such as zApp, OWL or PowerPlant.
2) World Wide Web developers seeking a database and report-writer
combination to create web pages in response to queries, searching hundreds
of thousands of records (at least).
BASIC PHILOSOPHY
Object-oriented design is mainly about classes, not individual objects.
OOFILE is similar. Most of the time you model your data in terms of
classes. You do NOT declare individual objects (unlike the ODMG model).
Consider a database from the user's view. They generally see collections of
data and edit or interact with individual records from the collection. The
user doesn't care about individual object identity, they don't create
symbolic names for particular objects. These things may be important inside
the database, but do not need to be exposed.
SOME SIMPLE EXAMPLES
Note: for more examples, including online queries, look on
http://www.highway1.com.au/adsoftware/oofile.html
Before venturing into database definitions, let's consider some
operations on a database containing People, Job Histories and Companies.
// print my address
cout << People["Andy Dent"].Address;
// get a separate list (iterator) of people who worked for software companies
dbPeople softP( People.PrevJobs->Company->MainBusiness()=="Software" );
// for the current softP record (ie person), print the number of large companies
// where they've worked, and the current company size
cout << softP.Name() << "\t"
<< (softP.PrevJobs->Company->NumEmployees() > 100).count()
<< "\t"
<< softP.CurrentJob->Company->NumEmployees() << endl;
NOTE:
The () at the end of fields, as shown above, are optional for all cases except
fields in relational expressions, eg: People.CurrentJob->StartDate().
DECLARING SIMPLE TABLES
To define a table with a few fields, the simplest declaration would be:
CLASS_TABLE(dbPeople)
dbChar Name, Address;
dbInt Salary;
};
This defaults the size of the dbChar fields to 80 chars. To specify the
size of the fields, and/or control indexing options, you need to add a
constructor:
CLASS_TABLE(dbPeople)
dbChar Name, Address;
dbInt Salary;
dbPeople : Name(40, "Name", kIndexNoDups),
Address(255, "Address"),
Salary("Salary", kIndexed)
{};
};
Note that the constructors also specify the field name strings. These
are optional, but are of great benefit when writing query and
report-writer logic or when constructing a database schema that should
be readable by others.
SOME OTHER FEATURES
- Derived fields, either specified as a combination of existing fields or
user-calculated
- User-defined relations
- keyword indexing
- phonetic indexing
- inbuilt report-writer
RELATIONS
One of the big features of an ODBMS is modelling the relationships between
objects. OOFILE allows you to model relations in a pure ODBMS sense, using
object identifiers, or explicitly perform runtime joins over database fields.
This would be mainly used by people porting existing database structures. There
are a number of syntaxes available to establish relationships, eg:
dbConnect_ctree theDB; // the physical database
dbAcademics Academics; // a couple of tables
dbStudents Students;
dbRelation Supervision("Supervision"); // a concrete relation
Supervision.Names("Supervises", "is Supervised by")
.Tables(Academics, Students)
.Links(Academics.Supervises, Students.Boss)
.JoinField(Academics.StaffNo, Students.SupervisorNo);
 
Continue to: