HomeActive Query Builder - Metadata handling and filtrationMetadata handling and filtration in Java, VCL and ActiveX EditionsLoading metadata from XML file

2.5. Loading metadata from XML file


This article is valid for Java, ActiveX and VCL editions.

The appropriate article for Active Query Builder 2 .NET Editon can be found here:

You can create the XML file that stores all necessary metadata information and loads it on start of the Query Builder. This might be helpful when database connection is not available at the client side (in web projects using ActiveX or Java Edition). This feature also could be helpful in the following cases.

  • Caching to speed up the metadata loading process.
  • Excluding unwanted objects from the metadata.
  • Adding missing information to the database schema (for example, some databases may miss the foreign key information, so joins will not be created automatically)
  • Adding descriptions or alternate names for database objects and fields.
  • Adding virtual tables and fields.

To build an XML file, you can do the following:

The sample code below is for the ActiveX Edition of Active Query Builder, but it is similar for the rest of editions.

// =========================
// Part one: creation of initial XML file
// ========================

// set this option to True BEFORE retrieving metadata from the database.
// setting this option will slower metadata retrieval procedure,
// but allows you to extract fields of all database objects at once.
ActiveQueryBuilderX1.WorkOffline = True; // This property is called "OfflineMode" in the .NET Edition

// setup database connection
ActiveQueryBuilderX1.ConnectionString = "your ADO connection string here";

// Retrieve metadata from the database and load it to the Metadata Container
ActiveQueryBuilderX1.Connect; //Other editions should use the RefreshMetadata method instead

// save metadata container content to the XML file
ActiveQueryBuilderX1.MetadataContainer.SaveToXMLFile("your filename.xml");

// or retrieve the same information as a string:
mystring = ActiveQueryBuilderX1.MetadataContainer.XML;

// =========================
// Part two: loading metadata from XML file
// ========================

// you should also set the offline mode when working without database connection
// to prevent retrieval of additional metadata information from the database
ActiveQueryBuilderX1.WorkOffline = True;

// load metadata container container from XML file or from URL
ActiveQueryBuilderX1.MetadataContainer.LoadFromXMLFile("your filename or URL.xml");

// or load the same information from string
ActiveQueryBuilderX1.MetadataContainer.XML = mystring; 

To cache metadata you should create an XML file that contain database objects, but not their fields (otherwise, creation of the XML file will be slower). An example of caching is available in the Full-featured MDI Demo (Active Query Builder demo project in VCL Edition). To do this you should call the RefreshMetadata method with the OfflineMode property set to False and then temporary set it to True on calling the SaveToXMLFile method. (See Working with Metadata Container to understand the OfflineMode property).

   queryBuilder.OfflineMode = true;
   queryBuilder.OfflineMode = false;

This page was: Helpful | Not Helpful