home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / docs / start.txt < prev    next >
Encoding:
Text File  |  1995-06-05  |  2.9 KB  |  74 lines  |  [TEXT/ttxt]

  1. BASIC PHILOSOPHY
  2. OOFILE provides you with frameworks to easily model databases and integrate your database with typical application frameworks. It is NOT a general persistence mechanism, to attach to any and all c++ classes.
  3.  
  4. OOFILE uses static c++ definitions to allow you to write clear logic however everything in OOFILE is dynamically defined. This allows us to create OOFILE interfaces on the fly, to existing databases, and leaves scope for DLL and other plug-in versions of OOFILE.
  5.  
  6. OOFILE uses only c++, with minimal use of macros and no special preprocessor required.
  7.  
  8.  
  9. Before venturing into database definitions, let's consider some
  10. operations on a database containing People, Job Histories and Companies.
  11.  
  12. // print my address
  13. cout << People["Andy Dent"].Address;
  14.  
  15. // get a separate list (iterator) of people who worked for software companies
  16. dbPeople softP( People.PrevJobs->Company->MainBusiness()=="Software" );
  17.  
  18. // for the current softP record (ie person), print the number of large companies
  19. // where they've worked, and the current company size
  20. cout << softP.Name() << "\t"  
  21.      << (softP.PrevJobs->Company->NumEmployees() > 100).count()
  22.      << "\t" 
  23.      << softP.CurrentJob->Company->NumEmployees() << endl;
  24.  
  25.  
  26. NOTE:
  27. The () at the end of fields, as shown above, are optional for all cases except 
  28. fields in relational expressions, eg: People.CurrentJob->StartDate().
  29.  
  30.  
  31. DECLARING SIMPLE TABLES
  32. To define a table with a few fields, the simplest declaration would be:
  33. CLASS_TABLE(dbPeople)
  34.    dbChar    Name, Address;
  35.    dbInt     Salary;
  36. };
  37.  
  38. This defaults the size of the dbChar fields to 80 chars. To specify the
  39. size of the fields, and/or control indexing options, you need to add a
  40. constructor:
  41. CLASS_TABLE(dbPeople)
  42.    dbChar    Name, Address;
  43.    dbInt     Salary;
  44.  
  45.    dbPeople : Name(40, "Name", kIndexNoDups), 
  46.               Address(255, "Address"), 
  47.               Salary("Salary", kIndexed)
  48.    {};
  49. };
  50.  
  51. Note that the constructors also specify the field name strings. These
  52. are optional, but are of great benefit when writing query and
  53. report-writer logic or when constructing a database schema that should
  54. be readable by others.
  55.  
  56.  
  57. RELATIONS
  58. One of the big features of an ODBMS is modelling the relationships between
  59. objects. OOFILE allows you to model relations in a pure ODBMS sense, using
  60. object identifiers, or explicitly perform runtime joins over database fields.
  61. This would be mainly used by people porting existing database structures. There
  62. are a number of syntaxes available to establish relationships, eg:
  63.  
  64.    dbConnect_ctree theDB;    // the physical database
  65.    dbAcademics Academics;    // a couple of tables
  66.    dbStudents  Students;
  67.  
  68.    dbRelation Supervision("Supervision");  // a concrete relation
  69.  
  70.    Supervision.Names("Supervises",        "is Supervised by")
  71.               .Tables(Academics,           Students)
  72.               .Links(Academics.Supervises, Students.Boss)
  73.               .JoinField(Academics.StaffNo, Students.SupervisorNo);
  74.