有没有办法将命名约定应用于在 Oracle SDDM 中创建的模型,以将实体和属性的逻辑名称更改为标题大小写?
我们正在对数据模型进行逆向工程,但没有找到选项。我们是否需要使用缩写文件来管理它?
有没有办法将命名约定应用于在 Oracle SDDM 中创建的模型,以将实体和属性的逻辑名称更改为标题大小写?
我们正在对数据模型进行逆向工程,但没有找到选项。我们是否需要使用缩写文件来管理它?
Oracle SQL Developer Data Modeler 中的自定义转换脚本 -
function toTitleCase(str)
{
return str.replace(/\w+/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
tables = model.getEntitySet().toArray();
for (var t = 0; t<tables.length;t++){
table = tables[t];
name = toTitleCase(table.getName());
table.setName(name);
columns = table.getElements();
size = table.getElementsCollection().size();
for (var i = 0; i < size; i++) {
column = columns[i];
cname = toTitleCase(column.getName());
column.setName(cname);
}
table.setDirty(true);
keys = table.getKeys();
for (var i = 0; i < keys.length; i++) {
key = keys[i];
if(!key.isFK()){
kname = toTitleCase(key.getName());
key.setName(kname);
}else{
kname = toTitleCase(key.getFKAssociation().getName());
key.getFKAssociation().setName(kname);
key.getFKAssociation().setDirty(true);
}
}
}
在 Powershell 中编写了以下代码,用于将逻辑实体的名称和属性更改为 Oracle SDDM 中的标题案例 -
$Culture = Get-Culture
# Path to the XML File
$directoryPath = "<Path to the Data Modeling Design>\logical\entity\seg_0"
function Change-Name-To-Title-Case
{
Param (
[parameter (Mandatory=$true, position=1, ParameterSetName='XML File Path')]
[string]$FilePath
)
[XML] $XmlDocument = ( Select-Xml -Path $FilePath -XPath / ).Node
[System.Xml.XmlWriterSettings] $XmlSettings = New-Object System.Xml.XmlWriterSettings
#Preserve Windows formating
$XmlSettings.Indent = $true
#Keeping UTF-8 without BOM
$XmlSettings.Encoding = New-Object System.Text.UTF8Encoding($false)
#--------------------------------------------------------------------
# Modify the Element - Entity Value
#--------------------------------------------------------------------
$elem_entity = $XmlDocument.SelectSingleNode("//Entity")
$elem_entity.Name = ($Culture.textinfo.totitlecase(($elem_entity.Name).ToLower()))
#--------------------------------------------------------------------
# Modify the Entity - Attributes Value
#--------------------------------------------------------------------
$elem_attributes = $XmlDocument.SelectNodes("//Attribute")
foreach ($elem_attribute in $elem_attributes ){
$elem_attribute.Name = ($Culture.textinfo.totitlecase(($elem_attribute.Name).ToLower()))
}
#--------------------------------------------------------------------
# Save the File
#--------------------------------------------------------------------
[System.Xml.XmlWriter] $XmlWriter = [System.Xml.XmlWriter]::Create($FilePath, $XmlSettings)
$XmlDocument.Save($XmlWriter)
#Close Handle and flush
$XmlWriter.Dispose()
}
Get-ChildItem $directoryPath -Filter *.xml |
Foreach-Object {
Change-Name-To-Title-Case -FilePath $_.FullName
}