Home > Articles

  • Print
  • + Share This

A State of Grace

So where were we? Oh yes, we were looking at the Browse Topic Box (BTB). We left it with the Programming topic open, wondering how exactly the renderBrowseTopicBox() function knew which piece of pre-generated HTML to grab to show what we see in Figure 1.

Figure 1 BTB with the programming topic selected.

If you recall, the ASP function referenced the public method getBtbHtml from the Java public class State. Let's dive right into State.java to see what's going on.

1 /*******************************
2 * METHOD: getBtbHtml
3 * PURPOSE: to get the BtbHTML from the database
4 * ARGS: none
5 * RETURN VALUE: String
6 * ASSUMPTIONS: the stateId has been set
7 ********************************/
8 public String getBtbHtml()
9 {
10  return btbHtml;
11 }

Well, it's simple enough, but obviously points a big flashing arrow somewhere else. We need to find out how btbHtml is set. First, it's declared:

public String btbHtml;	//the HTML needed to render the BTB

Then it's initialized:

btbHtml = null;

Then, finally, a real value is applied:

btbHtml = rec.getField("btb_html").getValue().toString();

There! That has a little meat to it! Line 3 above references a recordset returned from the database. The recordset is generated by the following lines:

StateDB mydb = new StateDB();
Recordset rec = null;
rec = mydb.getProperties(stateId);

This code references another class, StateDB, and calls the method getProperties.

1 /**************************************
2 * METHOD: getProperties
3 * PURPOSE: to get properties for the current state
4 * ARGS: String stateid
5 * RETURN VALUE: Recordset
6 *************************************/
7 public Recordset getProperties(String stateid)
8 {
9   StoredProcedure mysp = new StoredProcedure();
10  mysp.appendParam("@stateid",
11       AdoEnums.DataType.VARCHAR,
12       adoEnums.ParameterDirection.INPUT,
13       50,
14       stateid);
15  mysp.openStandardClient(Database.dsn(),
16       "sp_state_master_get_properties");
17  return (Recordset) mysp;
18 }

The gist of this method is the call to the SQL Server stored procedure sp_state_master_get_properties. The sharp-eyed reader will notice that we've written our own canned database access methods to facilitate dealing with SQL. The Java class StoredProcedure offers methods that extend the com.ms.wfc.data.Recordset class. AppendParam creates parameters on a command object (our stored procedure expects one incoming argument, @stateid). Finally, the openStandardClient call performs the actual stored procedure work. Because mysp, the StoredProcedure object, is an extension of a Recordset object, we can treat it as such once we pass it back to the ASP layer. By writing our own database access wrapper, we ensure that all access is performed the same way by every developer, and that proper cleanup and error handling is always available.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.