PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

Using EAServer to Solve Important Programming Tasks

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.

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:

    1. PowerBuilder forces methods to lowercase.
    2. 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:

ResultSet lrs_resultset
lds_data.GenerateResultSet (lrs_resultset)
return lrs_resultset
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;
    Next the component is accessed.
    var nvo = java.CreateComponent("YourPackageName/n_rs", "iiop://localhost:9000", "jagadmin", "");
    With the component reference, nvo, the method can be called:
    var rs = nvo.getrs();
    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:
    while(query.MoveNext()) {
    document.writeln("1: "+query.GetValue(1)+"<BR>");
    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.

  • Step 1: Add a parameter to getrs() and select reference (see Figure 3).

  • Step 2: Redeploy the component. Because the method signature changed, you'll need to regenerate the Java stubs and compile the Java files.

  • Step 3: Modify the resultset.stm file to retrieve the reference parameter. Add the following line after the previous import:
    import system/utils/JavaWrappers.ssc;
The following lines must be added before the method getrs() is called. First, a holder will be needed so the next line is added:
var lhldrValue = java.CreateObject("org.omg.CORBA.StringHolder", " ");
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.

More Stories By Tim Nesham

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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

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.