Class Property

Summary

A singleton class that provides global access to a set of persistent properties. Persistent properties are stored in an SQL database and can be retrieved by other program executions. A persistent property is a simple name/value pair that represents an item of information that is available across Unicon applications. The value can be any Unicon type that can be converted to and from a JSON string representation by the json support. Note that this should not include structures containing multiple references to the same structure (e.g. circular graphs, etc.) as the fetched property will not match the saved property.

The base implementation works with PostgreSQL 9.6+ via ODBC. All of the database-specific code can be found in the class propertydb::PropertyUtil, found in the file $UNICON/src/lib/pdb_util.icn which can serve as a template for adapting to different SQL databases. The Property constructor can be passed the string name of the required adaptation class, e.g. "MySQL_utils" (or whatever).

Superclasses:
Object

Package:
lang
File:
property.icn
Methods:
clearAll, count, getAllNames, getAllProperties, getP, getPString, removeP, setP, switchPropertyTable

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Fields:
pdb

Source code.

Details
Constructor

Property(user, passwd:"", dsn, tabl, uClass)

Parameters:
user
name of user owning the database table
passwd
that user's database access password (defaults to "")
dsn
database name as known by ODBC]. The default is the same as the user name
tabl
name of the property table in that database (defaults to "property_table")
uClass
name of the support class for a specific type of SQL database. The default is "propertydb::PropertyUtil" which is suitable for PostgreSQL 9.6+ (and possibly others). See the PropertyDB class for more details.

Construct a singleton Property class.

Methods:

clearAll()

Remove all properties from the database


count()

Returns:
the number of properties

Produce the number of properties.


getAllNames()

Returns:
set of property names

Produce a set of the names of all of the properties.


getAllProperties()

Returns:
table of all the properties

Produce a table containing all of the properties. The keys are the property names.


getP(pName)

Parameter:
pName
name of the property
Returns:
the current value of the named property

Produce a property's value.


getPString(pName)

Parameter:
pName
name of the property
Returns:
the JSON string value of the named property

Produce a property's value as a JSON string.


removeP(pName)

Parameter:
pName
name of property to remove

Remove a property from the database


setP(pName, value)

Parameters:
pName
name of the property
value
value for the named property

Set a property's value.


switchPropertyTable(tableName)

Parameter:
tableName
name of property table to use

Switch to a different property table in the database. Reference properties in a different table. The table must be (and will be created there if not) in the same SQL database as the original.


Fields:
pdb


This page produced by UniDoc on 2021/04/15 @ 23:59:53.