<criteriaElements>
<function name="EQ" property="employee.type">FULL_TIME</function>
<function name="EQ">
<path>employee.type</path>
<literal type="myPackage.Employee.Type">FULL_TIME</literal>
</function>
<function name="IN">
<path>employee.type</path>
<literal type="java.lang.List" memberType="myPackage.Employee.Type">FULL_TIME, PART_TIME</literal>
</function>
</criteriaElements>
A criteria element is mapped to a CriteriaElement instance: expression, select, order, group,
group restriction, and hint.
<and>
<function name="GT">
<function name="SIZE" property="expenseItems" />
<literal>5</literal>
</function>
<function name="LT">
<function name="year" native="true" resultType="java.lang.Integer">
<path>employee.hiredDate</path>
</function>
<literal>2015</literal>
</function>
</and>
<function name="IN">
<path>employee.type</path>
<literal>FULL_TIME, PART_TIME</literal>
</function>
<function name="CONCAT">
<path>employee.firstName</path>
<literal>,</literal>
<path>employee.lastName</path>
</function>
A function can be a native function supported by underlying database. For example,
function year(date) returns the year of a date.
<function name="year" native="true" resultType="java.lang.Integer">
<path>employee.hiredDate</path>
</function>
A function with property name and value can be written in 3 different ways.
<function name="EQ" property="employee.type">FULL_TIME</function>
<function name="EQ" property="employee.type">
<literal>FULL_TIME</literal>
</function>
<function name="EQ">
<path>employee.type</path>
<literal>FULL_TIME</literal>
</function>
EQ(equal) functions with property name and value will be used to initialize entity property
values if applyToCreate is true(default) for create view or if hiddenForQuery is false (default)
for query view.
<function name="EQ" applyToCreate="true" applyImmediate="false" hiddenForQuery="true">
<path>employee.type</path>
<literal type="myPackage.Employee.Type">FULL_TIME</literal>
</function>
<literal type="java.lang.Integer">123</literal>
<literal type="java.util.List" memberType="myPackage.ExpenseClaimItem">
<expenseClaimItem>
<code>00</code>
<expense>200.00</expense>
</expenseClaimItem>
<expenseClaimItem>
<code>01</code>
<expense>300.00</expense>
</expenseClaimItem>
</literal>
<literal type="java.util.Map"
mapEntryKeyType="java.lang.String" mapEntryValueType="java.lang.Integer">
<entry>
<key>001</key>
<value>200</value>
</entry>
<entry>
<key>002</key>
<value>300</value>
</entry>
</literal>
Literal values support the following expressions in addition to JSF EL expressions:
#{current_user}, #{current_user.propertyName}, #{current_date}, #{current_date.calendarFieldName}
<function name="EQ" property="creator">#{current_user}</function>
<function name="EQ" property="author">#{current_user.name}</function>
<function name="EQ" property="createdDate">#{current_date}</function>
<function name="EQ" property="year">#{current_date.YEAR}</function>
<function name="EQ" property="type">#{param.employeeType}</function>
<function name="IN" property="type">FULL_TIME,PART_TIME</function>
<function name="EQ" property="bookmarkableURL">#{containerBean.viewInfo.bookmarkableURL}</function>
<criteriaElements>
<or>
<function name="NE" property="type">FULL_TIME</function>
<function name="GE" property="hiredDate">2010-5-18</function>
</or>
<not>
<function name="EQ" property="type">FULL_TIME</function>
</not>
<or>
<and>
<function name="EQ" property="type">FULL_TIME</function>
<function name="GE" property="hiredDate">2010-5-18</function>
</and>
<not>
<function name="EQ" property="type">FULL_TIME</function>
</not>
</or>
</criteriaElements>
For example, return 5 if expense is greater than $5000; return 2 if expense is greater than $2000 but less than or equal to $5000; return 0 otherwise.
<switchCases>
<case>
<function name="GT" property="expense">5000</function>
<literal>5</literal>
</case>
<case>
<and>
<function name="GT" property="expense">2000</function>
<function name="LE" property="expense">5000</function>
<and>
<literal>2</literal>
</case>
<case>
<literal>0</literal>
</case>
</switchCases>
<object xmlns="http://www.cmobilecom.com/af/objects"
id="expenseClaims" type="entities">
<entityType>ExampleHR.EC</entityType>
<criteriaElements>
<function name="GE">
<subquery resultType="java.util.Integer" collate="" />
<select>
<function name="COUNT" property="expenseClaimItems.id" />
</select>
<function name="GT" property="expenseClaimItems.expense">1000</function>
</subquery>
<literal>2</literal>
</function>
</criteriaElements>
</object>
If the collate property is empty string, it stands for the root of parent query.
The subquery collates to the root of parent query ExpenseClaim as its root.
A subquery can be independent from its parent query. For example, select total expense amount and total number of distinct expense item codes.
<criteriaElements>
<select>
<function name="SUM" property="expense" />
<subquery resultType="java.util.Integer" entityType="myPackage.ExpenseClaimItem" />
<select>
<function name="COUNT_DISCOUNT" property="code" />
</select>
</subquery>
</select>
</criteriaElements>
<joinGraph>
<property name="order" joinType="INNER">
<property name="creator" joinType="INNER">
<properties joinType="LEFT">roles</properties>
</property>
</property>
</joinGraph>
<fetchGraph exclusive="false">
<properties>description</properties>
<properties joinType="INNER">customer</properties>
<properties joinType="LEFT">orderItems,shipTo,billTo</properties>
<property name="payment" joinType="LEFT">
<properties joinType="INNER">paymentMethod</properties>
</property>
</fetchGraph>
<select>
<path>employee.type</path>
<function name="SUM" property="expense" />
<function name="SUM">
<function name="SIZE" property="expenseItems" />
</function>
</select>
<select>
<path alias="empType">employee.type</path>
<function name="SUM" property="expense" alias="totalAmount" />
<function name="SUM" alias="totalItems">
<function name="SIZE" property="expenseItems" />
</function>
</select>
<asc property="employee.type" />
<asc>
<function name="year" native="true" resultType="java.lang.Integer">
<path>employee.hiredDate</path>
</function>
</asc>
<desc>
<alias>totalAmount</alias>
</desc>
<desc>
<function name="CONCAT">
<path>employee.type</path>
<alias>totalItems</alias>
</function>
</desc>
<group>
<alias>empType</alias>
<function name="year" native="true" resultType="java.lang.Integer">
<path>employee.hiredDate</path>
</function>
</group>
To group and select a number of expressions, set attribute select to true.
For example,
<group select="true">
<path alias="employeeType">employee.type</path>
<function name="year" native="true" resultType="java.lang.Integer"
alias="hiredYear">
<path>employee.hiredDate</path>
</function>
</group>
The specified aliases will be assigned to selections and used in grouping.
<having>
<function name="EQ" property="employee.type">
<literal>FULL_TIME</literal>
</function>
<function name="GE"
<alias>hiredYear<alias>
<literal>2015</literal>
</function>
</having>
<object xmlns="http://www.cmobilecom.com/af/objects"
id="object1" type="entity">
<entityType>ExampleHR.EMP</entityType>
<criteriaElements>
<function name="EQ" property="type">FULL_TIME</function>
</criteriaElements>
...
</object>
Example: create an Expense Claim item collection
<object xmlns="http://www.cmobilecom.com/af/objects"
id="createExpenseClaim" type="entity">
<entityType>ExampleHR.EC</entityType>
<mode>CREATE</mode>
<criteriaElements>
<function name="EQ" property="expenseClaimItems">
<literal>
<expenseClaimItem>
<code>00</code>
<expense>200.00</expense>
</expenseClaimItem>
<expenseClaimItem>
<code>01</code>
<expense>300.00</expense>
</expenseClaimItem>
</literal>
</function>
</criteriaElements>
</object>
Example: list all unpaid orders. Left join payment property to retrieve orders without
payment.
<object xmlns="http://www.cmobilecom.com/af/objects"
id="unpaidOrders" type="entities">
<entityType>Ecommerce.SO</entityType>
<criteriaElements>
<function name="IS_NULL" property="payment"></function>
<joinGraph>
<properties joinType="LEFT">payment</properties>
</joinGraph>
</criteriaElements>
</object>