SYS-CON MEDIA Authors: Elizabeth White, Yeshim Deniz, Roger Strukhoff, Jason Bloomberg, Pat Romanski

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
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility. As they do so, IT professionals are also embr...
Industry after industry is under siege as companies embrace digital transformation (DX) to disrupt existing business models and disintermediate their competitor’s customer relationships. But what do we mean by “Digital Transformation”? The coupling of granular, real-time data (e.g., smartphones, connected devices, smart appliances, wearables, mobile commerce, video surveillance) with modern technologies (e.g., cloud native apps, big data architectures, hyper-converged technologies, artificial in...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
CloudEXPO has been the M&A capital for Cloud companies for more than a decade with memorable acquisition news stories which came out of CloudEXPO expo floor. DevOpsSUMMIT New York faculty member Greg Bledsoe shared his views on IBM's Red Hat acquisition live from NASDAQ floor. Acquisition news was announced during CloudEXPO New York which took place November 12-13, 2019 in New York City.
OpsRamp is an enterprise IT operation platform provided by US-based OpsRamp, Inc. It provides SaaS services through support for increasingly complex cloud and hybrid computing environments from system operation to service management. The OpsRamp platform is a SaaS-based, multi-tenant solution that enables enterprise IT organizations and cloud service providers like JBS the flexibility and control they need to manage and monitor today's hybrid, multi-cloud infrastructure, applications, and wor...
The Master of Science in Artificial Intelligence (MSAI) provides a comprehensive framework of theory and practice in the emerging field of AI. The program delivers the foundational knowledge needed to explore both key contextual areas and complex technical applications of AI systems. Curriculum incorporates elements of data science, robotics, and machine learning-enabling you to pursue a holistic and interdisciplinary course of study while preparing for a position in AI research, operations, ...
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
Tapping into blockchain revolution early enough translates into a substantial business competitiveness advantage. Codete comprehensively develops custom, blockchain-based business solutions, founded on the most advanced cryptographic innovations, and striking a balance point between complexity of the technologies used in quickly-changing stack building, business impact, and cost-effectiveness. Codete researches and provides business consultancy in the field of single most thrilling innovative te...
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...
CloudEXPO has been the M&A capital for Cloud companies for more than a decade with memorable acquisition news stories which came out of CloudEXPO expo floor. DevOpsSUMMIT New York faculty member Greg Bledsoe shared his views on IBM's Red Hat acquisition live from NASDAQ floor. Acquisition news was announced during CloudEXPO New York which took place November 12-13, 2019 in New York City. Our Silicon Valley 2019 schedule will showcase 200 keynotes, sessions, general sessions, power panels, and...
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...
ShieldX's CEO and Founder, Ratinder Ahuja, believes that traditional security solutions are not designed to be effective in the cloud. The role of Data Loss Prevention must evolve in order to combat the challenges of changing infrastructure associated with modernized cloud environments. Ratinder will call out the notion that security processes and controls must be equally dynamic and able to adapt for the cloud. Utilizing four key factors of automation, enterprises can remediate issues and impro...
Intel is an American multinational corporation and technology company headquartered in Santa Clara, California, in the Silicon Valley. It is the world's second largest and second highest valued semiconductor chip maker based on revenue after being overtaken by Samsung, and is the inventor of the x86 series of microprocessors, the processors found in most personal computers (PCs). Intel supplies processors for computer system manufacturers such as Apple, Lenovo, HP, and Dell. Intel also manufactu...
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 wait for long development cycles that produce software that is obsolete at launch. DevOps may be disruptive, but it is essential. DevOpsSUMMIT at CloudEXPO expands the DevOps community, enable a wide sharing of knowledge, and educate delegates and technology providers alike.