Declarative Objectivity (DO) Language : Expressions
Expressions
Expressions are building blocks within clauses.
 
Use These Expressions
To Do This
Specify constant values
Specify values provided by the DO system or the computer on which it is running
Represent a list, set, or map and its elements
Represent the class and nondefault attribute values of a new persistent object
Represent an interval of elapsed time
Access the values of a persistent object’s attributes
Access the values of a collection’s elements
Access the values that can be reached indirectly from a persistent object
Specify the objects for a DO statement to process (the query source)
Operate on input values to produce output values
Specify string-matching patterns
Note:Examples in expression topics are based on the Rental Fleet Sample Schema.
About Expressions
Expressions are the main building blocks within DO clauses, and therefore within DO statements. Whereas a DO clause provides the context for an expression, the expression provides the detail for what to do within that context.
Different kinds of DO expressions serve various purposes:
Literal expressions represent values that remain constant throughout the execution of a DO statement.
Object structures, collection structures, and interval structures represent complex values that consist of other values.
Attribute expressions and collection-element expressions enable you to obtain values from the attributes or collections of existing persistent objects.
System values enable you to obtain values from the DO system or from your computer system.
Operator expressions enable you to test, transform, combine, or otherwise process input values (called operands) to produce output values.
Returned Values
DO processes expressions by evaluating (parsing and interpreting) them. The result of evaluating an expression is to return a value, called the returned value or output value. The type of the returned value is its result type. Result types may be any of the supported Objectivity/DB data types: Boolean, numeric, string, date, time, datetime, interval, object reference, embedded object, or collection.
The result type of a returned value depends on the kind of expression:
The result type for a literal expression is determined by syntax details of the expression.
For example, 2017-3-3 is a date literal, but 2017-3-3-12 is a reference literal (an OID).
The result type for an attribute expression is determined by the class that defines the attribute.
For example, when evaluated against a VehicleModel object, the attribute expression seatingCapacity returns an integer value, because the VehicleModel class defines seatingCapacity as an integer attribute.
The result type for a collection-element expression is determined by the collection to which the element belongs.
For example, when evaluated against a RentalCompany object, the collection-element expression highVolumeDates[1] returns a date value, because the RentalCompany class defines the attribute highVolumeDates as a list of dates.
The result type for an operator expression is determined by the expression’s operator.
For example, the expression brand == 'Tesla' returns true, false, or null, because those are the values the equality operator (==) can return, by definition.
Note:An expression is called a predicate expression if its return type is Boolean—that is, if it returns the Boolean values true, false, or null. The most common use for a predicate expression is in a WHERE Clause to filter the objects of a query source. A predicate expression is typically an operator expression, but could also be, for example, an attribute expression that evaluates to the value of a Boolean attribute.
Expression Context
When DO evaluates an expression in a statement, it does so relative to some evaluation context, which may change from one clause to the next. In a typical by-value query, the initial evaluation context is established by a clause such as FROM, which specifies a sequence of objects called the query source. Each object in the query source serves in succession as the evaluation context for a subsequent WHERE clause, and each object qualified by the WHERE clause serves in succession as the evaluation context for a subsequent RETURN clause.
As an example, consider the following statement, in which the query source is the sequence of persistent VehicleModel objects stored in the federated database:
FROM VehicleModel WHERE brand == 'Tesla' RETURN seatingCapacity;
When the WHERE clause considers a particular VehicleModel object, that object serves as the current context object for the expression. Accordingly, the expression brand can be interpreted as a direct attribute of the current context object, and the value of that attribute can then be compared to the specified literal string 'Tesla' .
A similar process occurs with the RETURN clause, whose evaluation context is the sequence of VehicleModel objects that have been qualified by the WHERE clause. As each qualified VehicleModel object in the sequence serves as the current context object for the RETURN clause, the expression seatingCapacity is interpreted as a direct attribute of that object. The effect of the statement is to return the seating capacity for each vehicle model whose maker is Tesla.
Combined Expressions
In general, expressions can be used recursively within other expressions. For example, the expression in the WHERE clause in the following statement consists of four nested expressions:
Notice that an enclosing expression can change the evaluation context for nested expressions.
The sequence of persistent RentalCompany objects constitute the initial evaluation context for the WHERE clause, so the expression models is interpreted as a direct attribute of RentalCompany.
The result of the models expression is a collection of referenced VehicleModel objects, which become the new evaluation context for interpreting the brand attribute expression.
Every operator expression has one or more nested expressions, which are its operands. For more information about operator expressions, see Operator Expressions.