3 Replies Latest reply on Jun 24, 2016 5:06 PM by rareddy

    Teiid-embedded (9.0.0CR2) export a VDB to XML

    jrod2016

      Is there a way to export a VDB to xml using the teiid-api?

       

      I'd like to do something like this:

       

      VDB vdb = admin.getVDB(VDB_NAME, VDB_VERSION);

      String vdbAsXml = vdb.getVDBAsXML(); //  Is this possible?

       

      Thanks,

      John

        • 1. Re: Teiid-embedded (9.0.0CR2) export a VDB to XML
          rareddy

          Not with single call, with multiple calls it is possible like

           

              public static void exportVDB(Admin admin, String vdbName, int vdbVersion) throws Exception {
                  VDBMetaData vdb = (VDBMetaData)admin.getVDB(vdbName, vdbVersion);
                 
                  for(Model m:vdb.getModels()) {
                      String ddl = admin.getSchema(vdbName, vdbVersion, m.getName(), null, null);
                      ((ModelMetaData)m).addSourceMetadata("DDL", ddl);
                  }
                 
                  FileOutputStream out = new FileOutputStream(vdbName+"-vdb.xml");
                  VDBMetadataParser.marshell(vdb, out);
                  out.close();
              }
          

           

          HTH

           

          Ramesh..

          • 2. Re: Teiid-embedded (9.0.0CR2) export a VDB to XML
            jrod2016

            Hi Ramesh,

             

            Thanks for the prompt reply. This definitely helped. However it seems that the only call required was VDBMetadataParser.marshell(...). I did not need to iterate over the models.

             

            I've included my code below:

             

            Thanks,

            John

             

            private void saveVDBSchema(VDBMetaData vdb) {

               try {

                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

                    VDBMetadataParser.marshell(vdb, baos);

                    final String vdbSchemaStr = baos.toString();

                    // My code goes on to use vdbSchemaStr ...

               } catch (XMLStreamException | IOException e) {

                    logger.error(String.format("Error [%s] while trying to save VDB schema", e.getCause()), e);

                   throw new RuntimeException(e);

               }

            }

            • 3. Re: Teiid-embedded (9.0.0CR2) export a VDB to XML
              rareddy

              Oh! well it looks like it slipped my mind that we added to include the DDL/metadata automatically, originally that is way it was.. Cool