Generate DDL from ER model using Open API

tomcat-thumbVisual Paradigm’s Open API is a powerful tool which allow user to extend the functionalities of Visual Paradigm software. With Open API you can generate DDL from ER models in your project. The generation of DDL include 4 major steps and this article will explain to you in details. To generate DDL with Open API:

  1. Retrieve your current opening project. You can make use of the ProjectManager to obtain your current opening project.
    // retrieve current opening project
    IProject project = ApplicationManager.instance().getProjectManager().getProject();
  2. Obtain the DatabaseManager from ApplicationManager.
    // obtain DatabaseManager form ApplicationManager
    DatabaseManager dm = ApplicationManager.instance().getDatabaseManager();
  3. Collect an array of entity model. You can collect it directly from project or under specific model element (as its child). In our example we retrieve all entity models directly from project.
    // obtain all entities (DB Table) from project
    IModelElement[] entities = project.toModelElementArray(IModelElementFactory.MODEL_TYPE_DB_TABLE);
  4. Finally we call the DatabaseManager to generate SQL for the selected entity model. In our example we generate DDL based on MySQL 5.0.5 or higher version. You can find the full list of supported database in the DatabaseType class.
    // call DatabaseManager to generate DDL
    String ddl = dm.generateCreateSQL(DatabaseType.MySQL_505, entities);

Remarks

* The DatabaseType you specified to DatabaseManager.generateCreateSQL() must be one of the database you selected in the project. Details about specifying project database can be found at Database Configuration section in Visual Paradigm User’s Guide.

Sample Plugin

The sample plugin attached in the article demonstrate how to generate DDL from the entity models in your project. After you deploy the plugin into Visual Paradigm you can then click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Trigger sample plugin

And then the DDL will be output to the Message Pane.

DDL being output to Message Pane

DDL being output to Message Pane

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Links

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply