[odb-users] Polymorphism through shared library

Arnaud Kapp arnaud.kapp at islog.com
Thu Nov 3 12:01:19 EDT 2016

Hello, I have questions about extending ODB models through shared 
library. I'm not sure what I'd like to achieve is possible.

I've read the following thread 

A quick intro: My project is module (as in dynamically loaded shared 
library) oriented. The core binary does a few things, provides some 
facilities, but mostly
it loads modules. Modules provides most of the functionality of the 
software. Third-party user can write modules for their own use.

In the project, we can describes 3 "components" that would need to use 
the database:
     + The core binary
     + The "officially supported by the project" modules
     + Third party modules.

Database versioning must be enabled, otherwise update will too much of a 
pain for everyone.

The "core binary" would have its own schema, and each modules could 
define an additional schema with its own versioning. This would allows
for updating the core and modules separately, ie a module update
could introduces new fields into its schema w/o needing a "core binary" 
DB version bump.

Up until this point I believe everything is possible if done carefully.
However, in addition to all of that, I'd like to be able to extend some 
classes from the "core binary" from modules code. And this is where I 
think I'd be stuck.

Consider this:

The following classes would come from "core binary".

// Keep tracks of what happened in the application.
#pragma db object polymorphic
class AuditEntry
#pragma db id
int id_;

// Where User is an other class mapped in the database.
std::shared_ptr<User> author_;
std::string what_happened_;

// Also from "core binary"
// Store information about an user-related event.
#pragma db object
class UserAuditEntry : public AuditEntry

std::shared_ptr<User> target_;

This 2 classes, along with the User class lives in the "core binary" 
schema and have their own model version.

Now from a third party modules.
#pragma db object
class Lama
#pragma db id
int id_;

std::string name_;

#pragma db object
class LamaAuditEntry : public AuditEntry
std::shared_ptr<Lama> target_;

Now I have a problem: I am mixing schemas together. The classes that are 
part of "third_party_schema" and "core_binary_schema" are referencing 
each other. I believe I can't have separate version for them now.

Sorry, this mail is getting a bit long, and is kinda messy. "Simply" 
stated: Is there a good way to extends core classes from a shared 
library and have them not share the same version? My guess is no based 
on my understanding of the linked thread. If its not supported / 
supportable, could you recommend an alternative in how to architect this?

Best regards / Cordialement,

Arnaud KAPP
31, Avenue du Général de Gaulle
67000 Strasbourg

More information about the odb-users mailing list