从类模型映射到关系模型

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

根据领域模型分析数据模型

Mapping from the Class Model to the Relational Model 从类模型映射到关系模型

Having described the two domains of interest and the notation to be used, we can now turn our attention as to how to map or translate from one domain to the other. The strategy and sequence presented below is meant to be suggestive rather than proscriptive - adapt the steps and procedures to your personal requirements and environment.

在需要对两个领域建模时,现在我们可以关注如何从一个领域映射或转换映射到另一个领域。以下的策略和方法,就是要启发,而不是强制的步骤和程序应用到您的个人需求和环境。

1. Model Classes

Firstly we will assume we are engineering a new relational database schema from a class model we have created. This is obviously the easiest direction as the models remain under our control and we can optimise the relational data model to the class model. In the real world it may be that you need to layer a class model on top of a legacy data model - a more difficult situation and one that presents its own challenges. For the current discussion will focus on the first situation. At a minimum, your class model should capture associations, inheritance and aggregation between elements.

1. 类建模

首先,我们将假设从已创建的类模型生成一个新的关系数据库模型。这显然是最容易的,可控制的,可以通过关系数据库模型反向优化类模型。在现实世界中可能你需要将类模型作为数据模型的上层,这是更困难的情况,也对自己提出了一个挑战。对于目前的讨论将集中在第一种情况。至少,你的类模型应捕元素之间的联系、继承和聚集关系。

2. Identify persistent objects

Having built our class model we need to separate it into those elements that require persistence and those that do not. For example, if we have designed our application using the Model-View-Controller design pattern, then only classes in the model section would require persistent state.

2. 确认持久对象

已建成的类模型,我们需要区分这些元素,那些需要持久化和那些不是。例如,如果我们设计我们的应用程序使用Model - View- Controller设计模式,那么只有MODEL模型部分需要持久化状态。

3. Assume each persistent class maps to one relational table

A fairly big assumption, but one that works in most cases (leaving the inheritance issue aside for the moment). In the simplest model a class from the logical model maps to a relational table, either in whole or in part. The logical extension of this is that a single object (or instance of a class) maps to a single table row.

3. 假设一个持久化类映射一个关系表

大多数情况下,这都是一个合理的假设,除去继承问题以外(暂且不考虑)。在最简单的模型中,逻辑模型中的一个类映射一个关系表的全部或一部分。这种逻辑的延伸是一个单一的对象(或类的实例)映射关系表中的一行数据。

4. Select an inheritance strategy.

Inheritance is perhaps the most problematic relationship and logical construct from the object-oriented model that requires translating into the relational model. The relational space is essentially flat, every entity being complete in its self, while the object model is often quite deep with a well-developed class hierarchy. The deep class model may have many layers of inherited attributes and behaviour, resulting in a final, fully featured object at run-time. There are three basic ways to handle the translation of inheritance to a relational model:

4. 选择一个继承策略

相关文档
最新文档