[odb-users] Re: Can one use ODB with Classes generated by XSD?
B Hart
bhartsb at gmail.com
Tue May 1 15:04:33 EDT 2012
Hello Boris,
I'm re-visiting this thread since ODB now supports MS SQL and I'm at a
place where I might be able to use ODB, and my requirements have changed .
Particularly I no longer have the need to map my schema into an existing DB
that doesn't match the schema well. That is I'm going to create a DB that
matches the Schema.
I've used CodeSynthesis XSD to generate classes for a set of schemas that
happen to be nicely hierarchical. Essentially the XSDs define the elements
for patient care records. Each record has up to ~550 elements divided into
~23 subsections/categories. Elements in the subsections have all the
different cardinalities. For example, elements relating to adminstering a
medication are defined in a complex element with cardinality sequence
(since multiple medications might be administered to the same patient, or
the same medication given at different times).
As an evaluation exercise I generated a DB schema from the XSDs using
Altova's XMLSpy. It generated a set of tables very reflective of the
organization of the XML Schemas as well as the element constraints. I'm
wondering if I similarly relied on ODB to generate the tables if it would
produce a similar DB schema, as well as the constraints based on the
element types? Haven't tried it yet.
Also, I'm wondering if item #2 below has been implemented? I have written
a program that with excellent help from XSD generated classes reads in
patient records in an XML file, validates the XML, and checks various
business rules and generates a report. At the point after validation has
occurred and Business Rules are checked and pass, the data is ready to put
into the DB. It would be nice if I could use ODB to generate the Schema
and make it happen with just a few lines of code (similar to how easy it is
with XSD to read in a complex schema and serialize it out again.).
Thanks in advance for your comments.
On Wed, Jul 27, 2011 at 7:17 AM, Boris Kolpackov <boris at codesynthesis.com>wrote:
> 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