Comments
bruce.armstrong wrote: Somebody just said it better than I did, and with more chops to say it: Open Letter to Mark Zuckerberg, Sheryl Sandberg & Facebook Mobile
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


SnapShot
SnapShot

I recently had the opportunity to rewrite one of our major data entry systems. This system processes payments on a monthly basis, either individually or submitted as a group under an administration company - rather like companies that have a third party handle their payroll.

The Problem
In some cases these group submissions run into thousands of individual payments that can take even the best data entry person a week or better to enter. In the past the problem was addressed either by leaving the workstation running with the payment in flight or saving an incomplete and unbalanced set of payments for later edits and corrections.

Neither of these solutions really solved the problem and on more than one occasion several days of work were lost due to a system outage or power failure. In addition, I wanted to create a system that wouldn't allow an out-of-balance payment to be saved to the database as these were particularly hard to ferret out under the old system. That, of course, eliminated the option of storing an incomplete payment entry for later.

What I needed was a way to take a "SnapShot" of the payment entry window that could be used at a later time to restore the window and allow an in-flight payment entry to be resumed.

The Solution
Fortunately, PowerBuilder's DataWindow provided the ideal tool to solve this problem. The GetFullState() DataWindow function is usually used in distributed processing. According to the PowerBuilder Help description, GetFullState() "retrieves the complete state of a DataWindow or DataStore as a BLOB". A BLOB (Binary Large Object) is a data type that can hold an unbounded amount of raw binary data. The counterpart to GetFullState() is the SetFullState() function that's used to restore a DataWindow (or DataStore) to the state that existed by applying the information stored in a BLOB created by GetFullState().

GetFullState() creates the BLOB with the DataWindow object specification, the contents of the four data buffers (Original, Primary, Filter, and Delete), and the status flags used by PowerBuilder to control the operation of the DataWindow. Since most of the data that I would need to restore is contained in either a DataWindow or a DataStore, these two functions make it easy to re-create those controls. The only remaining values that I would need to restore are any instance variables used in the window. These will be stored in the same location as the GetFullState() BLOBs.

Storage
The next piece of the puzzle is where to store this information so it can be used to reconstruct the DataWindow or DataStore sometime in the future. My first use of the BLOB data type was in a different application that actually stored the contents of the PBD files for the app on the database. These BLOBs were then downloaded to the system workstation whenever a new version was detected. Not much different from what I wanted to do here. For those who are interested, I described that system in a previous article, "Automating Your Software Installation and Updates" (PBDJ, Vol. 4, issue 12).

For Adaptive Server Enterprise the Image data type can be used to store BLOB information up to a maximum of 2,147,483,647 bytes of information.

Oracle has the Long Raw data type and Adaptive Server Anywhere uses Long Binary. One major difference between Sybase and Oracle is that Oracle limits the number of Long Raw data type columns to one per table. Sybase allows multiple columns to use the Image data type. All things considered, the Sybase capability makes it much easier to associate multiple BLOBs that will result from a SnapShot.

It's important to note that the columns that are defined to hold BLOB data cannot be accessed using normal SQL commands. The UPDATEBLOB and SELECTBLOB SQL statements take care of all data access. There's no INSERTBLOB statement. A SQL INSERT has to be used to create the row with the non-BLOB columns first, followed by the UPDATEBLOB.

The SnapShot Table
I first created a table with the columns in place that I would need to identify the ownership of a particular SnapShot. This will vary from application to application - however my system required the items shown in Table 1.

I then created columns to hold each of the instance variables in the Payment Entry Window. As this was a very complex system, I won't repeat every variable here - just a few:

Federal_id varchar(9) null
Payment_date smalldatetime null

I chose to allow null values here so that a SnapShot could be taken at any stage of the payment-entry process.

I finished up by defining image columns for each of the DataWindow/DataStores that I needed to reconstruct during the SnapShot Restore process. These I identified by the control name used in the window.

Dw_payor_information image null
Dw_payment_header image null
Dw_payment_detail image null

The Window Open Event
So far so good. Now I'll add the mechanism to the window that will allow me to take the SnapShot. Because I want the database activity for the SnapShots to be independent from the rest of the window activity, I need to define a transaction object strictly for SnapShot activity.

First the instance variable for the transaction object:

Transaction    itr_snapshot

in the open event for the window:

Itr_snapshot = CREATE transaction

itr_snapshot.DBMS = "SYC Sybase
System 10/11"
itr_snapshot.Database =
SQLCA.Database
itr_snapshot.LogPass = SQLCA.LogPass
itr_snapshot.ServerName =
SQLCA.ServerName
itr_snapshot.LogId = SQLCA.LogId
itr_snapshot.DBParm = "Release='11'"

and in the close event:

IF IsValid(itr_snapshot) THEN
DESTROY itr_snapshot
END IF
I set up the payor_payment_snapshot table on the same database that the application uses to store payment information. Under different circumstances the independent snapshot transaction object would allow me to use a different database if that was desirable.

Accessing the SnapShot Table
To update the non-BLOB columns of the table I need to create a DataStore capable of updating the fields in question. In my application this is ids_snapshot using dataobject "d_"windowname"_snapshot.

I use a window-defined function to actually "take" the SnapShot. Taking the SnapShot will be very specific to the contents of that window and therefore well suited to being written into the window itself instead of a global function or NVO (see Listing 1).

I use a similar window-defined function to restore the window from a SnapShot (see Listing 2). Basically we reverse the process - retrieving the SnapShot information and applying it to the window before the user sees it. The only problem here is if one of the DataWindows has changed (say a new column) since the SnapShot was taken. There are two ways to deal with this, which I'll cover later.

Putting the Pieces in Place
Implementation of the SnapShot functionality was fairly straightforward. A command button was placed on the window; Cb_snapshot executed the wf_snapshot() function, which checks to see if this window has a SnapShot ID already. The presence of an ID would mean that we want to update a SnapShot that already exists on the database. If the ID is null, the wf_snapshot() creates a new snapshot row on the database and records the ID as an instance variable.

In the open event of the window that contains SnapShot functions, a check is made to see if the user has any SnapShots currently on the database. If any are found, a response window is opened to allow the user to either select the SnapShot to be restored or cancel SnapShot selection, resulting in a new payment entry being started.

The response window also allows a user to delete any SnapShot entries that are no longer needed. This doesn't happen very often as the window automatically deletes a SnapShot once the payment entry is successfully saved.

Pitfalls
I mentioned earlier that if the DataWindow object has been changed between the taking of the SnapShot and the restoration, this will cause a problem. Specifically the SetFullState() function will return a 2, indicating that the DataWindow object being restored is different than the DataWindow object that is currently assigned to the DataWindow or DataStore. This usually means that a column has been added or removed from the DataWindow object. This will probably cause problems with the application that's trying to continue processing.

I've dealt with this situation two different ways:
1.   I use a version indicator on the SnapShot to tell the application which DataWindow object to assign using simple IF - THEN - ELSE logic.
2.   I keep a copy of the old executable around for use with the old SnapShots. This takes some coordination with the users but it's easier to do if there are a large number of DataWindow changes to deal with.

Summary
With SnapShot we provided our data entry personnel with the ability to record the current state of any payment entry that they're working on. I tell people the same thing I tell users about backups: "How much data do you want to rekey in the event of a system failure?" Nice thing about SnapShot is that it is fire-and-forget. Fire alarm? Hit SnapShot and exit the building. Coffee break? SnapShot will complete while you're stirring in the sugar.

I also have people do a SnapShot immediately before doing a save. If there's a problem with the save or a programming error, I have a fighting chance of saving the work if I have that SnapShot. This has happened on a number of occasions - usually with the largest payments (isn't that always the way it seems to go?).

One last benefit relates strictly to the developer. How many times have we had to do significant work setting up a situation to test either a new feature or a program fix? With SnapShot I can get the program set up once - do the SnapShot on the test system and re-create the test scenario as many times as I need - simply by choosing to restore the SnapShot.

About Bob Gardner
Bob Gardner has been developing PowerBuilder systems since leaving the mainframe world in 1995.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Before embarking on using open source cloud technology for your web property, a basic understanding of cloud, as it’s used in the industry, is essential. While there might be exceptions, here are the definitions. A software application delivered on the web instead of installing standa...
Businesses today generate billions of events or 100s of TBs of data in a month. These data contain valuable insights into customer behavior, key trends, buying patterns, etc. If these are successfully mined, they can lead to successful decision-making to maximize revenue and traffic fo...
Grid Dynamics, an eCommerce technology solutions company, and GridGain Systems, makers of an open source in-memory platform for Big Data processing, on Wednesday announced the expansion of their partnership which began in 2008. Grid Dynamics provides personalization and big data solut...
Private clouds solve many problems for enterprises and bring unique operational challenges along with them. There are dozens of companies of all sizes that will build you a private cloud and turn over the keys – then what? Trying to convert a traditional enterprise IT operations team t...
The networking industry has gone through different waves over last 30+ years. In the ’80s, the first wave was all about connecting and sharing; how to connect a computer to other peripheral devices and other computers. There were many players who developed technology and services to ad...
If your organization already uses virtualized infrastructure, you are well on your way to providing IT as a Service. But as businesses demand faster results in today’s competitive market, organizations look to gain more benefits from cloud computing than just virtualized infrastructure...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE