实际上,从概念模型生成 Postgresql 物理模型时,似乎没有保留继承信息。
作为一个练习(为了好玩,你可能会说),我设计了一个粗略的解决方案......
- 拥有 Postgres DBMS 的可编辑版本(使用标准版本,或创建副本,或将其嵌入物理模型中)
- 在此 DBMS 中,在 Profile > Table 下添加转换“PreserveInherits”(见下文)
- 在 DBMS 中,添加一个转换配置文件“PreserveInheritance”,模型类型为“Conceptual Data Model”,并在使用上述“PreserveInherits”转换的 Post-generation 中添加一个步骤
- 在 CDM 中使用工具 > 生成物理数据模型时,确保在 PDM 生成选项的“详细信息”选项卡中推送/选中“启用转换”
- 该技巧通过覆盖表上的物理选项来生成所需的“inherits(foo)”选项。
PreserveInherits 转换的来源:
dim targetmap
dim targetmapcreation
sub DescentTargets(pkg, trfm)
dim obj
for each obj in pkg.tables
if not (obj.IsShortcut) then
dim src : set src = trfm.GetSource(obj)
if not (src is nothing) then targetmap.add src,obj
end if
next
for each obj in pkg.Packages
DescentTargets obj,trfm
next
end sub
function GetTargetObject(obj, model, trfm)
' global dims are not reset betweeen generations, use a timer to reset it sometimes
if isempty(targetmap) or datediff("s",targetmapcreation,time)>60 then
set targetmap = CreateObject("Scripting.Dictionary")
targetmapcreation = time
' fill map with information about target objects
DescentTargets model,trfm
end if
if targetmap.Exists(obj) then set GetTargetObject = targetmap.Item(obj)
end function
Sub %Transformation%(table, trfm)
' find origin entity
dim source : set source = trfm.GetSource(table)
if not (source is nothing) and source.IsShortcut then set source = source.TargetObject
if not (source is nothing) and source.ClassKind = cls_Entity then
' walk up to parent entity
dim link
for each link in source.InheritsFrom
dim cdmparent : set cdmparent = link.ParentEntity
if not (cdmparent is nothing) and cdmparent.IsShortcut then cdmparent = cdmparent.TargetObject
if not (cdmparent is nothing) then
' walk "back" to target table of parent entity
' trfm.GetParent(cdmparent) does not work as I hoped, use a helper function
dim pdmparent : set pdmparent = GetTargetObject(cdmparent,table.model,trfm)
if not (pdmparent is nothing) then
' msgbox "found parent table " & pdmparent.name
table.physicaloptions = "inherits (" & pdmparent.code & ")"
end if
end if
' TODO modify the code to deal with several inheritances...
exit for
next
end if
End Sub