Home > Metamodelling Concepts > Custom Constraints
A good metamodelling language already provides a great set of features that enable you to constraint the valid set of models to a large extent. OOMEGA provides e.g. entity and attribute classes, attributes, associations, compositions, exact multiplicities and some others.
On the other hand there are always some specific constraints that should be guaranteed by the database back-end at transaction commit, but cannot be expressed by a generic metamodelling language. Hence we introduced the concept of custom constraints. So you can code an arbitrary constraint with Java that will be automatically checked at commit time.
In SDL a custom constraint can be realized with a method. The method's signature must be "protected void customConstraints()". Within its implementation the "check" method is called with the following parameters:
- a message describing the potential constraint violation
- the field to which the constraint is related to or "null" if it is a class-level constraint
- a boolean value that states whether the check has been successfully passed or not
Here's a simple example.
@entity class ModelFolder extends Folder { protected void customConstraints() { check("Folder name of model root folder must be 'Models', not: '" + getName() + "'", ModelFolder.P.name, "Models".equals(getName())); } }
Next chapter: Textual Syntax Specification