Toad World® Forums

How can I call a function from a package script during model conversion


#1

I want to do the following with Toad Data Modeler 6.5.5.6

I have defined a package containing a function within a script.
I would like to execute this function sometime during the conversion of a model (f.g. MySQL) to another model (f.g. PostgreSQL).

How can that be achieved?

Thanks


#2

Hello Albert,
run custom function is possible by macro call or by override some object in TDM. If you use macro it is more simple, but you need call your function manually (from popup menu of model or similar).
If you want use second way at first you need to find good class to override. In your case it is “Convertor Rule” of model. Bellow I describe more detailed how to do it.

  1. Create Custom Package that will have Extension to “Database MySQL” and “Database PostgreSQL”
    image

image

  1. Open Package Explorer and find this package and open its metamodel
    image

  2. Create new class in metamodel and set
    Name - “ConvertorRulePERModelMYPG”
    Caption - “ConvertorRulePERModelMYPG”
    Object Type - 26016

  3. Create New Method in this class and call it “AfterConvertNodeExtended”, this method must have one Dispatch parameter Node and it is without result type.
    image
    image

  4. Click On Edit Script button in method Properties. This create script with method that will be called instead default “AfterConvertNodeExtended” (This method is by default empty). To this script method you can write your code or call another function from your package (ScriptName.MethodName)

  5. Save All and close TDM

  6. Open your package in some xml editor (I use XMLEditPro) and create definition of convertor rule in this package
    image
    ConvertorRuleModelMYPG node contains three attributes, that correspond with metamodel class
    CSAOName - ConvertorRulePERModelMYPG
    CSAOCaption - ConvertorRulePERModelMYPG
    ObjectType - 26016

ID - some unique GUID
Name - 2001(PERModel) <> 2001(PERModel)
Model1PropertyName, Model2PropertyName - leave empty becouse it is root object model
CanConvert - 1
CanAlter - 0
All AddSurroundigs nodes - 0
AfterConvertExternal - 1
Model1Package/ID - {5CEFC82A-2D9A-48C4-9369-F0F9CC4D10BB}
Model2Package/ID - {3024A445-2DF4-4946-8F66-7E165D07D973}
Last two values are ids form package from Database MySQL and Database PostgreSQL.

I attached sample package it should write message “Test” to message explorer after convert model.
Package is written in TDM 6.5.
Becouse at this time it is not possible attached zip file, so I changed extension from zip to txt, please change it back after download.ConvertMYPG.zip.txt (1.3 KB)

Daril