|User's Guide: Small Ada 95 Object Database; Version 0.1.0; Document Revision $Revision: 1.9 $|
|Prev||Chapter 4. Development Guide||Next|
All objects which are expected to be persistent are implementations of the abstract type OOS.Persistent.Object. This abstract class requires the implementation of the following methods:
Load the instance from the server into the memory
Store the instance on the server
The Load procedure is called upon loading the object contents by means of the Get_Object method. The Store procedure is called upon executing a commit operation.
There are two proposed implementations for the Load/Store functions:
Simply leave the generation of such procedures to the odlprep processor. The odlprep will generate all methods required by the server and client libraries to work properly.
Doing it manually
The minimal implementation is shown below. This example simply writes/reads the object contents as a raw stream into/from the server. The disadvantage of this method is that neither the server nor the client knows any thing about the object structure. In case that you add a new field to the object and then you try to load the object from the server, the application code code will fail, since the stored object is smaller then the expected object. In order to overcome this problem, the server provides so called templates where the application my store structural information about the object.
If you are using odlprep building a template will be done by the preprocessor. The preprocessor creates a code which is executed on the client in order to encode/decode an object based on the template information.
Example 4-1. Minimal Load and Store implementation
procedure Load( This : in out Object; S : in Stream_Access; Tmp : in Persistent.Handle := null ) is begin Object'Read( S, This ); end Load; procedure Store( This : in out Object; S : in Stream_Access; Tmp : in Persistent.Handle := null ) is begin Object'Write( S, This ); end Store;