User's Manual

Chapter 11. Services Tutorials 139
versioned object type Quux {
BigInteger[1..1] id = quuces.id INTEGER;
String[1..1] name = quuces.name VARCHAR;
object key(id);
}
Example 11-7. The versioned keyword
The consequences of marking an object type as versioned are explained in Section 11.5.2 Fully
versioned types.
11.5.2. Fully versioned types
All instances of the object type Quux defined in Example 11-7 are versioned.
Marking one object type as versioned may impose constraints on other object types, forcing
them to be versioned, too. Two most straightforward examples of this are subtyping and composite-
component relationship.
object type GreatQuux extends Quux {
String[0..1] email = great_quuces.email VARCHAR;
component Foobar[0..n] foobars = join great_quuces.id
to foobars.great_quux_id;
Country[1..1] country = join great_quuces.country_id
to countries.id;
reference key (great_quuces.id);
}
Example 11-8. Components and required compound attributes
In Example 11-8, the GreatQuux object type is versioned, because it extends a versioned type. If
the object type X is marked as versioned, then the versioning service infers that the subtypes and
components of X are also versioned.
This happens because a data object fully owns its components. As part of properly versioning a data
object, we must version its components. In Example 11-8, this semantic constraint dictates that the
object type Foobar is also versioned.
Generally speaking, versioning a data object means recording its creation and deletion events, as well
as all changes to its attributes. For example, if a Great Quux’s email was quux@example.com on
19 Jan. and changed to great_quux@example.com on 12 Apr., the versioning service will have
a record of this.
In the event that this data object is rolled back to its 19 Jan. state, then the email address has to be
changed back to quux@example.com. This is an example of versioning a scalar attribute.
We use the term scalar attribute to refer to a property that has a simple object type, such as BigInte-
ger, Boolean, or String.
If the properties type of an object type are compound, they are referred to as compound attributes.
In Example 11-8, Country is a compound object type (the exact PDL definition is not shown for
the sake of brevity). Thus, the property country of the object type GreatQuux is a compound
attribute.
As the example of the email property demonstrates, the case of versioning scalar attributes is a
straightforward one, while compound attributes require a little extra care. Section 11.5.3 Recoverable
types explains another situation in which compound attributes require special treatment.