Query template file

The query template file is a mechanism by which we can easily map a query on your logical model to one or more SQL statements. The SQL assets are kept in separate files, which are isolated from the runtime Java code. This template helps database administrators and programmers to locate and analyze SQL statements. Additionally, changes to SQL used for queries do not require recompiling Java code. Also, the addition of new columns into existing tables might not require changing SQL statements that use those tables. Column information is separated out in the SYMBOL_DEFINITIONS section.


Query template file location and naming

A service module can have one or more query template files. Prefix query template files with 'wc-query' and use the extension .tpl.

Default query template files are in the following directory workspace_dir\WC\xml\config\com.ibm.commerce.servicemodule

We can add new queries or extend provided queries, by placing your query template files under the extended configuration directory for our service module.

Custom query template files must be placed in the following directory: workspace_dir\WC\wc\xml\config\com.ibm.commerce.servicemodule-extFor example, a catalog query template file is in this directory: xml\config\com.ibm.commerce.catalog-ext.

Note: Adding new columns to our custom tables requires changing physical SDOs that represent those tables, with the Data Service Layer wizard.


Query template file syntax and loading

Query template files are loaded in ascending alphanumeric order. When files that contain query definitions are loaded, the new queries override the previously loaded queries.

The blocks in the query template must be in this order:

  1. BEGIN_SYMBOL_DEFINITIONS

  2. END_SYMBOL_DEFINITIONS

  3. BEGIN_XPATH_TO_SQL_STATEMENT

  4. END_XPATH_TO_SQL_STATEMENT

  5. BEGIN_ ASSOCIATION_SQL_STATEMENT

  6. END_ ASSOCIATION_SQL_STATEMENT

  7. BEGIN_SQL_STATEMENT

  8. END_SQL_STATEMENT

  9. BEGIN_PROFILE

  10. END_PROFILE.

The BEGIN_PROFILE_ALIASES and END_PROFILE_ALIASES blocks can be defined anywhere within a query template file.

Note:


Query template file organization

A query template file has five main sections, of which the first two are mandatory:


Support for column aliases

To avoid ambiguity in selecting columns with identical name from different tables, column aliases are used. The column alias prefix can be specified before a column symbol reference. The general syntax of the column symbol reference is:

For example:

Assume that the following symbol definitions exist:

The resulting query is translated as: