zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Taro 3.1 beta 发布: 开放式架构新增 4 端支持
    JS复习之深浅拷贝
    痞子衡嵌入式:MCUXpresso IDE下SDK工程导入与workspace管理机制
    痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.6)- 串行NOR Flash下载算法(MCUXpresso IDE篇)
    《痞子衡嵌入式半月刊》 第 22 期
    痞子衡嵌入式:读工程师岗位工作31年退休的同事离职信有感
    痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.5)- 串行NOR Flash下载算法(IAR EWARM篇)
    千万不要给女朋友解释 什么是 “羊群效应”
    保姆级教程,带你认识大数据,从0到1搭建 Hadoop 集群
    短链接服务Octopus的实现与源码开放
  • 原文地址:https://www.cnblogs.com/teddyma/p/194924.html
Copyright © 2011-2022 走看看