通过 COM 访问 PowerDesigner 存储库模型
Accessing PowerDesigner Repository Models via COM
我一直在尝试使用 COM API 直接从 PowerDesigner 存储库获取实时模型,但没有成功。这是我在 VBA 中尝试过的内容:
Set pd = CreateObject("PowerDesigner.Application")
Set conn = pd.RepositoryConnection
conn.Open "", "", "ShhMahPW"
Set model = conn.FindChildByPath("Program/Project/Logical Models/MahLOM", PdOOM_Classes.cls_Model)
MsgBox model.ShortDescription 'This fails because model is null!
同样,我一直在使用 Java COM 桥在 Eclipse 中尝试同样的事情:
Application pd = this.getApplicationHook();
//Make live connection to proxy repository
RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
conn.Open( "", "", ConnectionParams.PASSWORD );
BaseObject model = conn.FindChildByPath( "Program/Project/Logical Models/MahLOM",
PdOOM_Classes.cls_Model );
//Null model, COMException: "Action can not be performed. result = -2147467259"
System.out.println( model.GetShortDescription() )
有人可以建议一种深入存储库的好方法吗?我已经能够确认我与存储库有连接,然后在该顶层列出 children。我正在努力深入研究根级别以外的文件夹。谢谢!
我知道我要从存储库中提取的模型已经存在于我的本地工作区中。实际上,这是对本地工作空间模型的更新。要执行此操作,可以使用方法 UpdateFromRepository()
!
那么我能做的就是获取本地 PowerDesigner 模型的句柄,然后在检索子项之前调用更新。请注意从 BaseObject
到 BaseModel
的转换是为了刷新...
private BaseObject getModel(){
Application pd = this.getApplicationHook();
model = pd.OpenModel(this.basePath + this.modelName);
System.out.println( "Retrieving model updates from repository... ");
RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
conn.Open( "", "", ConnectionParams.PASSWORD);
boolean success = new BaseModel(model).UpdateFromRepository();
if( success )
System.out.println( "Update successful!" );
else
System.out.println( "Update failed. Check PowerDesigner settings." );
return this.model;
}
您的主要问题是搜索 ChildKind
应该是 Cls_RepositoryModel
,而不是 PdOOM_Class.cls_Model
。
option explicit
' assuming we're already connected
if RepositoryConnection.Connected then
Descent RepositoryConnection,""
end if
dim c
set c = RepositoryConnection.FindChildByPath("Folder_7/ConceptualDataModel_1", Cls_RepositoryModel)
if not c is nothing then
output "*** found object " & c.classname
end if
sub Descent(obj,ofs)
output ofs & obj.name & " - " & obj.ObjectType & " - " & obj.ClassName
if obj.ObjectType = "RepositoryModel" then exit sub
if obj.PermanentID = 3 then exit sub ' to save time, don't enter Library
if not obj.HasCollection("ChildObjects") then exit sub
dim c
for each c in obj.ChildObjects
Descent c,ofs & " "
next
end sub
我一直在尝试使用 COM API 直接从 PowerDesigner 存储库获取实时模型,但没有成功。这是我在 VBA 中尝试过的内容:
Set pd = CreateObject("PowerDesigner.Application")
Set conn = pd.RepositoryConnection
conn.Open "", "", "ShhMahPW"
Set model = conn.FindChildByPath("Program/Project/Logical Models/MahLOM", PdOOM_Classes.cls_Model)
MsgBox model.ShortDescription 'This fails because model is null!
同样,我一直在使用 Java COM 桥在 Eclipse 中尝试同样的事情:
Application pd = this.getApplicationHook();
//Make live connection to proxy repository
RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
conn.Open( "", "", ConnectionParams.PASSWORD );
BaseObject model = conn.FindChildByPath( "Program/Project/Logical Models/MahLOM",
PdOOM_Classes.cls_Model );
//Null model, COMException: "Action can not be performed. result = -2147467259"
System.out.println( model.GetShortDescription() )
有人可以建议一种深入存储库的好方法吗?我已经能够确认我与存储库有连接,然后在该顶层列出 children。我正在努力深入研究根级别以外的文件夹。谢谢!
我知道我要从存储库中提取的模型已经存在于我的本地工作区中。实际上,这是对本地工作空间模型的更新。要执行此操作,可以使用方法 UpdateFromRepository()
!
那么我能做的就是获取本地 PowerDesigner 模型的句柄,然后在检索子项之前调用更新。请注意从 BaseObject
到 BaseModel
的转换是为了刷新...
private BaseObject getModel(){
Application pd = this.getApplicationHook();
model = pd.OpenModel(this.basePath + this.modelName);
System.out.println( "Retrieving model updates from repository... ");
RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
conn.Open( "", "", ConnectionParams.PASSWORD);
boolean success = new BaseModel(model).UpdateFromRepository();
if( success )
System.out.println( "Update successful!" );
else
System.out.println( "Update failed. Check PowerDesigner settings." );
return this.model;
}
您的主要问题是搜索 ChildKind
应该是 Cls_RepositoryModel
,而不是 PdOOM_Class.cls_Model
。
option explicit
' assuming we're already connected
if RepositoryConnection.Connected then
Descent RepositoryConnection,""
end if
dim c
set c = RepositoryConnection.FindChildByPath("Folder_7/ConceptualDataModel_1", Cls_RepositoryModel)
if not c is nothing then
output "*** found object " & c.classname
end if
sub Descent(obj,ofs)
output ofs & obj.name & " - " & obj.ObjectType & " - " & obj.ClassName
if obj.ObjectType = "RepositoryModel" then exit sub
if obj.PermanentID = 3 then exit sub ' to save time, don't enter Library
if not obj.HasCollection("ChildObjects") then exit sub
dim c
for each c in obj.ChildObjects
Descent c,ofs & " "
next
end sub