AQL queries

Introduction

AQL is short for Adaptive Query Language and is a set of object classes that is used to both express and perform data queries against the WAF content objects. Currently AQL does not support update queries, but it supports select queries with aggregate functions, joins, group by etc. The terminology and structure of queries is similar to SQL but with two key differences:

  1. The query is not expressed as a string. It is expressed by a series of objects using both method calls and operator overloading*.
  2. The result of queries can be C# class objects. These objects inherit from ContentBase and contains typed properties and methods.

* Operator overloading is a technique where operator such as “==” “I” “&” are given special meaning if used on certain types of objects.

The consequence is that you get better compile time verification of both query expressions and query results. Data type errors are discovered compile time and not runtime. The system also gives websites complete protection against SQL injection attacks.

The AQL Caches

Internally queries against objects in WAF are broken down into two stages. Stage one query the database to build a list of the content Ids that are relevant for the query. This stage uses an internal cache called the “Query Cache”. This cache stores the id of relevant objects for each query.

Stage two retrieves the data necessary to instantiate the content object properties. Stage two uses an internal cache called “Content Cache”. This cache stores a copy of the data need to instantiate a content object.

Both caches are “smart” and are updated automatically by the system as data change. You can always rely on that the data you retrieve is fresh and not out of date. Both caches have special dictionaries of property changes that trigger cache updates. The cache is very effective and performing similar queries repeatedly is very fast.  Normally you do not need worry about performance even if you execute 1000 queries on a single page view.

The system supports lazy loading of property values and if a particular property is not loaded by default in the main query the system will load it when it is accessed.

The AQL objects

There are three main base objects in AQL

  1. Query. It defines the whole query statement. You can compare this object to the Command object in ADO.NET.
     
  2. Expressions. Expressions represent all fields and combination of fields and field functions that can be evaluated as a value. Expressions use operator overloading to combine several expressions into one combined expressions. (Compared to SQL these objects represents the part of an SQL statement that can follow the SELECT and WHERE statement of query.)
     
  3. Content aliases. These objects represent a reference to a specific content class. The FROM statement takes this object as its parameter. The class can also represent a join of two or more content aliases.
     
  4. Result values. These objects represent a reference to a particular column and current row in the result set of an AQL query. The object can represent either a direct property value or a content object.
     
  5. Result set. This is comparable to ADO.NET record set objects. It can contain a table of both direct property values and content objects.