Chapter 3. Client Programming Tutorial

Table of Contents
Specifying Persistent Objects
Building client applications

Specifying Persistent Objects

Lets assume we want to write a small application which maintains personal records of a small company. Each member of this company has a name (Firstname and Familyname) a sequence number and for example an age. Such an object is specified in the way shown below:

Example 3-1. Defintition of the Person Object

with Ada.Strings.Unbounded;                     use Ada.Strings.Unbounded;
 
package Person is
 
   type Object is persistent record
          First_Name  : attribute Unbounded_String;
          Family_Name : attribute Unbounded_String;
          Age         : attribute Natural := 0;
          Seq         : attribute Natural := 0;
       end record ;

   ... 
 
   procedure Display(
      This : in Object );
 
   ...
end Person;
      

Together with the object specification you may may want to specify a procedure Display to dump onto some channel the contents of the object for debugging purposes. The object specification will be put into the file person.ods and the package body which contains the implementation of Display will be put into person.odb

The odlprep translator will generate from this file a package person (files person.ads, person.adb) which can be used together with the SDB packages load/store objects from the ADB server. This step is done as shown below:

Example 3-2. Using odlprep


gnade@boavista:~/adb/test/odlprep> odlprep person
 
Ada 95 Object Defintion Language Translator; Version 0.1.0
Copyright (C) 2003 Michael Erdmann (http://www.purl.org/net/michael.erdmann)
 
 
Processed 1 file(s) successfully
 
gnade@boavista:~/adb/test/odlprep> ls -ltr perso*
-rw-r--r--    1 gnade    users        3967 2005-07-30 15:15 person.ods
-rw-r--r--    1 gnade    users        4776 2005-07-30 15:15 person.odb
-rw-r--r--    1 gnade    users        4903 2005-07-31 17:06 person.ads
-rw-r--r--    1 gnade    users        6948 2005-07-31 17:06 person.adb