Overview

This package provides PowerLinks developers with the ability to save and retrieve named values in a database. The values are associated with a particular proxy tool, instance and/or user and allow data for a user to persist between accesses. The data may be stored in any database accessible as a WebLogic data source or via a JDBC connection string.

System requirements

The ProxyToolRegistry package can be used by PowerLinks written for WebCT Vista 4.2 (or higher) and WebCT Campus Edition 6.2 (or higher). It is dependent on the following Java packages:

Installation

This package is designed for use with PowerLinks and may be installed either by copying the jar file into the same directory as the PowerLink itself, or placed in the common directory so that it can be shared by more than one PowerLink. The same choice applies to the jar files for each of the dependent Java packages.

The package uses a single database table for storing the settings values. The table may be created in any database for which there is a Java JDBC database driver available. By default it is assumed to use a data source defined on the same Weblogic server as used by WebCT. The database table should have the following definition:

ColumnData typeAllow nullsPrimary key
NameDescriptionSQL ServerOracle
ProxyToolName Name of the proxy tool as specified in its deployabledomponents.xml file varchar(256)varchar2(256)NoNo
InstitutionSourceName Source name of the institution for which the proxy tool instance and user apply varchar(32)varchar2(32)NoYes
InstitutionSourceID Source ID of the institution for which the proxy tool instance and user apply varchar(256)varchar2(256)NoYes
LearningContextSourceName Source name of the learning context in which the proxy tool instance has been added (empty string for global settings, see below) varchar(32)varchar2(32)NoNo
LearningContextSourceID Source ID of the learning context in which the proxy tool instance has been added (empty string for global settings, see below) varchar(256)varchar2(256)NoNo
ProxyToolInstanceID ID of the proxy tool instance (empty string for global settings) number(20,0)numeric(20,0)NoYes
PersonSourceName Source name for the user to whom the setting applies (empty string for anonymous settings, see below) varchar(32)varchar2(32)NoYes
PersonSourceID Source ID for the user to whom the setting applies (empty string for anonymous settings, see below) varchar(256)varchar2(256)NoYes
SettingName Name of the setting varchar(255)varchar2(255)NoYes
SettingValue Value of the setting varchar(4000)varchar2(4000)No (SQL Server); Yes (Oracle)No
CreateTime The date and time when the setting was added number(20,0)numeric(20,0)NoNo
LastModifyTime The date and time when the setting was last modified number(20,0)numeric(20,0)NoNo

All setting values are stored and retrieved as strings but may be converted to other data types as required. The maximum size of any individual setting value is 4,000 characters but this can be increased as required subject to any database limitations (for example, Oracle 8.1 and above limit the size of varchar fields to 4,000 bytes). Use the addLongSetting() and getLongSetting() methods to save and retrieve settings which may have values which are too long to be saved in a single record. The following SQL statements illustrate how table specified above might be created (the table name may be changed to suit). For Microsoft SQL Server:

CREATE TABLE ProxyToolRegistry(
  ProxyToolName varchar(256) NOT NULL,
  InstitutionSourceName varchar(32) NOT NULL,
  InstitutionSourceID varchar(256) NOT NULL,
  LearningContextSourceName varchar(32) NOT NULL,
  LearningContextSourceID varchar(256) NOT NULL,
  ProxyToolInstanceID numeric(20,0) NOT NULL,
  PersonSourceName varchar(32) NOT NULL,
  PersonSourceID varchar(256) NOT NULL,
  SettingName varchar(256) NOT NULL,
  SettingValue varchar(4000) NOT NULL,
  CreateTime numeric(20,0) NOT NULL,
  LastModifyTime numeric(20,0) NOT NULL);

ALTER TABLE ProxyToolRegistry ADD PRIMARY KEY (
  InstitutionSourceName ASC,
  InstitutionSourceID ASC,
  ProxyToolInstanceID ASC,
  PersonSourceName ASC,
  PersonSourceID ASC,
  SettingName ASC);

For Oracle:

CREATE TABLE ProxyToolRegistry(
  ProxyToolName varchar2(256) NOT NULL,
  InstitutionSourceName varchar2(32) NOT NULL,
  InstitutionSourceID varchar2(256) NOT NULL,
  LearningContextSourceName varchar2(32) NOT NULL,
  LearningContextSourceID varchar2(256) NOT NULL,
  ProxyToolInstanceID number(20,0) NOT NULL,
  PersonSourceName varchar2(32) NOT NULL,
  PersonSourceID varchar2(256) NOT NULL,
  SettingName varchar2(256) NOT NULL,
  SettingValue varchar2(4000) NULL,
  CreateTime number(20,0) NOT NULL,
  LastModifyTime number(20,0) NOT NULL);

ALTER TABLE ProxyToolRegistry ADD CONSTRAINT ProxyToolRegistry_pk PRIMARY KEY (
  InstitutionSourceName,
  InstitutionSourceID,
  ProxyToolInstanceID,
  PersonSourceName,
  PersonSourceID,
  SettingName);

Note that Oracle users should also set the empty property (see below) as the database does not support empty strings.

Configuration settings

An optional properties file may be placed in the same directory as the package file. This file should have the same file name as the package but be given an extension of .properties. For example, if the package is named ProxyToolRegistry.jar it will look for a properties file named ProxyToolRegistry.properties. The properties file may contain one or more of the following settings:

NameDescriptionDefault value
Weblogic data sourceGeneric JDBC connection
datasource.name the JNDI name of the Weblogic data source ProxyToolRegistry NA
driver class name of JDBC database driver to be loaded (e.g. net.sourceforge.jtds.jdbc.Driver); not required if the driver is already loaded NA None
connection the JDBC connection string (e.g. jdbc:bea:sqlserver://db.server.com:port;databaseName=db_name) NA None
username JNDI/database username JNDI username used by WebCT database connection None
password JNDI/database password JNDI password used by WebCT database connection None
poolconnections initial size of the connections pool for JDBC data sources NA 5
poolexhausted default action when the JDBC connections are exhausted; recognised values are:
  • 0 - fail the request
  • 1 - block the request
  • 2 - grow the size of the connection pool
NA 2
tablename name of database table used for saving settings ProxyToolRegistry
empty The string used to represent an empty string; this is only required for databases which do not support empty strings, such as Oracle None
escape The escape character used in an SQL LIKE clause as supported by the host database !
wildcardany Wildcard character representing zero or more characters in an SQL LIKE clause as supported by the host database %
wildcardsingle Wildcard character representing any single character in an SQL LIKE clause as supported by the host database _
valuefieldsize The size of the SettingValue field 4000
sequenceseparator The character used to separate a setting name from the record number for setting values split across multiple records ;

Using a WebLogic data source

Since WebCT is run using WebLogic the easiest way of adding this database is as a data source within the WebLogic Server Administration Console in a similar way to the data sources used to connect to the WebCT databases. Further details on creating WebLogic data sources can be found on their documentation website. When using a data source (or multi data source) name other than the default of ProxyToolRegistry include the following lines in the properties file:

datasource.name=xxx
username=yyy
password=zzz

where:

Using a JDBC connection

It is also possible to define a standard JDBC connection string to connect to the database table. This may be specified by including the following line in the properties file:

connection=jdbc:bea:sqlserver://db.server.com:port;databaseName=db_name

where:

A connection to an Oracle database can be specified like this:

connection=jdbc:oracle:thin:@db.server.com:port:db_name

JDBC drivers for other databases are also available; check your database documentation for details.

Usage

Class methods

This package is comprised of a single class which is fully described in the JavaDocs documentation. The main methods supported are as follows:

Each setting comprises a simple name and value pair. However, there are four different types of setting which are supported as specified by the values of the global and anonymous parameters.

 anonymous
falsetrue
global false 1. settings which relate to both a specific proxy tool instance and a specific user 2. settings which relate to all users of a specific proxy tool instance
true 3. settings which apply to all instances of a proxy tool for a specific user 4. settings which apply to all users of all instances of a proxy tool

Note the term global is used to refer to all proxy tool instances within the same institution and not for all instituons on the server. Some illustrations of common uses of these methods follow.

Creating an instance

An instance of this utility can be created by calling its constructor method. The SaveEmptyValues property determines whether, or not, a setting should be saved when its value is empty. The default value is true which means that settings may have empty values. However, when this value is set to false new settings will not be created with empty values and updating an existing setting to an empty value will cause it to be deleted. This saves wasting database space as the value of a non-existent setting will be empty anyway.

  import com.webct.platform.sdk.security.authentication.module.WebCTSSOContext;
  import com.spvsoftwareproducts.webct.utils.ProxyToolRegistry;

  ...

  ProxyToolRegistry ptReg = null;

  try {
    ptReg = new ProxyToolRegistry(super.getWebCTSSOContext());
    ptReg.setSaveEmptyValues(false);
  } catch (SQLException e) {
    throw new LoginException("Unable to get proxy tool registry instance");
  }

Accessing a single setting

The following examples illustrate how to access a setting for each of the four categories identified above. They assume that a instance of this proxy tool registry has been created with a name of ptReg

1. User-specific data for a proxy tool instance

These settings apply to a single proxy tool instance and to a single user; for example, this could be used to save data entered by a user.

  boolean ok;
  String idValue;

// Create setting
  ok = ptReg.addSetting("ID", "123");

// Read setting
  idValue = ptReg.getSetting("ID");

// Update setting
  ok = ptReg.updateSetting("ID", "456");

// Delete setting
  ok = ptReg.deleteSetting("ID");

Note: the alternate form of each of the above methods may be used instead by specifying a value of false for both the global and anonymous parameters. That is,

  ok = ptReg.addSetting("ID", "123");

is equivalent to

  ok = ptReg.addSetting(false, false, "ID", "123");

2. General settings for a proxy tool instance

These settings apply to all users for a single proxy tool instance; for example, this could be used to save configuration settings made by a section designer or instructor.

  boolean ok;
  String idValue;

// Create setting
  ok = ptReg.addSetting(false, true, "default", "All");

// Read setting
  idValue = ptReg.getSetting(false, true, "default");

// Update setting
  ok = ptReg.updateSetting(false, true, "default", "None");

// Delete setting
  ok = ptReg.deleteSetting(false, true, "default");

3. User-specific data for all instances of a proxy tool

These settings apply to all instances of a proxy tool for the same user; for example, this could be used to save general configuration settings for a user.

  boolean ok;
  String idValue;

// Create setting
  ok = ptReg.addSetting(true, false, "autosave", "Yes");

// Read setting
  idValue = ptReg.getSetting(true, false, "autosave");

// Update setting
  ok = ptReg.updateSetting(true, false, "autosave", "No");

// Delete setting
  ok = ptReg.deleteSetting(true, false, "autosave");

4. General settings for all instances of a proxy tool

These settings apply to all users and all instances of a proxy tool within an institution; for example, this could be used to save institution-wide configuration settings for the tool.

  boolean ok;
  String idValue;

  if (isInstitutionAdmin()) {
// Create setting
    ok = ptReg.addSetting(true, true, "enable", "Yes");
  }

// Read setting
  idValue = ptReg.getSetting(true, true, "enable");

  if (isInstitutionAdmin()) {
// Update setting
    ok = ptReg.updateSetting(true, true, "enable", "No");

// Delete setting
    ok = ptReg.deleteSetting(true, true, "enable");
  }

Note: only users who have the institution administrator role are able to add, update and delete settings in this category.

Processing multiple settings

Methods are also provided to process a list of settings at the same time. The getSettings method will return all the settings in the specified category as a Map. It is also possible to limit the list returned to only those settings with names beginning with a specified prefix.

  import java.util.Map;

  ...

  // Get all setting values for the current user in the current proxy tool
  Map userSettings = ptReg.getSettings();

  // Get the values for all anonymous settings for the current proxy tool with names starting with "temp_"
  Map toolSettings = ptReg.getSettings(false, true, "temp_");

The addSettings, updateSettings and deleteSettings methods all process a list of settings supplied as a Map.

Handling long setting values

If the size of the SettingValue field is not sufficient for the data to be stored, then the long settings facility can be used to automatically split larger values across multiple records.

Add/update a long setting

A long setting is added in the same way as a normal setting, except that if a setting of the same name already exists it will always be updated irrespective of the AutoUpdate setting and no record will remain in the database when a setting has an empty values irrespective of the SaveEmptyValues setting.

  boolean ok;
  String description = "This is intended to represent a very long setting value!";

// Create setting
  ok = ptReg.addLongSetting("Description", description);

If, for the sake of this example, the length of the SettingValue field in the database is only 40 characters (not a length which is recommended for a real system!), then the above description value will be stored in two records:

SettingNameSettingValue
Description;1This is intended to represent a very lon
Description;2g value!

The separator between the name of the setting specified in the code ("Description") and the record sequence number (1, 2) defaults to a semicolon but can be changed via the properties file (see above). (The names of any long settings already in the database will need to be updated manually if this property is changed.) The sequence numbers used will always have the same length to preserve their natural sort order (e.g. 01, 02, ..., 10, 11). The setting name should be short enough to allow the separator and the sequence number to be appended without exceeding the size of the SettingName field (which is 256 characters by default).

Accessing the value of a long setting

Using the normal getSetting method will normally return an empty string for a long setting because no record exists with that name; the name for a long setting has a separator and sequence number appended to it. Thus, to retrieve the value for a long setting the getLongSetting method should be used so that the relevant sequence of records can be concatenated. There are two main versions of this method, one which accesses the database to retrieve the relevant records, and one which extracts these from a map of settings which has already been retrieved:

  TreeMap settings = new TreeMap();
  String description = null;

// Retrieve a long setting
  description = ptReg.getLongSetting("Description");

// Alternatively retrieve all settings and then extract a long setting
  settings = ptReg.getSettings();
  description = ptReg.getLongSetting(settings, "Description");

// This long setting can now also be accessed as a normal setting from the Map
  description = settings.get("Description");

Deleting a long setting

A long setting should be deleted by using the deleteLongSetting method. This is equivalent to adding a long setting with no value.

  TreeMap settings = new TreeMap();
  String description = null;

// Retrieve a long setting
  ok = ptReg.deleteLongSetting("Description");

Deleting an instance

The resources associated with an instance of the Proxy Tool Registry may be released by calling the close method; for example:

  if (ptReg != null) {
    ptReg.close();
  }

Version history

VersionDateDescription
1.0.0013-Dec-2008Initial release

Licence

Creative Commons License This work is written by Stephen Vickers and is released under a Creative Commons GNU General Public Licence. The ProxyToolRegistry package is downloadable from OSCELOT where it is also possible to report bugs and submit feature requests.

Valid XHTML 1.0 Strict