Constraints

Constraints make it possible to impose checks on data as it is loaded. A constraint is expressed as a query which is local to an object--in other words, the query is associated with a particular class, and it applies only to objects in that class as they are loaded. Thus it is invalid to use FIND or FOLLOW in a constraint.

Constraints are not part of models.wrm, but are registered in wspec/constraints.wrm using the syntax shown below. The constraint names the target class, then specifies the relevant query.

Objects which violate constraints will not be loaded and the violation will be reported. The example below uses tace and pparse.

Constraints can be used to specify tags, particular values in fields or even the presence of a value, as is shown below.

Example model and constraint


?Paper Year UNIQUE Int
       Author Text


Class Paper
Constraints "Year:1"
This constraint requires a value in the first field following the Year tag (it must be non-void). An attempt to load this data

Paper X
Author Sam
Year 1995

Paper Y
Author Tom

Paper Q
Year 1992

Paper Z
Author Sally
will generate these warnings:

acedb> pparse rawdata/test.ace
// Parse error near line 7 in Y : Object Y does not satisfy constraints
// Parse error near line 13 in Z : Object Z does not satisfy constraints
// 3 objects read with 2 errors// 2 Active Objects 
acedb>

Limitations

The implementation of constraints is currently bugged (version 4.5)