Files related to this demo are in install_dir/COM/odi/demo/pcount.


Persistent Counter
==================
This program demonstrates how to write a simple applet that uses
ObjectStore.  You could use this applet as a "hit counter"
(such as those numbers you see on Web pages that say "this page has
been visited 001729 times.").

Data Model
==========
The database is so simple that there are no persistent classes.  There
is just one Integer object, whose value is the counter.

Running the Applet
==================
Because ObjectStore operates on (opens, reads, writes) files,
Web browsers will not allow applets that use ObjectStore to run as an
"untrusted" applet.  Currently, all applets downloaded from Web
servers are considered "untrusted".  Technology for "trusted" applets
is being developed by several companies and is expected to be
available in the near future.

This demo program does not work in Netscape Navigator or in Internet
Explorer, regardless of where it is loaded from. 


The applet can be run from the "appletviewer" application that is
provided with the Java Development Kit.  The procedure is described
below.

Before running the program, you need an additional entry in your
CLASSPATH environment variable.  You already have an entry for the
"osji.zip" file, in order to use ObjectStore.
You must add an additional entry for the directory that contains the 
zip file, so that Java can find this program.

For example, on Solaris, if you place the ObjectStore distribution into 
/opt/ODI/osji, you need:

  CLASSPATH=/opt/ODI/osji/osji.zip:/opt/ODI/osji

On Windows, if you place the ObjectStore distribution into
c:\odi\osji, you need these entries:

  CLASSPATH=c:\odi\osji\osji.zip;c:\odi\osji

Compile the program: go to the directory COM/odi/demo/pcount
and enter

javac *.java

If you are running a server on the local machine, enter

appletviewer PersistentCounter.html

The applet window contains a line of text that says "This page has
been visited 1 time.".  If you click on the the Restart or Reload
items in the Applet menu, you'll see the counter go up.  If you exit
appletviewer and then start a new appletviewer, the value of the
counter is preserved.

The program creates a database to hold the counter.  The "init"
method gets the name of the database from the parameters specified in
the APPLET tags in the HTML page.  The HTML page says:

  PARAM NAME=db value="pcount.odb"

so the database is created in the same directory that holds the HTML
file itself. 
 

You can also run the program using the command line Java VM.

   java -Ddb=pcount.odb COM.odi.demo.pcount.PersistentCounter

Your configuration might be set up so that the ObjectStore Server
requires a user name and password to run this program. If it is,
you can specify a user name and password on the command line with
the -D option (/d for Microsoft jview):

   java -DCOM.odi.user=your_user_name -DCOM.odi.password=your_password \
     -Ddb=pcount.odb COM.odi.demo.pcount.PersistentCounter

To run this on a remote server, edit the PersistentCounter.html file
and put in something like this:

  PARAM NAME=db value="g:\bob\pcount.odb"

Using the JDK 1.2 Beta 4 or Later Releases
==========================================
If you are using the JDK 1.2 Beta 4 or later releases, the appletviewer 
enforces the new JDK security rules and requires some new arguments to 
specify the CLASSPATH. Before you run the pcount example, you must 
create a security policy file with the following contents:

grant {
   permission java.security.AllPermission;
};

When you invoke appletviewer, you must specify 

- An option that identifies the security policy file
- The CLASSPATH

For example, if the security policy file and the pro.zip file are in 
C:\ODI\PSEPROJ, you would enter the following command line:

appletviewer -J-Djava.security.policy=C:\ODI\PSEPROJ\security.fil -J-cp -JC:\ODI\PSEPROJ\pro.zip;C:\ODI\PSEPROJ PersistentCounter.html