[odb-users] Encapsulating ODB

Adam Walters awalters at spsy.com
Tue Jul 27 12:23:03 EDT 2021


Thanks Boris,
After some playing around with your 'Hello World" sample, I was able to accomplish what I needed (I had tried this originally but had failed to change one of the references to the original class and assumed that the reams of obscure compiler errors meant it wasn't possible). I ended up creating an abstract base class from which the persistent class derives. The base class has accessor methods for the data members of interest and these are overridden in the derived class to provide the access. Users of the data access layer can instantiate a persistent object through a static factory method in the base class and obtain it as a pointer to the base class (thus avoiding any need to include any of the ODB headers). Once the object has been filled in, it can be persisted by a call to an overloaded method in the base class that calls the database code in the derived class. I haven't fully implemented this yet but I am confident from the test application I have written that it should work.

Best regards,
Adam Walters

-----Original Message-----
From: Boris Kolpackov <boris at codesynthesis.com> 
Sent: Tuesday, July 27, 2021 6:39 AM
To: Adam Walters <awalters at spsy.com>
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Encapsulating ODB

CAUTION: This email originated from outside your organization. Exercise caution when opening attachments or clicking links, especially from unknown senders.

Adam Walters <awalters at spsy.com> writes:

> Although ODB encapsulates the database code, the classes used for 
> persistence have to reference the ODB includes so that the pragmas and 
> other references compile.

You can move the pragmas (and any ODB #include's that they require) to a separate file or #ifdef them out using the ODB_COMPILER macro.
The introduction to Chapter 14, "ODB Pragma Language" has all the
details:

https://codesynthesis.com/products/odb/doc/manual.xhtml#14

Of course that also means you persistent classes won't be able to use some of the ODB feature that depend on types (and thus headers) provided by ODB, such as lazy pointers, change-tracking contains, and sections.



More information about the odb-users mailing list