TAPSchemaDM
This is the TAP schema defined using VO-DML and created so that a mapping from a arbitrary VO-DML model to its TAP schema can be serialized. The VO-DML tooling will produce the TAP schema for a model as part of the output of the vodmlSchema
command.
The model follows the description of TAP schema in the TAP Standard. The TAP Standard does not provide a machine-readable version of the TAP Schema - this DM fills that gap. Some of model element names themselves are different from the names used in the TAP standard (and this is reflected in the XML serialization). However, naturally the RDB serialization will produce exactly the required tables as described in the TAP Standard - although there are some additional columns produced.
How to use
Java
The Standard VO-DML tooling will produce a TAPSchemaDM instance in the static.TAPSchema()
method of the generated model (See TapSchemaModel for the Model class of the TAPSchemaDM itself). The code below shows the essential steps
for storing the generated TAPSchema in a database. In this case it is for the TAPSchema for the TAPSchema itself, but it will apply for any model code generated by the VO-DML tooling - which itself does not have a direct dependency declared for this library. However, then to decode and save the TAPSchema instance in a project then a direct dependency to the should be declared.
- Unmarshal the XML instance
- Normalise the tap schema instance to produce the extra key columns required by the database serialization
- Serialize this model instance to the database.
TapschemaModel model = new TapschemaModel();
InputStream is = TapschemaModel.TAPSchema();
JAXBContext jc = model.management().contextFactory();
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<TapschemaModel> el = unmarshaller.unmarshal(new StreamSource(is), TapschemaModel.class);
TapschemaModel model_in = el.getValue();
org.ivoa.dm.tapschema.ColNameKeys.normalize(model_in); // note that this step is necessary before saving to the database to set up the table_name foreign keys
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
model_in.management().persistRefs(em);
em.persist(model_in.getContent(Schema.class).get(0));
em.getTransaction().commit();
Direct to DDL
It is possible to work directly with the XML TAPSchema instances (produced by the VO-DML tools vodmlSchema command) to produce DDL to both create the model tables and fill the TAPSchema tables with the model descriptions.
Model Tables
The DDL for the model tables can be created by executing the tap2posgresql.xsl against the TAPSchema instance. This repository has a test showing this being driven by Java code - in this case the DDL is being created for the TAPSchema itself.
It is possible to drive the transformation from the commandline (after installing the Saxon XSLT processor)
java -jar /opt/packages/SaxonHE12-7J/saxon-he-12.7.jar -xsl:src/main/resources/tap2posgresql.xsl -s:build/generated/sources/vodml/schema/tapschema.vo-dml.tap.xml
It would be equally possible to drive from other languages where Saxon is supported e.g. Python via saxonche.
TAPSchema Content
The TAPSchema content for a particular Model can be created by execution the tap2instanceDDL.xsl XSLT against the TAPSchema instance for a particular model.