1、环境准备:
1.1、PowerDesigner软件安装:
(略)基本傻瓜式安装,一直next到结束就行,自己也没找到特别好的安装包,就不提供了。
注意事项:如果安装的是32位的PowerDesigner,需要将环境变量中的jdk变为32位的,使用的数据库链接包也为32位的。
1.2、32位的jdk
链接:https://pan.baidu.com/s/1dxg9K-MM48zWYe5LZqpEbA
提取码:2nqv
1.3、MySQL的32位connect.jar(3.1.14、5.0.8、8.0.23)
链接:https://pan.baidu.com/s/1vdcMS60jRBHBjiCGhMb57w
提取码:jjz8
也可以直接官网下载::https://dev.mysql.com/downloads/connector/j/
1.4配置环境变量
这里有两种方法:
(1)https://blog.csdn.net/csdn15679160266/article/details/80767378
一个下载32位安装jdk之后不用修改环境变量所编写的"startup.bat"批处理脚本,同样放置在pd的安装目录下
"startup.bat"脚本内容如下:
%JAVA_HOME写你自己的下载的32位jdk的安装目录%
SET JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_79
%CLASSPATH写你放在pd安装路径下的驱动包,这里我演示的是oracle的%
SET CLASSPATH=F:\powerdesigner16\ojdbc6.jar
%下面是pd的启动程序%
PdShell16.exe
使用管理员方式启动dat文件
(2)修改环境变量
此电脑→属性→
编辑:JAVA_HOME、CLASSPATH、Path。
注意:如果修改完之后没有变更过来可以直接删除system32下面的java.exe、javaw.exe、javaws.exe3个文件,这样它们永远不会再对你的jdk造成冲突,再用cmd中的“where java”命令可以看到自己配置好的环境变量到底是真正生效了还是system32里面的jre伪装的
2、反向MySQL的链接部分
2.1新建一个pdm,dbms选择mysql(https://www.cnblogs.com/vevy/p/10516314.html)
2.2 Database - Connect 选择数据库连接
2.3 配置连接信息
数据库连接这里是通过一个配置文件来获取连接信息的,首次的话因为没有,所以我们需要选择Configure进行配置。
2.4 填写配置信息
如图,选择添加数据库资源,出现如上,相关说明如下:
- Connection profile name:JDBC配置文件名称,可随意填写
- Directory:配置文件保存路径
- Description:配置文件描述,可根据实际用途填写
- Connection type:连接方式,这里我们选择JDBC
- DBMS type:数据库类型,提供大部分主流数据库选择,我们选择MySQL
- User name:登录数据库的用户名
- JDBC driver class:指定驱动类,使用默认的com.mysql.jdbc.Driver
- JDBC connection URL:连接URL,格式jdbc:mysql://ServerIP/Hostname:port/database
- JDBC driver jar files:指定连接的jar包路径
2.5 连接测试和配置保存
如图填写信息完成后,点击左下角的 Test Connection,出现成功提示则说明连接可行:
2.6、注意事项:
此处可能会出现链接不上的问题,我这里遇到的是一直提示无法识别字符集‘255’。
我所用的解决方法是,在连接串后面添加上字符集配置:
?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2b8
成功连接后,我们一路确定下去把这个配置文件进行保存,最终你可以在你指定的文件夹(该目录没有限制,自定义一个目录即可,此处我是建立在安装文件下的一个userConf文件夹内)中看到这个保存好的文件:
3、从已有数据库中的表进行逆向工程图
3.1设置逆向表显示模板
在空白pdm上右键,选择Display Preferences
选择Modify,设置表格颜色及是否展示注释
设置为默认模板
设置注释及显示顺序
勾选显示code并调整到最上端
设置为默认
3.2 菜单选择,从数据库更新模型
3.3 选择数据库连接配置文件
3.4 选择涉及的数据库和想要导出的表
此处:若想一个库中多中表颜色,可以分多次选择表,但是注意多次选择是,一定要使用全不选再单独勾选,不然会将所有用户的表都反转。
3.5 第一批表反向完成
3.6第二次导入
再次设置模板:保存时会有提示,第一项为:所有的都变为新模板;第二项:选中的改变模板;第三项:新的使用模板
再次导入:
4.批量修改表,展示注释:
4.1Tools下增加一个vbs的脚本
复制脚本执行。即可
vbs文件内容如下(注意需要管理员运行):https://note.youdao.com/ynoteshare1/index.html?id=17edcd38f6d14d5ae5c2402ab28343e2&type=note
4.2 添加表名注释的vbs
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
' get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
' This routine copy name into comment for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
if InStr(tab.comment,tab.code)=0 then
tab.name = tab.code +"("+ tab.comment+")"
tab.comment= tab.name
end if
end if
next
' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
4.3 将注释放置name列中的vbs
'代码二:将Comment中的字符COPY至Name中
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
' get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
Private sub ProcessFolder(folder)
On Error Resume Next
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.name = tab.comment
Dim col ' running column
for each col in tab.columns
if col.comment="" then
else
col.name= col.comment
end if
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name = view.comment
end if
next
' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
结果如下:
变为: