
/*
 * This transformation is uni-directional in direction "rdbms" and maps classes in packages to tables in schemas.
 * It is based upon the example in the official QVT specification at http://www.omg.org/cgi-bin/apps/doc?ptc/05-11-01.pdf.
 */

transformation UMLClasses2Tables(uml:SimpleUML, rdbms:SimpleRDBMS) {

	-- map each package to a schema
	top relation PackageToSchema {
	  
	  pn : String;
	  
	  checkonly domain uml p : SimpleUML::UmlPackage {
	    umlName = pn
	  };
	  
	  enforce domain rdbms s : SimpleRDBMS::RdbmsSchema {
	    rdbmsName = pn
	  };
	  
	}
	
	-- map each persistent class to a table
	top relation ClassToTable {
	  
	  cn : String;
	  prefix : String;
	  
	  checkonly domain uml c : SimpleUML::UmlClass {
	    umlNamespace = p : SimpleUML::UmlPackage {
	    },
	    umlKind = 'Persistent',
	    umlName = cn
	  };
	  
	  enforce domain rdbms t : SimpleRDBMS::RdbmsTable {
	    rdbmsSchema = s : SimpleRDBMS::RdbmsSchema {
	    },
	    rdbmsName = cn,
	    rdbmsColumn = cl : SimpleRDBMS::RdbmsColumn {
	      rdbmsName = cn + '_tid',
	      rdbmsType = 'NUMBER'
	    },
	    rdbmsKey = k : SimpleRDBMS::RdbmsKey {
	      rdbmsColumn = cl : SimpleRDBMS::RdbmsColumn{}
	    }
	  };
	  
	  when {
	    PackageToSchema(p, s);
	  }
	  
	  where {
	    ClassToPkey(c, k);
/*	    prefix = cn;
	    AttributeToColumn(c, t, prefix);*/
	  }
	  
	}
	
	relation ClassToPkey {
	  
	  cn : String;
	  
	  checkonly domain uml c : SimpleUML::UmlClass {
	    umlName = cn
	  };
	  
	  enforce domain rdbms k : SimpleRDBMS::RdbmsKey {
	    rdbmsName = cn + '_pk'
	  };
	  
	}
}
