Sometimes it may be practical to keep a target value once it has been set even if its corresponding source value changes. Consider in our example we want the name of a table to be set only when it is first created, i.e if the table's name or that of its package is modified and a retransformation is performed, the new name should be left unmodified and vice versa. The following script realizes this situation.
transformation umlToRdbms(uml:SimpleUML, rdbms:SimpleRDBMS) { top relation PackageToSchema { theName: String; checkonly domain uml p:UMLPackage{ name=determineValue(p.name, theName) }; enforce domain rdbms s:Schema { name=determineValue(s.name, theName) }; when{ theName = if p.oclIsUndefined() then s.name else if s.name.oclIsUndefined() then s.name else p.name endif endif; } } query determineValue(value:String, default:String) : String { if modelElementValue.oclIsUndefined() then defaultValue else modelElementValue endif } }During forward transformation, the query is used to determine the value used to match the package and that set to the table's name. Since the value of the variable theName is bound in the "when" clause to that of the package, the package match will always be satisfied. Since the query returns the name of the table if it is not undefined, its name will only be set if it is undefined.