|
Comments
|
Today's Top SOA Links
DataWindows SnapShot
SnapShot
By: Bob Gardner
Mar. 1, 2003 12:00 AM
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 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 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 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 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 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
The Window Open Event First the instance variable for the transaction object: Transaction itr_snapshot in the open event for the window:
Itr_snapshot = CREATE transaction and in the close event:
IF IsValid(itr_snapshot) THEN
Accessing the SnapShot Table 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 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've dealt with this situation two different ways:
Summary 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. Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||