Showing posts with label powerdesigner. Show all posts
Showing posts with label powerdesigner. Show all posts

Wednesday, 5 June 2013

Highlight empty tables in PowerDesigner model with VB Script

The wonderful thing about PowerDesigner automation is that you can actually connect to database from VB Script to get some crucial information that is unavailable (or was not captured) at a reverse engineering phase.
The following script queries Oracle ALL_TABLES system view to find out if table in the model stores any data. Then those tables that are empty are highlighted with thick maroon frame.

Monday, 3 June 2013

Working with PowerDesigner models through VB interface

PowerDesigner has great automation abilities. The easiest way to work with a model programmatically is to use PowerDesigner's embedded Visual Basic script interface and to run scripts through 'Edit/Run script' window.
Here's an example script that uses given color to highlight tables that have comments or that have at least one column with a comment:
Dim model
Set model = ActiveModel
For each table in model.Tables
   doPaint = false
   tableComment = Trim( table.Comment )
   if ( "" <> tableComment ) then
      doPaint = true
   end if

   if ( not doPaint ) then
      For each column in table.Columns
         comment = Trim( column.Comment )
         if ( "" <> comment ) then
            doPaint = true
            Exit For
         end if
      Next   
   end if
   
   if ( doPaint ) then
      For each symbol in table.Symbols
         symbol.BrushStyle = 6 'Gradient 
         symbol.GradientFillMode = 64
         symbol.FillColor = RGB( 252, 178, 104 ) 
         symbol.GradientEndColor = RGB( 255, 255, 255 )
      Next
   end if
Next
More info about PowerDesigner automation at SyBooks and PowerDesigner's 'Metadata Objects' help file.
Tip: when reverse engineering big unfamiliar scheme you can easily select and move apart particular symbols by adjusting their 'Position' property. For example you can select and move tables with particular prefix:
Dim model
Set model = ActiveModel
PREFIX = "hh_"
For each table in model.Tables
   tableName = LCase( Trim( table.Name ) )
   if ( PREFIX = Left( tableName, Len( prefix) ) ) then
      For each symbol in table.Symbols
         symbol.Position = NewPoint( 0, 0 )
      Next
   end if
Next
After desired symbols are moved to the (0,0) position they can be selected and arranged with 'Symbol->Auto layout command'.
This simple solution of how to distill big scheme came to me after I had reversed database with 2K of tables with a few foreign key constants defined. I faced a brick wall of tables arranged by their column count. All semantics were encoded in table names so I just had to set apart tables with equal prefixes. I've searched for a function to add symbols to selection but with no success. So I decided to move desired symbols to the center of workspace and then to select them with single mouse movement. That's when 'Auto layout' command came in very handy.

Thursday, 30 May 2013

An AHK script to select particular tables for reverse engineering in PowerDesigner

The following script helps to select tables (optionally any objects) in the 'Database Reverse Engineering' window of PowerDesigner 15.3 that are stored in txt file.
First one should unmark all objects in the list view, then run the script, hit F5, and after the selection process ends (that can be noticed by stopped blinking of the 'Database Reverse Engineering' window) hit SPACE to mark only selected objects.
Here's the resulting list:

Script uses Acc Library to get the names of items in the ListView and to select them. It should be run under one of the latest releases of AutoHotkey_L.
In my particular case file containing list of objects is called 'tables_to_reverse.txt' (see the script).

Wednesday, 29 May 2013

Reverse engineering Oracle 11gR2 scheme with Sybase PowerDesigner 12.5 on Windows 7 x64

The following setup was made to perform reverse engineering of Oracle 11gR2 scheme into physical diagram using Sybase PowerDesigner 12.5 on Windows 7 x64.
ConnectionType: JDBC
DBMS type: Oracle
User name: <your scheme name>
Password: <your password>
JDBC driver class: oracle.jdbc.driver.OracleDriver
JDBC connection URL: jdbc:oracle:thin:@//<your host>:<your port>/<your service name>
JDBC driver jar files: c:\Oracle\product\11.2.0\client_1\jdbc\lib\ojdbc6.jar
Plus had to install 32-bit Java and add edit path variable in batch file to make PowerDesigner use appropriate VM:
set path=C:\Program Files (x86)\Java\jre7\bin\client\;%path%
cd "c:\Program Files (x86)\Sybase\PowerDesigner 12\"
pdshell12.exe
Many thanks to Devtype blog and Jan Bartos' answer on google groups.