Using EAServer to Solve Important Programming Tasks

There are files that come with EAServer that were hidden from me when I first started using EAS. These files, primarily utilities, can solve some common and important programming tasks. This article essentially covers two of these files or utilities, one named javaqry.ssc; and the other, JavaWrappers.ssc.

CIO, CTO & Developer Resources

The javaqry.scc file resides in a directory created by Dynamo called Yoursite/System/Utils and provides a way for a PowerBuilder DataStore to be "passed" from Jaguar to the Web server where it can be manipulated in DynaScript. The other file, JavaWrappers.ssc, helps in passing values by reference between the Web server and Jaguar. (This file can be downloaded from the PBDJ Web site,
www.PowerBuilderJournal.com.) In this article I'll explore the use of these files in trying to solve the two aforementioned programming tasks. Note: The source code is in resultset.pbl and resultset.stm (see the PBDJ Web site).

Task 1:Passing a DataStore from Jaguar to server-side script, then processing the rows to display in an HTML client browser

Step 1: Create a DataWindow object. I'm assuming the reader already knows how to create a DataWindow object in the DataWindow painter. The DataWindow object I used is an external DataWindow with seven columns. The details about my DataWindow object are unimportant, and you can create whatever kind you need.

Step 2: Create a custom class object - also known as a nonvisual object or NVO. I created a nonvisual object called n_rs having one method called GetRS(). Two things I'd like to point out about Figure 1 that may escape the reader's notice are:

PowerBuilder forces methods to lowercase.

There's no data type in the drop-down listbox called ResultSet.

I called the method GetRS, but PowerBuilder forces it to lowercase. This becomes critical when working with Java and JavaScript, both case sensitive. The method must be in lowercase, getrs(), in JavaScript or the method call will fail. Since there's no data type in the drop-down listbox called ResultSet, you'll need to type this in yourself. The result set is one of the predefined Jaguar IDL data types. Basically, this means you won't need to do anything special for Jaguar to handle the result set. For more information on Jaguar data types refer to the Jaguar Programmer's Guide in the Online Books. To get the data from the DataStore to the result set and return it to the server you'll need the following lines:

At this point you might like to review Listing 1. (I assume the reader already knows how to use Jagmanager to generate and compile Java stubs. If not, refer to the Jaguar Programmer's Guide.)

Run the Jaguar Component Wizard in PowerBuilder to deploy the NVO to Jaguar, then use Jagmanager to generate the Java stubs (see Figure 2).

After the stubs are successfully generated, compile the Java files. We're now set to access the component from inside the stm file. Note: Dynamo uses the file extension "stm" for the same reason other Web servers use .htm to contain HTML.

Step 3: Create the stm file to access the Jaguar component method. Create a simple HTML file in Powersite; mine is called resultset.stm. The javaqry.ssc file is imported to help get the RESULTSET. Since this is server-side script, the "begin script" tag, "<%" needs to be first.
<% import system/utils/javaqry.ssc;

But the variable rs is not the RESULTSET type that we need. This is where the object called JavaQuery from the javaqry.ssc file comes into play:

var query = new JavaQuery(rs);

The RESULTSET type is returned and is now ready for use. This object doesn't have much functionality but it gives enough to get the job done. Basically, only three methods are available at this point: GetColumnCount(), GetValue() and MoveNext(). The code will now iterate through the rows in the result set:

The start of the result set is prior to the first row, so MoveNext() gets the first row on the first call and continues until the "while" evaluates to false to indicate no more rows.

Step 4: Why do this at all? There are circumstances when data will need to be combined from disparate sources. In such cases, information may need to be retrieved from a database to be used at a later time. Two examples would be combining database data with a text file and building an HTML table.

If you're using Active Server Pages, then take a look at the file called adoqry.ssc. This file can be used in a similar way to the javaqry.ssc, but it makes use of ADO recordsets.

Task 2:Returning values passed by reference from Jaguar
At times it would be nice to return more than one data type from a component method. For example, with our result set created in Task 1, a small amount of data may be related to the result set that could be retrieved in a separate SQL call inside the Jaguar component. An extra component method call could then be avoided if the data were passed back by reference as a parameter to the method.

Now the JavaFieldHelper object is created and the holder is passed so that a helper reference is returned. The helper will help us extract the value from the holder.

var lhlprValue = new JavaFieldHelper(lhldrValue);

The getrs() method can now be called with the reference parameter.

var rs = nvo.getrs(lhldrValue);

Because the holder variable was passed into the JavaFieldHelper object, the helper, lhlprValue, can be used to access the actual value:

var thevalue = lhlprValue.getString("value");

The value can then be displayed to the client browser.

document.writeln("Passed by reference: "+ thevalue +"<BR>");

Now might be a good time to refer to Listing 2.

The JavaWrappers.ssc file comes from Sybase but was not included with the version of EAServer that I have. I found the file through the Sybase newsgroup devoted to EAServer. See the newsgroup powersoft.public.easerver at
http://forums.Sybase.com. This is a very active newsgroup and is essential if you need help on EAServer topics; in many ways it's superior to paid support.

EAServer is a large product with many new and powerful features. I hope this article has helped you to understand a few of the more obscure features and stimulated your interest to discover more.

Tim Nesham, a consultant with BORN, has 14 years of experience in the IT industry. Having started with seven years of C programming experience, he later became a CPDP4 and certified PowerBuilder instructor.

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Cloud computing budgets worldwide are reaching into the hundreds of billions of dollars, and no organization can survive long without some sort of cloud migration strategy. Each month brings new announcements, use cases, and success stories.