Java Reference
In-Depth Information
subpackages, recursively obtained with calls to package2schemas() for each
subpackage.
query UML::Package::package2schemas() : OrderedSet (RDB::Schema) {
self . map package2schema()->asSequence()->
union( self .getSubpackages()-> collect (package2schemas()))
->asOrderedSet()
}
Looking at the package2schema() mapping, you can see our first when
clause in the script. We want to map UML Package elements to RDB Schema ele-
ments only if they contain persistent classes. The hasPersistentClasses()
query can determine this; you can see it here along with the isPersistent()
query it uses. As you can see, a class is persistent if it contains a stereotype equal
to the String 'persistent' .
query UML::Package::hasPersistentClasses() : Boolean {
ownedElements-> exists (
let c : UML::Class = oclAsType (UML::Class) in
c. oclIsUndefined () implies c.isPersistent())
}
query UML::ModelElement::isPersistent() : Boolean {
stereotype->includes('persistent')
}
The mapping from package to schema involves selecting and collecting
all the UML::Class instances from the package and invoking the
persistentClass2table() mapping.
mapping UML::Package::package2schema() : RDB::Schema
when { self .hasPersistentClasses() }
{
name := self .name;
elements := self .ownedElements-> select ( oclIsKindOf (UML::Class))->
collect ( oclAsType (UML::Class). map persistentClass2table())
->asOrderedSet()
}
The persistentClass2table() mapping appears next. A when clause
eliminates classes that are not persistent using the same query that was used ear-
lier to determine whether a package contained at least one persistent class. The
name of the table is mapped from the name of the class. The columns of the table
are created by the class2columns() query and sorted by name. Primary keys
are created using the class2primaryKey() mapping, while foreign keys are
created using the class2foreignKeys() query.
Search WWH ::




Custom Search