Step 1 - Setting up a business object


In this example I'll use the wwBusiness object to build a simple editing application that lets us view entries in developer registry. Operationally this will be very similar to the straight file access example I used in the first Step by Step guide, but we'll greatly reduce code by using the business object. And for kicks I'll upsize the application once we're done and run it with SQL Server without making any major code changes. Ready?

First we'll need to create a business object. In this case we'll keep it really simple with a single table application that uses the wwDevRegistry table in your wwDemo directory. First thing we want to do is create a business object that maps to this table. To this run the Web Connection Management Console (DO CONSOLE) and click on the Create New Business Object link. You'll see the following Wizard:

You specify a class to create and the name of the file that you'd like to bind it to. Binding to a file is optional, but in most cases business objects bind to an underlying file or at least a controlling file. Some objects like invoices are aggregate objects, and even though the invoice object is more complex and made up of multiple file relations it would still bind to the invoice master table.

In this case we're dealing with a single developer list table, so we choose that. Note that you can pick the file from the file dialog. I changed the value from the dialog to a relative path (.\) instead of using the full path to make the path more portable. Next I need to specify an ID file that is used to generate new PKs for my business object. If this file doesn't exist it's created for you. Each business object gets a record in this table with an increment count that generates the new ids.

Ok, click the Go button and new business object is created for you that should look like this now:

Simple Querying data

First, lets just check out how the business object works by trying some simple querying:

DO wconnect
SET CLASSLIB to wwBusiness Additive
SET CLASSLIB TO wwDeveloper ADDITIVE

loDev = CREATEOBJECT("cDeveloper")

loDev.Query()

BROWSE

This retrieved the entire contents of the table in a cursor to us. If you want to filter the query or retrieve only a few fields you can do something like this:

loDev.Query("company,Name where company < 'D'")

The Query method retrieves data with a SQL statement into a cursor. You can also specify a full SQL statement without an INTO clause like this:

loDev.Query("select company,Name where company < 'D' ORDER BY company","Developers")

The second parameter is the name of the cursor that's created. If you'd like to return data in XML format you can change the command to:

loDev.Query("select company,Name where company < 'D' ORDER BY company","Developers",3)
ShowXML(loDev.cResultXML)

The third parameter determines the output type for the query. When returning XML the cursor is created and parsed into the cResultXML property. The cursor is closed. If you want to create XML and also keep the cursor you can use:

loDev.Query("select company,Name where company < 'D' ORDER BY company","Developers")
loDev.ConvertData(3)
ShowXML(loDev.cResultXML)
BROWSE

There's much more to the object of course, but I'm going to leave that for later. Next let's create a new process in our Web Connection Step by Step WebDemo server.



  Last Updated: 1/14/2002 | © West Wind Technologies, 2008