Two principal uses can be made of the provided client package : it can be used to communicate with a SIRA_PRISE server from within a java program, or it can be used to do "scripting" : save SIRA_PRISE commands in a script file, and execute those commands repeatedly.
For further information about using the SIRA_PRISE client package with a java program, we refer to the javadoc documentation for this package, which is also included in the distribution. The remainder of this section will discuss the scripting facilities provided by the client package.
The java class for the script processor is be.SIRAPRISE.client.ProcessScript. The command line for invoking the script processor thus becomes
java
be.SIRAPRISE.client.ProcessScript scriptfilename
Please observe that the classpath must be set properly, such that the script processor has access to the sp.client.jar package :
java
-cp sp.client.jar be....,
where the name of the jar file might need to be preceded by the appropriate directory specification.
Several options can be configured for invocations of the script processor. Which options they are, and where and how the script processor searches for them, is explained in this section.
There are several ways to pass run-time options to the script processor. The order in which the script processor searches for these options is the same for each option, allthough for some options it may be the case that some of these locations do not apply :
Specifying options via the command line is done by appending the option name, followed by the option value in brackets, at the end of the command line. E.g. to set the HOST option to the value LOCALHOST via the command line, one would have to enter the command line
java
be.SIRAPRISE.client.ProcessScript ... HOST(LOCALHOST)
Specifying options via a properties file is done by placing option lines in a file named be.SIRAPRISE.client.ProcessScript.properties. This file is searched for (in the order specified) on the classpath, in the user's current working directory (i.e. the directory named by the user.dir system property), and in the user's home directory (i.e. the directory named by the user.home system property).
Option lines have the
format OPTIONNAME=OPTIONVALUE
(e.g. HOST=LOCALHOST).
The following options can be used in the script processor :
|
Option name |
Description |
Default value |
|---|---|---|
|
|
The hostname or IP address of the SIRA_PRISE server to which to connect. |
LOCALHOST |
|
|
The IP port number on the server to which to connect |
50000 |
|
|
The userID owning the transactions that will be started to execute the script's commands. |
"" (the zero-length string, implying that the transactions will be anonymous). |
|
|
The file where the script processor's output is to be written. This option can only be set on the command line, not in a properties file. |
The script file name, suffixed with ".out.txt". |
|
|
Directory where the script processor will search for a script file if it is not found in the current directory. |
No default. |
|
|
Comma-separated list of names of algorithms that the script processor can use for signing. |
No signing. |
|
|
Comma-separated list of names of algorithms that the script processor can use for encryption. |
No encryption. |
The script processor uses the following steps to locate the script file :
The following table clarifies how the script processor determines the complete name of the script file to read, based on the filename given in argument :
|
Argument |
Value specified for property SCRIPTSDIRECTORY |
Complete filename searched for if script not found in the current directory |
|---|---|---|
|
Usr/MyScRiPt |
SCRIPTS\ |
Usr/MyScRiPt.SPS |
|
Scripts\test25 |
SIRA_PRISE_SCRIPTS\ |
Scripts\test25.SPS |
|
Test25.SPS |
SCRIPTS\ |
SCRIPTS\Test25.SPS |
|
Test25 |
SCRIPTS\ |
SCRIPTS\Test25.SPS |
|
X:myscript |
SCRIPTS\ |
X:myscript.SPS |
Note that names of script files must always end with the suffix ".SPS". The script processor will append this suffix to any provided filename that does not meet that requirement.
Scripts files are "plain text" files, encoded using some character set. Which character set the script file is encoded in, can be specified as the first line in the script as follows :
*
Charset=windows-1252
If this line is not found
in the script, or the value specifies a character encoding that cannot
be found using Charset.forName(),
then the character encoding is assumed to be the default Character
encoding of the JVM in which the script processor runs (i.e. the
Character encoding returned by Charset.defaultCharset().
(Note : this line is assumed to hold only characters in the
unicode range < 128. So the encoding of the line that defines
the encoding for the rest of the file should not be an issue.)
Scripts files contain series of valid SIRA_PRISE commands in the format as defined in the grammar section. The commands in the file are separated from each other by a CRLF sequence or a LF character, e.g. :
add
relvar,relvar(t(relvarname(DUMMADEE)relvarpredicate(The shop is open)))
add key,key(t(relvarname(DUMMADEE)keyid(1)))
The token combination |> (a vertical bar followed by a greater-than sign) at the end of a line is a continuation sequence. This indicates that the following line in the script will be part of the same command. That following line must be present, or the script processor will raise an exception and not send the command to the server.
The script processor in the package processes a script file by reading this file line per line, assembling the lines into full commands according to the continuation sequences it encounters, and sending each command to a SIRA_PRISE server. When not using continuation sequences, multiple assignments must therefore be written down in their correct syntactical form, i.e. CMD(...)CMD(...)CMD(...)... , all of them on one single line.
Thus trying to execute the little script above will produce the following results :
Request
: add relvar,relvar(tuple(relvarname(DUMMADEE)relvarpredicate(The shop
is open)))
Reply : be.SIRA_PRISE.server.ConstraintViolatedException : Relvar
DUMMADEE has no Key.
Request : add key,key(tuple(relvarname(DUMMADEE)keyid(1)))
Reply : be.SIRA_PRISE.server.ConstraintViolatedException : A Key is
defined for relation variable DUMMADEE but that variable does not exist.
Reply : OK.
For the script to work as (presumably) intended, it must be changed to :
CMD(add
relvar,relvar(t(relvarname(DUMMADEE)relvarpredicate(The shop is
open))))CMD(add key,key(t(relvarname(DUMMADEE)keyid(1))))
The output of the process appears in a file named in the OUTFILE option.
The script processor will try to process all commands using one single transaction, i.e. it will connect to the server once, start a transaction, and then send it all the commands in the script. If any kind of error is reported by the server, then all updates will be undone by the server up to the most recent successful commit, and the transaction will be ended. The script processor then proceeds by starting a new transaction, and continues to send the remaining commands to the server.
Commit commands can be used in the scripts to control which updates can be undone in the event of an expected or unexpected error signaled by the server (expected errors arise if scripts are used to test whether SIRA_PRISE correctly reports constraint violations etc.).
By default, the script processor connects to a SIRA_PRISE server without authenticating itself, and uses anonymous transactions to execute the commands. This section explains the steps needed to use the script processor in authenticated mode, i.e. have the script processor authenticate itself when connecting to the server.
The steps needed to achieve this are the following :
The steps needed for using non-anonymous transactions with the script processor are similar to the steps needed for using the script processor in authentication mode, with the following differences :