Adichatz generates brute queries to fetch data from Application server or database (by default, one query per entity).
For example, the query for a Customer class is described by an XML file called $projectDirectory/resources/xml/model/customer/CustomerQUERYGENERATED.axml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<queryTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" queryType="JQL" entityURI="adi://myproject/model.customer/CustomerMM" suffix="c" xsi:noNamespaceSchemaLocation="http://www.adichatz.org/xsd/v0.8.7/generator/queryTree.xsd">
    <jointure fieldName="address" jointureType="join fetch " suffix="a"/>
    <jointure fieldName="store" jointureType="join fetch " suffix="s"/>
    <queryPreference orderByClause="c.customerId">
        <parameter id="active" property="active" style="SWT.RIGHT" suffix="c"/>
        <parameter id="address" property="address" suffix="c"/>
        <parameter id="createDate" property="createDate" style="SWT.CENTER" suffix="c"/>
        <parameter id="customerId" property="customerId" style="SWT.RIGHT" suffix="c"/>
        <parameter id="email" property="email" suffix="c"/>
        <parameter id="firstName" property="firstName" suffix="c"/>
        <parameter id="lastName" property="lastName" suffix="c"/>
        <parameter id="lastUpdate" property="lastUpdate" style="SWT.CENTER" suffix="c"/>
        <parameter id="store" property="store" suffix="c"/>
    </queryPreference>
</queryTree>

Remarks:
The query description contains 2 parts:

  • Jointures part describes other entities linked to each rows fetched by the query.
  • The QueryPreference part describes the default attributes managed in the outline panel of a Query Editor. Here, only optional query parameters are listed.



Complete query by changing XML elements:
Now, we want to complete the query in two ways:

  1. Add jointures to fetch the staff of the store and the address with the city and the country of the store.
  2. Add a preference to select only Customers from USA (countryId=103) a new pagination, a new column orders and two filters.

Queries could be easily changed as shown below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<queryTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" queryType="JQL" entityURI="adi://myproject/model.customer/CustomerMM" suffix="c" xsi:noNamespaceSchemaLocation="http://www.adichatz.org/xsd/v0.8.7/generator/queryTree.xsd">
    <jointure fieldName="address" jointureType="JOIN FETCH" suffix="a">
        <jointure fieldName="city" jointureType="JOIN FETCH" suffix="ci">
            <jointure fieldName="country" jointureType="JOIN FETCH" suffix="co"/>
        </jointure>
    </jointure>
    <jointure fieldName="store" jointureType="JOIN FETCH" suffix="s">
        <jointure fieldName="staff" jointureType="JOIN FETCH" suffix="st"/>
        <jointure fieldName="address" jointureType="JOIN FETCH" suffix="sa">
            <jointure fieldName="city" jointureType="JOIN FETCH" suffix="sci">
                <jointure fieldName="country" jointureType="JOIN FETCH" suffix="sco"/>
            </jointure>
        </jointure>
    </jointure>
    <queryPreference orderByClause="c.customerId">
        <parameter id="address" suffix="c"/>
        <parameter id="customerId" style="SWT.RIGHT" suffix="c"/>
        <parameter id="createDate" style="SWT.CENTER" suffix="c"/>
        <parameter id="email" suffix="c"/>
        <parameter id="firstName" suffix="c"/>
        <parameter id="lastName" suffix="c"/>
        <parameter id="lastUpdate" style="SWT.CENTER" suffix="c"/>
        <parameter id="active" suffix="c"/>
        <parameter id="store_city" prompt="Store city" property="city" suffix="a"/>
        <parameter id="store_country" prompt="Store country" property="country" suffix="sci"/>
        <parameter id="customer_city" prompt="Customer city" property="city" suffix="a"/>
        <parameter id="customer_country" prompt="Customer country" property="country" suffix="ci"/>
        <parameter id="staff_name" prompt="Staff name" property="lastName" suffix="st"/>
    </queryPreference>
    <permanentPreferences>
        <queryPreference id="usa" statusBarKey="Navigation" columnOrder="0, 3, 4, 5, 2, 1, 6, 7, 8">
            <pagination firstResult="0" maxResults="50" paginated="true"/>
            <parameter id="customer_country" prompt="Customer country" property="country" permanent="true" entityURI="adi://myproject/model.country/CountryMM" suffix="co" valid="true" columnText="United States" expression="103" operator="="/>
            <filters>
                <filter enabled="true" text="Value in column 'active' is false." searchString="true" column="activeTC"/>
                <filter enabled="false" text="Value in column 'store' contains string 'Australia'." column="storeTC" searchString="Australia" exactString="false" caseInsensitive="false"/>
            </filters>
        </queryPreference>
    </permanentPreferences>
</queryTree>

Explanations:

  • Lines 4 and 5: Fetch city and country of the address of the customer.
  • Line 9: fetch the staff of the customer.
  • Lines 10, 11 and 12: Fetch address, city and country of the store of the customer.
  • Lines 25 to 28: Add parameters allowing the user to extend the selection to specified fields.
  • Line 32: Define e new preference, identified by usa string, column order is changed and chosen Navigation bar is Scale: User can navigates thru pages using a scale control.
  • Line 33: Pagination start to first element (position 0) and fetch 50 rows per page.
  • Line 34: select only customer from USA.
  • Lines 36 and 37: Add 2 filters: first on column Active, second on column Store. Only first filter is enabled.



Open Add navigator item to see how to create a new item in navigator to call the query with defined preference.
Open Change table include to see how to display data from new jointures in table control.

tutorial/complete_query.txt · Last modified: 2015/10/05 17:52 (external edit)