The where statement restricts results, returning only those that match the value comparison(s), or in the case of the negated value comparison, return only the results that do not match the value comparison.
After the use of the where statement you must also provide two operands for comparison, as well as an operator on which the two operands can be compared.
To create multiple comparisons you must use the statements
For more information see GMQL Conjunctions and Disjunctions.
The simplest use of the where keyword is to define one comparison consisting of two operands and one operator.
select ENTITY_PROPERTIES|* from TYPE_SIGNATURE where OPERAND OPERATOR OPERAND
The following query lists all instances of the
User entity where the value of the property
select * from com.braintribe.model.user.User u where u.lastName like 'Smith'
The following query lists all instances of the Group entity where the value of the property
conflictPriority is equal to
select * from com.braintribe.model.user.Group g where g.conflictPriority = 0.00
Note the difference between the two select queries above. While the comparison on a string value requires the use of single quotation marks, the comparison on a number value does not.
Additionally, because the second query above includes the decimal place (that is,
0.00) no additional suffix is required. We could also declare:
g.conflictPriority = 0D.
This would have the same effect. For more information on the use of numbers and strings in a value comparison see GMQL Syntax.
If you want to compare a complex property, one whose value represents another entity type, you need to use an entity reference. In the following query, only
User entity instances are returned when their property picture contains an
AdaptiveIcon instance with the ID of
select * from com.braintribe.model.user.User u where reference(com.braintribe.model.resource.AdaptiveIcon, 2L) = u.picture
from TYPE_SIGNATURE where OPERAND OPERATOR OPERAND
The following query returns all instances of the
User entity where the value of the property
from com.braintribe.model.user.User where lastName like 'Smith'
Because no alias was defined after the entity source declaration, when the property
lastNameis used, GMQL assumes that the source is
User. Unlike the select query, aliases are not mandatory in entity queries. For more information, see GMQL Syntax.
The where statement can only be used on properties that are of a collection type (either Set, List or Map), since these are the only property types that can be compared; all other types return a single value or instance.
property SOURCE_PROPERTY of reference(ENTITY_REFERENCE, ID) where OPERAND OPERATOR OPERAND
The following query returns a collection of groups where the name of the group is
property groups g of reference(com.braintribe.model.user.User, 'john.smith') where g.name = 'admins'
An operand can be many things, from a basic type (string, date, number, and so on) to entity references, enum references, collections or even functions. Available operands include:
- Simple types (Strings, Numbers, dates, booleans, and so on)
- null values
- entity type references
- enum type references
- property references (for example, using an alias: p.lastName)
- functions (Aggregate functions, string functions, boolean functions, and date functions)
|The operator in is used to compare one value against a set of values contained in a collection. If the value provided is contained within this collection the entity instance will be returned as part of the results set. The value is provided on the left-half side of the operator while the set is provided on the right-hand side. |
There are two specific ways that this operator can be used. You can either use this operator to search a collection property for the value defined, or you search on a specific property for one of several values passed as a set.
Compare a value against those contained in a collection property (return only
or for complex collections (that is, collections whose elements are other entities) (return only
Compare a property of an entity against a collection of values (return only
|Used in string comparisons. For example, |
|Used for non case sensitive comparisons. The functionality of |
|greater than or equal to|
|not equal to|
|less than or equal to|
|Whether the left-hand value equals the right-hand value|