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 cannot currently be used with the Informix database. The oldvideo
application, however, can be used with Informix.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 Server-Side 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.
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.
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 path names 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.
ifx_load.csh
shell script for videoapp
and for oldvideo
.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.sqlYou can also run the script from the
oldvideo
directory. This SQL script does not create a new database. Instead, it creates the Oracle tables in the current instance.ora_load
script file to load the video tables with data. On NT, run the ora_load.bat
batch file to load the video tables with data. You must edit the appropriate file to connect to your server; the instructions for doing so are in the file.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
For example:$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
For example: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
PATH
environment variable must include the $DB2PATH/bin
, $DB2PATH/misc
, and $DB2PATH/adm
directories.db2_load.csh
; on NT, it is in db2_load.bat
. Edit the appropriate db2_load
file and modify the following parameters to reflect your environment:<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 password/etc/services
file has entries for your instance or service name if you are creating the database in a remote DB2 server.db2_load
script runs the db2_video.sql
and import.sql
scripts. These subsidiary scripts create the video tables and load them with data from the *.del
files. They do not create a new database. Instead, they create the DB2 tables in the local database alias specified in the db2_load
script.NOTE: 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 4, "Quick Start with 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://server.domain
/videoapp
After connecting to the database, the Application Manager displays the videoapp
home page, as shown in Figure 13.1.
Figure 13.1 Videoapp home page
videoapp
as a customer or as an administrator. As a customer, you can:
As an administrator, you can:
videoapp
, listed in the following table, are copiously commented.
Table 13.1 Primary videoapp
source files
videoapp
. It describes only how the application works with the database and details the procedure for renting a movie. Other tasks are similar.
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.
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.connection
videoapp
'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 loopThis 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.
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: 09/29/99 18:02:00