Declarative Objectivity (DO) Language : Expressions : Object Structures
Object Structures
An object structure is an expression for specifying the class and attribute values of a persistent object.
Syntax 

objectStructure : ( className '{' '}') | (className '{' assignment (',' assignment)* '}' );
assignment : targetAttribute ':' valueExpression;
targetAttribute : (embeddedAttribute '.')* attribute;
valueExpression : expression;
Quick Look 
Create a new customer with the specified first name, last name, and user identifier:
CREATE Customer{firstName:'Fred', lastName:'Mertz', userId:'fmertz'};
Update a particular customer’s embedded address:
UPDATE Customer WHERE lastName == 'Mertz' SET address TO Address{street:'123 Fourth St.', city:'San Jose', state:'CA', postalCode:'95128'};
Create a new location with the specified airport code and list of stalls:
CREATE Location{airportCode:'LAX', stalls: LIST{3-3-1-47, 3-3-1-48}};
Create a new rental contract with the specified tracking number and a reference to a new customer:
CREATE RentalContract{trackingNumber: 345, customer: CREATE Customer{firstName: 'Fred', lastName: 'Smith'}};
Create a new reservation whose time stamp is the current moment:
CREATE Reservation{timestamp: $$NOW};
Discussion 
An object structure is an expression that specifies the class of an object and optionally provides values to be assigned to the object’s attributes. You can use an object structure:
To specify a new referenceable object in a top-level or nested CREATE Statement.
To specify a new or reinitialized embedded object in an ADD Clause, in a SET Clause, or nested within an enclosing object structure.
Specifying the Class of the Object
An object structure must begin with the name of the class of the object being created or reinitialized. The class must exist in the schema. For example:
Location{...}
The class name should include namespace qualification if needed to identify a unique class. For example:
FleetData.Location{...} 
The designated class may be either referenceable or embeddable, as determined by the context.
Specifying Attribute Values for the Object
An object structure may include 0 or more comma-separated assignment expressions enclosed in curly braces. Each assignment expression specifies a value for a targetAttribute of the object being created or reinitialized. The targetAttribute and valueExpression are separated by a colon. The order of assignment expressions is not significant.
A targetAttribute is typically a direct attribute defined by the object’s class. For example, the following object structure assigns a value to airportCode, which is a direct attribute defined by the Location class:
Location{airportCode: 'LAX'}
If the class defines an embedded-object attribute, you can assign values to individual attributes of the embedded object. In such cases, the targetAttribute can be specified as an indirect attribute of the enclosing object. For example, the following object structure assigns values to two indirect attributes of Location, which are themselves direct attributes of the embedded Address:
Location{airportCode: 'LAX', address.city: 'Los Angeles', address.state: 'CA')
There is no intrinsic limit to the depth of a targetAttribute expression, as long as the designated attributes are reachable entirely through embedded objects.
You specify the value to be assigned to the targetAttribute by providing a valueExpression that returns a value of the type defined for the targetAttribute in the specified class. For example, the following object structure assigns a string value to the string attribute airportCode, and assigns a list to the list attribute stalls:
Location{airportCode:'LAX', stalls: LIST{3-3-1-47, 3-3-1-48}}
The following table indicates the kind of valueExpression you use for each type of targetAttribute :
targetAttribute Type
valueExpression
Boolean, numeric, string, date, time, datetime
Literal expression, system value expression, or other expression returning a value of the appropriate type
Reference
Embedded object
Nested object structure
Collection
Interval
A valueExpression can include operator expressions and system values, as long as they return values of the required type. For example, the following object structure uppercases the string assigned to userId, and truncates the string assigned to pw if it is longer than 15 characters:
Customer{firstName:'Fred', lastName:'Mertz', userId: UPPER('fMertz'), SUBSTRING(pw, 0, 15)}
Note:Specifying a nested object structure for an embedded-object attribute is equivalent to specifying the embedded object’s individual attributes as indirect attributes of the enclosing object.
For example, the following object structures are equivalent:
Location{airportCode: 'LAX', address.city: 'Los Angeles', address.state: 'CA')
 
Location{airportCode: 'LAX', address: Address{city: 'Los Angeles', state: 'CA'} 
Implicitly Assigning Default Values
The number of assignment expressions you include in an object structure is flexible. An explicit assignment expression is required only when assigning a nondefault value to an attribute. Omitting an assignment expression for an attribute implicitly assigns a built-in default value to that attribute. For example, the following object structure specifes a Location object with all default attribute values:
Location{}
Similarly, the following object structure assigns a nondefault value to one attribute (airportCode) of a Location object, and implicitly assigns a built-in default value to each of the other attributes (name, address, rateFactor, stalls, and so on):
Location{airportCode: 'LAX'}
An attribute’s type determines the built-in default value assigned to it.
Type of Omitted Attribute
Built-in Default Value
Displayed Value
Numeric
0
0
Boolean
False
false
String
Null, for variable-length string
null
Empty string, for fixed-length string
''
Date
0001-01-01
0001-01-01
Time
00:00:00
00:00:00
DateTime
0001-01-01 00:00:00
0001-01-01 00:00:00
Reference
Null
0-0-0-0
Embedded object
Each component attribute is set to a value appropriate to the type
Collection
Null, for variable-size collection
null
Collection of null elements, for fixed-size collection
{}
Interval
Empty interval
{}