Welcome!

Blog Feed Post

Refactoring PowerBuilder code with the PowerDesigner plug-in

Here’s a trivia question for you… How long ago did Sybase release the PowerDesigner Plug-in for PowerBuilder?

Your answer would probably be, “What the heck is the PowerDesigner Plug-in for PowerBuilder???”  It is, arguably, the least-discussed feature of both PB and PD, and yet, with the release of PB12.NET, it could become the most important tool in your PB toolkit.  As developers look to migrate their existing (and often, aging) PB applications to PB12.Net and Windows Presentation Foundation (WPF), they may encounter the need for some level of refactoring.  It may be necessary to “flatten” the object hierarchy by consolidating classes, or to better isolate the presentation layer (View) from the business logic (Controller) and the data access layer (Model).  My colleague Yakov Werde has published a number of great articles and videos on the ups and downs of PowerBuilder migrations.  You can find them all here.

As long time PB developers know, this type of work is never fun, due to some basic restrictions built into the PB IDE itself.   For example, since PB always opens objects in “edit” mode, it cannot allow an ancestor class and one of its descendent classes to be open in the painter simultaneously.  The refactoring process becomes a tedious and error-prone cycle of opening the descendent, copying code to the clipboard, closing the descendent, opening the ancestor, pasting in the code, closing…  Oh, and don’t forget that the Classic PB requires an object to compile cleanly before it allows a save.  And some tasks, like altering an object’s ancestry, can’t be done in the painter at all!  These require the developer to resort to the “Edit Source” option, working directly with the PB source code!  Not a task for the faint of heart (or the newbie)…

 

Most PowerBuilder developers are probably familiar with PowerDesigner and it’s industry-leading Data Modeling capabilities, and perhaps they even use it to generate a Data Dictionary for their relational database.  But PowerDesigner has a depth and breadth far beyond basic data modeling that many are just not aware of…  One of the primary features of the Developer edition of PD is the Object Oriented Modeling (OOM) tool.  The OOM has the ability to reverse-engineer code modules into a UML compliant Class Diagram.  It actually reads and parses the code, and generates all the UML artifacts into a PD model!  Once the code is reversed into a Class Diagram, the developer can work with the model in a graphical drag-and-drop UI, and then forward-engineer the changes back into the code.  PD can read and write a number of languages, including Java, Visual Basic, C, C++, C#, and (wait for it…), PowerBuilder!    PowerDesigner can directly update the PowerScript inside PB Classic PBLs!

 

Let’s get started with a simple demo using the Examples app that ships with PB 12 Classic, and PD 15.2. One note: the PD plug-in is a free component, but you do have to have PowerDesigner (Developer or Studio editions) installed to get it.

The first step (after both PB and PD are installed) is to enable the plug-in inside the PowerBuilder IDE.  Open PB, and select Tools > Plug-in Manager… This opens the dialog shown in Figure 1.  Simply check PowerDesigner on and click OK.

Plug-in Manager dialog

Three new panels will appear in the IDE – the Class Browser and two “output” panels.  Since these take up valuable screen real estate, I typically close the output panels and just leave the Object Browser visible.  The output panels will automatically reappear when needed, so just close those for now.

 PB IDE with PD Plug-in activated

The next step is to reverse-engineer the PowerBuilder code into an Object Oriented Model.  The plug-in will add three new menu options to the Target context menu.  Right-click on the Target and select Reverse Engineer.

Plug-in menu items

This brings up a dialog that shows a treeview containing all the PBLs in the current target, and all the objects in each PBL.  This lets you select the PBLs or individual objects that need to be reverse-engineered.  Typically, one would reverse the entire target, but hundreds of classes can result in quite a messy diagram.  If you know you’ll be working with a distinct subset of the target, deselect anything that isn’t required.  Click OK to initiate the reverse-engineering process, and then go get a cup of coffee (or maybe even grab lunch?).  The process can take several minutes, depending upon the number of objects being reversed, and the number of object references that are detected.

Reverse Engineer dialog

 

When the process finishes, there are two important steps that must be completed to “finalize” the linkage between the model and the PB target.

  1. Save the OO Model to a .OOM file.  Right-click the second node in the PD Object Browser (the one just below the topmost “Workspace” node) and select Save As…  to save the .OOM file into a folder somewhere.  
  2.  Now go back to the PB System Tree and right-click on the Target node (again, not the Workspace node).  Select Plug-in Attributes… to open the dialog window shown below.  Set the oompath attribute to the full path/filename of the .OOM file that was just created.  Click OK to close this dialog.

 Plug-in Properties dialog

You should immediately notice a couple of changes to the IDE:

  • The PD Object Browser pane will be populated with a set of folders, one for each PBL in the target.
  • Expanding a PBL node will display a set of subfolders:
    • Classes:  This folder contains the shortcut to the object in the PBL, including PB system classes like checkbox, radiobutton, datawindow, etc.  This is just like the PB System Tree.
    • Associations:  This list shows the relationships between any object in the PBL and any other object it references, like controls or user objects on a window.
    • Generalizations:  This folder contains an entry for every inheritance relationship, from a child to its parent.  For example, since w_about_system is a direct descendent of w_center, then in OO terms, w_about_system is a generalization of w_center.
    • Dependencies: For PB applications, Dependencies are very much like Associations, but you’ll also see “influent objects” listed here.  For example, w_add_sales_order has 6 commandbuttons and 2 datawindows, so those 8 entries are Associations.  The PB system classes “commandbutton” and “datawindow” are both “influent object dependencies”.
    • You’ll also see an entry called “ClassDiagram_1″.  This is the graphical representation of all the entries in the four folders listed above, for that specific PBL. 

You’ll also see a new menu item in the PB system tree context menu – Find in Class Diagram.  Choosing this item will open the OOM class diagram and select the class.  Double-clicking a class in the PD diagram opens the object in the corresponding PowerBuilder painter.  You now have the full depth and breadth of PowerDesigner’s Object Oriented Modeling tool at your disposal.  Attempting to define all that functionality is clearly beyond the scope of this blog post (and probably would fill a book). 

You have a full cross-reference of object classes and system classes, ancestry and descendent lineages, as well as the ability to view methods and event scripts!   However, it’s important to remember that PowerDesigner is a software MODELING tool, NOT a software DEVELOPMENT tool like PowerBuilder.  PD doesn’t allow you to compile code, check syntax, or deploy targets.  And even though the integration between the model and the code is bi-directional, it’s not automatic.  Changes made in one side are not automatically visible in the other. 

  • To move a change from the model into the code, select Language > Generate PowerBuilder… from the PD menu. 
  • To move a change from the code into the model, select Reverse Engineer… from the PB target context menu.

Let’s walk through a simple example.  We’re going to change the ancestor of a window class and generate that change into PB.  To do this in PB would require use of the Edit Source option, and a knowledge of the internal syntax of the PowerScript code that is usually hidden from the developer’s view.  In PD, it’s a simple drag and drop!

  1. In the PD browser, find the w_main class.  It lives in the pbexamfe PBL. Right-click it and select Find in Diagram…
  2. Press F7 to zoom out a bit, because you’ll need to see both w_main and w_center on the screen at the same time.  w_center is in the same PBL, so it exists in the same diagram.
  3. Select the Generalization tool from the PD toolbar (it’s the one that looks sort of like an organization chart).  Then click on w_main and drag the arrow over to drop it on w_center.  That class is now the ancestor of w_main!
  4. * An alternative method is to use the Properties dialog, as shown below.  When you first open the properties for w_main, you’ll see that the “Extends” property reads <None>.  Click the button immediately to the right of that field (Select Classifier), then select w_center in the list of window classes.  This has the same effect as dragging and dropping a Generalization link.

Class Properties dialog

 

To generate the code back into the PBLs, select Language > Generate PowerBuilder…  The dialog shown below is presented, which allows you to select or de-select objects.  You can also have PD save a backup copy of any changed PBLs at this time.  Since I knew that I’d only changed one object, I deselected everything except w_main.  Click OK to start the generation process.  Note: even if you only change a single object, PB will still initiate an incremental build on the target.

 

Generate PowerBuilder dialog

 

If you now open w_main in the PB editor, you’ll see that it shows as being descended from w_center.  A simple example, I know, but think of how easy this would make the process of adding a “corporate” layer between the existing framework layers in a PFC-based application!   You’d create new empty classes with the PFD_ prefix, create a generalization from those to their corresponding PFC_ layer components, then change the PFE_ components’ ancestry by dropping their existing generalizations from the PFC_ to the PFD_ layer.   

To refactor a method or event script from one class to another, it’s as simple as dragging and dropping the operation definition from one classes’ Operations folder to another.  That single step brings over the method signature, the parameters, as well as all the PowerScript!  Once all the refactoring work is done and tested on the “Classic” side, the migration to PB12.Net and the Visual Studio Isolated Shell will proceed much more smoothly.

 

In summary, PowerDesigner and the PD Plug-in for PowerBuilder can be a fantastic addition to your PB tools arsenal, especially if you’re considering a migration to PB12.Net.

 

Enjoy!
-Paul-

Read the original blog entry...

More Stories By Paul Horan

Paul Horan is a Senior Solution Advisor and Mobility Architect at SAP, and works with the SAP Mobile Platform and SAP Mobile Secure product lines. Paul joined SAP as part of their acquisition of Sybase in June, 2010. Prior to that, Paul worked for Sybase as a technical pre-sales architect supporting PowerBuilder, PowerDesigner, and SQL Anywhere. Paul works out of SAP's Reston VA office. A 1984 graduate of Indiana University, Paul currently resides in Arlington VA.

Latest Stories
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
"NetApp's vision is how we help organizations manage data - delivering the right data in the right place, in the right time, to the people who need it, and doing it agnostic to what the platform is," explained Josh Atwell, Developer Advocate for NetApp, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
What You Need to Know You know you need the cloud, but you’re hesitant to simply dump everything at Amazon since you know that not all workloads are suitable for cloud. You know that you want the kind of ease of use and scalability that you get with public cloud, but your applications are architected in a way that makes the public cloud a non-starter. You’re looking at private cloud solutions based on hyperconverged infrastructure, but you’re concerned with the limits inherent in those technolog...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
One of the biggest challenges with adopting a DevOps mentality is: new applications are easily adapted to cloud-native, microservice-based, or containerized architectures - they can be built for them - but old applications need complex refactoring. On the other hand, these new technologies can require relearning or adapting new, oftentimes more complex, methodologies and tools to be ready for production. In his general session at @DevOpsSummit at 20th Cloud Expo, Chris Brown, Solutions Marketi...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
Most of the time there is a lot of work involved to move to the cloud, and most of that isn't really related to AWS or Azure or Google Cloud. Before we talk about public cloud vendors and DevOps tools, there are usually several technical and non-technical challenges that are connected to it and that every company needs to solve to move to the cloud. In his session at 21st Cloud Expo, Stefano Bellasio, CEO and founder of Cloud Academy Inc., will discuss what the tools, disciplines, and cultural...
Why Federal cloud? What is in Federal Clouds and integrations? This session will identify the process and the FedRAMP initiative. But is it sufficient? What is the remedy for keeping abreast of cutting-edge technology? In his session at 21st Cloud Expo, Rasananda Behera will examine the proposed solutions: Private or public or hybrid cloud Responsible governing bodies How can we accomplish?
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
DevOps at Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to w...
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
With the rise of DevOps, containers are at the brink of becoming a pervasive technology in Enterprise IT to accelerate application delivery for the business. When it comes to adopting containers in the enterprise, security is the highest adoption barrier. Is your organization ready to address the security risks with containers for your DevOps environment? In his session at @DevOpsSummit at 21st Cloud Expo, Chris Van Tuin, Chief Technologist, NA West at Red Hat, will discuss: The top security r...
There is huge complexity in implementing a successful digital business that requires efficient on-premise and cloud back-end infrastructure, IT and Internet of Things (IoT) data, analytics, Machine Learning, Artificial Intelligence (AI) and Digital Applications. In the data center alone, there are physical and virtual infrastructures, multiple operating systems, multiple applications and new and emerging business and technological paradigms such as cloud computing and XaaS. And then there are pe...
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.