[odb-users] Re: Can one use ODB with Classes generated by XSD?

Boris Kolpackov boris at codesynthesis.com
Wed Jul 27 10:17:23 EDT 2011


Hi Brian,

B Hart <bhartsb at gmail.com> writes:

> Where you say "(those can be placed into a separate file and included into
> the ODB compilation with the --odb-epilogue option)." do you mean the
> xsd-generated classes with pragmas?

XSD-generated classes do not have any pragmas (XSD doesn't know anything
about ODB). So you will need to add those pragmas yourself, which can be
placed into a separate file (we call it a "mapping" file) and "added"
to the ODB compilation process (when you compile the XSD-generated header)
using the --odb-epilogue option.


> So hypothetically, if I decided to create a whole new DB (based on the XML
> Schema and using ODB), how would I best use the XSD-generated classes with
> ODB to do this?  Will ODB create a complete DB from the XSD-generated
> output?

No, as I explained above, you will need to "tell" ODB how to map the
XSD-generated classes to the database, just as you would do for hand-
written code. ODB has no idea which XSD-generated classes should be
objects, which should be value types, which attribute/element is the
object id, etc. Only you can decide such aspects of the mapping.

There will be other difficulties as well. Here are a few from the
top of my head:

1. All data members in the XSD-generated classes are protected which
   makes them inaccessible to ODB. To overcome this, you could post-
   process the XSD-generated header with a script and replace
   'protected:' with 'public:'. Alternatively, we can add an option
   to XSD to generate data members public.

2. XSD uses wrapper templates for 'one' and 'optional' members. ODB
   will not know how to "unwrap" them without some help from your
   side (value_traits). We are currently working on the 'wrapper'
   concept for ODB which will make handling this much easier.

3. You will need an id member for every object class. This may
   or may not be a problem in your case. Support for objects
   without an explicit object id is also on our TODO list.

Boris



More information about the odb-users mailing list