UML Model/Relation Db Table Mapping Design For LiteMda - Draft
In this article, I talk about the "UML Model/Relation Db Table Mapping Design" for LiteMda.
What is "UML Model/Relation Db Table Mapping Design"?
-To make the persistation of Domain Objects being transparent to Db Tables, it needs to find a way, as natually as possible, to represent all the kinds of associations among class objects.
What kinds of associations need to be considered?
-Generalization, Association, Directed Association, Self Association, Aggregation and Composition, .
Then, let's deal with them on by one.
Generalization
ClassB generalizes ClassA means ClassB is a subclass of ClassA.
Natually, we can uses two tables, TableA and TableB, to implement the mapping. TableB as the subclass needs including all the columns in TableA, and there will be two default transactions be implemented that when we insert a new row to TableB, we must also insert one in TableA, and when we delete rows in TableA, we must check if the related rows in TableB also need to be deleted. To represent the Generalization Hierarchy, we may use a global ID for each instance, and if, for one instance, there are more than one rows in the tables, the global ID of them should be same.
Association/Aggregation/Composition
ClassB associates with ClassA means ClassB and ClassA have the references each other.
ClassB aggregates ClassA means ClassA is one of the parts of ClassB.
ClassB is composed of ClassA and some other classes means ClassA and some other classes can fully compose a ClassB.
The reason that I talk about them together here is for O/R Mapping, they are some degree similar that they all need to associate with their related objects, having the references each other for each pair of objects.
Since ClassB and ClassA have the references each other, we can use TableB and TableA ,and each table has a column as the friend key of the other, of cource, the main keys and friend keys are all global IDs. Transactions needed: delete.
Directed Association
ClassB directed associates with ClassA means ClassB has a reference to ClassA, but ClassA hasn't a back reference.
Different from Association, only TableB has a column as friend key to TableA, and the main keys and friend keys are all global IDs. Transactions needed: delete.
Self Association
ClassA self associates with itself means ClassA has a reference to another ClassA.
We can use TableA to represent ClassA, and TableA has a column as a friend key to TableA, and the main keys and friend keys are all global IDs. Transactions needed: delete.
----------------
Something else:
Two kinds of the basic associations aren't be discussed here, Realization(class generalize from an interface) and Dependency(class uses an interface or another class), because generally, they won't impact the Db Tables' structures for class objects.
This article is a draft version, welcome any suggestion and criticism, thanks!
//The End