videoapp
sample application, which illustrates the use of the LiveWire Database Service. It describes how to configure your environment to run the videoapp
and oldvideo
sample applications.
Sections in this chapter:
Netscape servers come with two sample database applications, videoapp
and oldvideo
, that illustrate the LiveWire Database Service. These applications are quite similar; they track video rentals at a fictional video store. The videoapp
application demonstrates the use of the DbPool
and Connection
objects. The oldvideo
application demonstrates the use of the predefined database
object.
There are a small number of restrictions on the use of these applications:
videoapp
application uses cursors that span multiple HTML pages. If your database driver is single-threaded, these cursors may hold locks on the database and prevent other users from accessing it. For information on which database drivers are single-threaded, see the Enterprise Server 3.x Release Notes.
NOTE: Your database server must be up and running before you can create your video database, and you must configure your database server and client as described in Chapter 10, "Configuring Your Database."In addition, the database-creation scripts use database utilities provided by your database vendor. You should be familiar with how to use these utilities.
videoapp
application is in the $NSHOME\js\samples\videoapp
directory, where $NSHOME
is the directory in which you installed the Netscape server. The oldvideo
application is in the $NSHOME\js\samples\oldvideo
directory.
For each application, you must change the connect string in the HTML source file, start.htm
, to match your database environment. For information on the parameters you use to connect, see "Database Connection Pools"; for even more information, see the description of the connect
method in the JavaScript Reference.
For the videoapp
application, change this line:
project.sharedConnections.pool =
For the
new DbPool ("<Server Type>", "<Server Identifier>",
"<User>", "<Password>", "<Database>", 2, false)oldvideo
application, change this line:
database.connect ("INFORMIX", "yourserver", "informix",
Save your changes and recompile the application. To recompile one of the applications from the command line, run its build file, located in the application's directory. Be sure your
"informix", "lw_video")PATH
environment variable includes the path to the compiler (usually $NSHOME\bin\https
).
Restart the application in the JavaScript Application Manager.
Creating the Database
There are two sets of creation scripts for videoapp
and oldvideo
, in their respective application directories. The sets of scripts are identical. If you run one set, both applications will be able to use the database.
The first time you run the scripts you might see errors about dropping databases or tables that do not exist. These error messages are normal; you can safely ignore them.
Informix
Before using the following instructions, you must configure your Informix client as described in "Informix". In addition, make sure your PATH
environment variable includes $INFORMIXDIR\bin
and that your client is configured to use the Informix utilities.
The SQL files for creating the video database (lw_video
) on Informix are in these two directories:
$NSHOME\js\samples\videoapp\ifx
$NSHOME\js\samples\oldvideo\ifx
NOTE:
Remember that pathnames in this manual are given in NT format if they are for
both NT and Unix. On Unix, you would use $NSHOME/js/samples/videoapp/
ifx.
cd c:\netscape\server\js\samples\videoapp\ifxYou can also run the commands from the
ifx_load.bat
oldvideo\ifx
directory:
ORACLE_SID
environment variable.
The SQL files for creating the video database on Oracle are in these two directories:
$NSHOME\js\samples\videoapp\ora
$NSHOME\js\samples\oldvideo\ora
SQL>
prompt, enter this command:
Start $NSHOME\js\samples\videoapp\ora\ora_video.sql
oldvideo
directory. This SQL script does not create a new database. Instead, it creates the Oracle tables in the current instance.
PATH
environment variable includes $SYBASE\bin
and set DSQUERY
to point to your server.
The SQL files for creating the video database on Sybase are in these two directories:
$NSHOME\js\samples\videoapp\syb
$NSHOME\js\samples\oldvideo\syb
syb_video.csh
userid password
$NSHOME\js\samples\videoapp\syb\syb_load.csh saOn NT, the script is:
syb_load userid password
For example:
c:\netscape\server\js\samples\videoapp\syb\syb_load saAlternatively, you can run the script from the
oldvideo
directory.
NOTE: If you have both Sybase and MS SQL Server or DB2 installed on your machine, there is a potential naming confusion. These vendors have utilities with the same name (bcp
andisql
). When running this script, be certain that your environment variables are set so that you run the correct utility.
DSQUERY
to point to your server.
The SQL files for creating the video database on MS SQL Server are in these two directories:
$NSHOME\js\samples\videoapp\mss
$NSHOME\js\samples\oldvideo\mss
mss_load
userid password
c:\netscape\server\js\samples\videoapp\mss\mss_load sa
NOTE: If you have both MS SQL Server and Sybase or DB2 installed on your machine, there is a potential naming confusion. These vendors have utilities with the same name (bcp
andisql
). When running this script, be certain that your environment variables are set so that you run the correct utility.
$NSHOME\js\samples\videoapp\db2
$NSHOME\js\samples\oldvideo\db2
<nodename>
: node name alias<hostname>
: host name of the node where the target database resides<service-name>
: service name or instance name from the services file<database-name>
: database name<user>
: authorized user<password>
: user's passwordNOTE: If you have both DB2 and Sybase or MS SQL Server installed on your machine, there is a potential naming confusion. These vendors have utilities with the same name (bcp
andisql
). When running this script, be certain that your environment variables are set so that you run the correct utility.
videoapp
sample application up and running. This sample is significantly more complex than the samples discussed in Chapter 2, "Introduction to the Sample Applications." This chapter only gives an overview of it. You should look at some of the files to start familiarizing yourself with it.
Once you have created the video database and changed the database connection parameters, you can access the application here:
http://
After connecting to the database, the Application Manager displays the server.domain
/videoappvideoapp
home page, as shown in Figure 13.1.
Figure 13.1 Videoapp home page
The first thing you must do when you're connected is to add a new customer. Until you have done this, there are no customers to use for any of the other activities.
You can use videoapp
as a customer or as an administrator. As a customer, you can:
videoapp
, listed in Table 13.1, are copiously commented.
Table 13.1 Primary videoapp
source files
Application Architecture
This section orients you to the implementation of some of the functionality in videoapp
. It describes only how the application works with the database and details the procedure for renting a movie. Other tasks are similar.
Connection and Workflow
When a user initiates a session with videoapp
by accessing its default page (home.htm
), videoapp
checks whether it is already connected to the database. If so, videoapp
assumes not only that the application is connected, but also that this user is already connected, and it proceeds from there.
If not connected, videoapp
redirects to start.htm
. On this page, it creates a single pool of database connections to be used by all customers, gets a connection for the user, and starts a database transaction for that connection. It then redirects back to home.htm
to continue. The user never sees the redirection.
The database transaction started on start.htm
stays open until the user explicitly chooses either to save or discard changes, by clicking the Save Changes or Abort Changes button. When the user clicks one of those buttons, save.htm
or abort.htm
is run. These pages commit or roll back the open transaction and then immediately start another transaction. In this way, the customer's connection always stays open.
Once it has a database connection, videoapp
presents the main page to the user. From that page, the user makes various choices, such as renting a movie or adding a new customer. Each of those options involves displaying various pages that contain server-side JavaScript statements. Many of those pages include statements that use the connection to interact with the database, displaying information or making changes to the database.
The first thing you must do when you're connected is to add a new customer. Until you have done this, there are no customers to use for any of the other activities.
Renting a Movie
The pick.htm
page contains a frameset for allowing a customer to rent a movie. The frameset consists of the pages category.htm
, videos.htm
, and pickmenu.htm
.
The category.htm
page queries the database for a list of the known categories of movie. It then displays those categories as links in a table in the left frame. If the user clicks one of those links, videoapp
displays video.htm
in the right frame. There are a few interesting things about the server-side code that accomplishes these tasks. If you look at this page early on, you see these lines:
var userId = unscramble(client.userId)
These statements occur in most of
var bucket = project.sharedConnections.connections[userId]
var connection = bucket.connectionvideoapp
's pages. They retrieve the connection from where it is stored in the project
object. The next line then gets a new cursor applicable for this task:
cursor = connection.cursor("select * from categories");
A variant of this statement occurs at the beginning of most tasks.
Here is the next interesting set of statements:
<SERVER>
...
while (cursor.next()) {
catstr = escape(cursor.category)
</SERVER><TR><TD><A HREF=`"videos.htm?category=" + catstr` TARGET="myright">
<SERVER>write(cursor.category);</SERVER></A>
</TD>
</TR>
<SERVER>} // bottom of while loop
This loop creates a link for every category in the cursor. Notice this statement in particular:
<A HREF=`"videos.htm?category=" + catstr` TARGET="myright">
This line creates the link to videos.htm
. It includes the name of the category in the URL. Assume the category is Comedy. This statement produces the following link:
<A HREF="videos.htm?category=Comedy" TARGET="myright">
When the user clicks this link, the server goes to videos.htm
and sets the value of the request
object's category
property to Comedy
.
The videos.htm
page can be served either from pick.htm
or from category.htm
. In the first case, the category
property is not set, so the page displays a message requesting the user choose a category. If the category
property is set, videos.htm
accesses the database to display information about all the movies in that category. This page uses the same technique as category.htm
to construct that information and create links to the rent.htm
page.
The rent.htm
page actually records the rental for the customer. It gets information from the request and then updates a table in the database to reflect the new rental. This page performs the update, but does not commit the change. That doesn't happen until the user chooses Save Changes or Abort Changes.
The pickmenu.htm
page simply displays buttons that let you either return to the home page or to the page for adding a new customer.
Modifying videoapp
As way of getting used to the LiveWire functionality, consider modifying videoapp
. Here are some features you might add:
sharedConnections
array implies that this particular user is connected. You can change start.htm
to check whether there is an ID for this user in that array and whether the connection stored in that location is currently valid. See "Sharing an Array of Connection Pools".
Last Updated: 10/30/97 12:19:43