Active Query Builder support area

Loading metadata from XML file (VCL, ActiveX and Java)

Last modified:


Warning:
This article is valid for Java, ActiveX, and VCL editions.
The appropriate article for Active Query Builder .NET Editon can be found here:
You can create the XML file that stores all necessary metadata information and loads it at the start of the Query Builder. This might be helpful when the database connection is not available at the client-side (in web projects using ActiveX or Java Edition). This feature also could be useful 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 to the rest of the 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 must create an XML file that contains database objects, but not their fields (otherwise, the 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 temporarily set it to True on calling the SaveToXMLFile method. (See Working with Metadata Container to understand the OfflineMode property).
   queryBuilder.RefreshMetadata();
   queryBuilder.OfflineMode = true;
   queryBuilder.MetadataContainer.SaveToXMLFile(cacheFile);
   queryBuilder.OfflineMode = false;

Is this article helpful for you?