Chapter 5. Building Applications

Building an application using persistent objects requires to defined the objects to be handled as persistent objects and to add some basic glue code to your application as shown below:

Example 5-1. A minimal Application

with MyObject;
with ODB.Persistent;        
with ODB.Storage.File;             ......          
use  ODB;
procedure Main is 
   O          : ODB.Reference ;
   File_Store : File.Object;

   O := Lookup_Object( "First_Object" );
   if O = null then     
      O := new MyObject.Object;
      Object_Name( O, "First_Object" );
      O.A := 1;
   end if;
   ........... do some thing ......

   when Others =>
end Main;
In order to use persistency for certain objects you need to define these objects in separate packages. This may be done completely by using Ada 95 or by means of the object definition language (ODL) which is an extension of Ada 95. In the example above, this has been done in the package MyObject which provides a persistent data type Object.

Upon start of the application, it will be checked if the object is already known in the persistency store with the name "First_Object". If not, the object will be allocated by means of the new method.