Chat now with support
Chat with Support

Toad Data Modeler 7.0 - User Guide

Introduction User Interface Models and Model Objects
Physical Data Model
Entity Relationship Diagram Objects Basic Database Design Advanced Database Design
Universal Data Model Logical Data Model Working with Model Objects
Features and Tools
Application Variables Export/Import DDL Script Generation Graphics Model Actions Print Create New Project Reports Reverse Engineering Scripting and Customization About Templates Tips and Tricks Toad for Oracle Integration Toad Intelligence Central (TIC) Integration Tools Version Control
Options and Configuration Databases
Amazon Redshift 1.0 IBM DB2 LUW 9.5 IBM DB2 LUW 9.7 IBM DB2 LUW 10.1 IBM DB2 LUW 10.5 IBM DB2 LUW 11.1 IBM DB2 z/OS 10 IBM DB2 z/OS 11 Greenplum 4.1 Greenplum 4.2 Ingres 9.3 Ingres 10.0 EDB Postgres Advanced Server 10 Microsoft Access 2007/2010 Microsoft Azure SQL Database V12 Microsoft SQL Server 2005 Microsoft SQL Server 2008 Microsoft SQL Server 2012 Microsoft SQL Server 2014 Microsoft SQL Server 2016 Microsoft SQL Server 2017 MySQL 5.0 MySQL 5.1 MySQL 5.5 MySQL 5.6 MySQL 5.7 MySQL 8.0 Oracle 10g Oracle 11g Release 1 Oracle 11g Release 2 Oracle 12c Release 1 Oracle 12c Release 2 Oracle 18c Specifics - Oracle 12c Release 2 PostgreSQL 9.0 PostgreSQL 9.1 PostgreSQL 9.2 PostgreSQL 9.3 PostgreSQL 9.4 PostgreSQL 9.5 PostgreSQL 10 SQLite 3.7 Sybase ASE 15.5 Sybase ASE 15.7 SAP ASE 16.0 Sybase IQ 15.2 Sybase SQL Anywhere 11 SAP SQL Anywhere 17 Teradata 13 Vertica Database 8.0
Copyright Legal Notices

Iterate Entity And Attributes

This sample shows you how to iterate entities and attributes and how to recognize PK, PFK or FK attributes.

function main()

{

var app = System.GetInterface('Application');

var Model = app.Models.GetObject(0); // gets first model in application

var e, a, iterEntity, iterAttribute;

Model.Lock();

for (e=0; e<Model.Entities.Count; e++) // iterate entities

{

iterEntity = Model.Entities.GetObject(e);

iterEntity.Lock();

for (a=0; a<iterEntity.Attributes.Count; a++) // iterate attributes

{

iterAttribute = iterEntity.Attributes.GetObject(a);

if(iterAttribute.IsPrimaryKey == 1) // check if attribute is PK

{

if(iterAttribute.FKForeignKeys.Count !=0)

Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-PFK');

else

Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-PK');

}

else

{

if(iterAttribute.FKForeignKeys.Count !=0)

Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-FK');

}

}

iterEntity.UnLock();

}

Model.UnLock();

Model.RefreshModel();

}

Call Existing Script from Model Properties Form

Edit the Model Properties form. See the "Modify Form" topic to find out how to edit existing form.

Add there a new button and remember the name of the form - FmPERModelEdit. The name can be found in the Form Explorer.

Defined caption for the button - Write Customer Feedback To Log.

Set the name of the button to FeedbackButton.

Create a new script with the name of the Model Properties form - FmPERModelEdit.

Write event function to the script.

Code

function FeedbackButtonOnClick()

{

  WriteFeedbackToLog.WriteFeedback()

}

Explanation

  • FeedbackButton = name of the button.
  • OnClick = event.
  • WriteFeedbackToLog = name of script that contains called function.
  • WriteFeedback = called function.

When you click the button, an output will be displayed in Message Explorer (Log).

For more information, see Modify HTML Reports.

Modify HTML Reports

To modify HTML reports, we need to extend existing method. The first thing we need to do is to find out what script should be extended.

In Script Explorer, you can see BasicHTMLPERReportOR script with function ReportTableUserProperties. This is the script that generates Tables pages in HTML reports, specifically the section Table Properties.

You can also see script BasicHTMLPERReportOR10 that extends the BasicHTMLPERReportOR script.

Now we now need to write a script that will extend the ReportTableUserProperties function defined in the BasicHTMLPERReportOR script.

For that purpose, we need to open our CustomerFeedback metamodel and the method there.

Open the CustomerFeedback metamodel, add there a new class (see the Class icon in the toolbar), edit the class and set the name to BasicHTMLPERReportOR10. (One extension of that class already exists, in our metamodel we will create another extension of the class).

Define Object Type (the value can be currently found out in metamodel to HTML report for Oracle 10g package).

Add the ReportTableUserProperties method to the class.

Add two new parameters to the method. (The method name and number of parameters must be identical to the original method - see the first screenshot).

Return back to the General tab. Click Reload. Script name and method name will appear there. Add a prefix My to it (this will be changed in future, no manual modification will be required).

Click Edit Script.

Click OK and define code for the ReportTableUserProperties method that extends the existing method of the same name.

Code:

function ReportTableUserProperties(Document, Entity)

{  

  // Table definition

  Table = Document.CreateTable(false,true);

  Table.CreateColumn(20);

  Table.CreateColumn(80);

  var row = -1;

 

  if (Entity.ConfirmedByCustomer == true)

  {

    Table.CreateCell( ++row,0,'Confirmed' );

    Table.CreateCell( row,1,'Yes' );

  }

  else if (Entity.ConfirmedByCustomer == false)

  {

    Table.CreateCell( ++row,0,'Confirmed' );

    Table.CreateCell( row,1,'No' );

  }

  else

  {

    Table.CreateCell( ++row,0,'Confirmed' );

    Table.CreateCell( row,1,'Undefined' );

  }

 

  if (Entity.NotesFromCustomer.length > 0)

  {

    Table.CreateCell( ++row,0,'Notes from Customer' );

    Table.CreateCell( row,1, Entity.NotesFromCustomer );

  }

 

  if (row > -1)

  {

    Document.WriteStyled( 'CAPTION2', 'Customer Feedback' );

    Table.Draw();

    Table.Close();

  }        

 

  Instance.ReportTableUserProperties(Document, Entity);

 

 

};

Explanation

Table.CreateColumn(20) - the CreateColumn function belongs to the HTMLReportTable class. All functions related to the Table object can be found in the Toad Data Modeler Reference.

Entity.ConfirmedByCustomer - represents the variable we added earlier to the CustomerFeedback metamodel.

Entity.NotesFromCustomer.length - standard JavaScript function that returns number of characters of the NotesFromCustomer string.

Document.WriteStyled - represents function that belongs to the HTMLDocument class.

Instance.ReportTableUserProperties(Document, Entity);

  • Instance - using the Instance keyword, we can call existing function we extended. We could copy and paste the content of the ReportTableUserProperties function defined in the BasicHTMLPERReportOR script. However, if a change was made to the script later, we would have to update our script too, which would be difficult to maintain. That's why it's better to write code that will extend the existing functionality only, and call the rest from existing script via the Instance keyword.
  • ReportTableUserProperties - represents existing function we call.

When you generate HTML reports now, you will see the following output. New section Customer Feedback is generated on top, followed by the Table Properties part, as originally defined in the ReportTableUserProperties function in script BasicHTMLPERReportOR.

Customize Forms and Frames

Toad Data Modeler allows you to edit some forms and frames for more comfortable work.

What Is Editable Form?

It is a form of which appearance you can edit to meet your needs and requirements. You can add, change components and delete user components (those you created).

How Do I know the Form is Editable?

Right-click the form to see the pop-up menu. If there's the Customize Form (as) option, the form is editable.

Example: The Entity Properties form

What Is Editable Frame?

Properties of editable frames are similar to properties of editable forms, however frame represents only a part of a form, not  complete form. E.g. the Options form has editable frames Application, Graphics etc.

What Is Editable Form for?

To customize appearance and functionality of forms to suit your needs, e.g. you want to have different options for different database types.

If you model your own property in metamodel, you will probably want to visualize it somehow (write out its value to edit etc.) Therefore it's necessary to edit appropriate form and insert to it a new component to which you will assign appropriate property then. Also, to inserted components, you can add values by scripting.

To edit a form

Right-click the form and select Customize Form or CustomizeForm as.

Customize Form

The changes will be saved to your user package My Package.

Customize Form as

The changes will be saved to another package than My Package. This option is disabled by default. To enable it, select Settings | Options | Expert Mode and uncheck the Save the definitions to the My Package checkbox.

Forms can be edited via the following tools :

  • Component Inspector - list of properties of selected component in the form. Here, you can edit properties
  • Component Palette  - list of components that you can add to a form
  • Form Explorer - tree structure of the edited form
  • Alignment - alignment options

Forms of these three tools can be docked in Toad Data Modeler environment  at your convenience.

If you want to hide/show any of these tools permanently, you can clear/select appropriate option in:

  • Right-click the form and select Designer Mode Options.
  • From the Settings menu, select Options | Editable Forms.

Example: The Entity Properties form that is being edited now.

 

To finish editing a form

Close the form that you have just edited (click x in the right-hand corner, e.g. in the Entity Properties form).

After you close the edited form, you need to save the changes to package.

Note: You will not finish editing the form by closing any of the tool forms (Inspector, Explorer or Palette Component). If you close any of them, the Show option for the tool (Show Inspector, Show Explorer...) will be automatically cleared. If you edit a form next time, the form of this tool will not display. To display it again, you need to enable the Show option either in the Designer Mode Options or in the Settings menu | Options | Editable Forms.

 

To save the changes

  1. Right-click the form and select Save Form or Save Form to.

The changes will be saved to appropriate packages, however to preserve them even after you close the application, you have to save also the packages.

  1. Save the packages in Package Explorer.

Changes will be saved either to actual package, or user package (according to the settings in the Settings menu | Options | Paths).

If you want to save the changes to another package, you have to start the edit process with option Edit Form as, then select the package and finally click Save Form to to save the changes.

Editable Forms Right-Click Options

Right-click the form to see the following options:

Option Description

Customize Form

Edits a form. All changes will be stored to My Package user package (file My Package.txg).

Customize Form as

Edits a form in a state according to the selected package. (Only the components that are saved in the selected package and its child packages will be available.)

This option is available only if checkbox Save the Definitions to the 'My Package' is clear. - See the checkbox in the Settings menu | Options | Expert Mode.

Load Form

Reloads a form.

Save Form

Saves changes in the default package (see the Settings menu).

Save Form to

Saves changes to previously selected package (see Edit Form as).

Designer Mode Options

Here, you can hide/show the tools for next form edit.

Default Values of Object

Opens the dialog where you can define or edit default values of appropriate form/dialog/frame.

Related Documents