com.ibm.wbi.util
Class IniDatabase

java.lang.Object
  |
  +--com.ibm.wbi.util.Database
        |
        +--com.ibm.wbi.util.IniDatabase

public final class IniDatabase
extends Database

IniDatabase is an implementation of Database that uses multiple local files as its persistent storage. All of the files have either ".ini" or ".prop" file extensions.

The directory structure depends on the type of database. For a SERVER database, the files are in the directory named installPath + File.separator + Database.name (where "etc" is the Database name used for the Transproxy server database). Other types of databases are in installPath + separator + typename + separator + databasename. Thus, the directory for files on Windows NT corresponding to server database named "etc" would be installPath\etc, while the directory for the USER database for STEVE would be installPath\USER\STEVE. See the typeNames defined in Database.

A Database object contains a collection of DatabaseSection objects. These can be stored either in individial property files, or in database subset files that contain multiple sections.

The .ini files contain the information for multiple DatabaseSections. For these files, the DatabaseSection name is given in square brackets and the property values follow as key=value pairs. Section definitions are separated by one or more blank lines.

The .prop files contain only a single DatabaseSection. For these files, the property name is inferred from the name of the file, and is not specified explicitly.

Multiple-section files are loaded in one operation. It is not possible to load individual DatabaseSections from these files. However, when they are are saved, sections that have not been changed by the application are written out exactly as they were read in. Sections that have been changed are written out using the Properties save() facility, which causes a time stamp comment to be added to that section of the .ini file.

Single-section files are loaded and saved independently.

If the directory assumed by this object does not already exist, the object will attempt to create it. This may be useful for an system that creates and saves DatabaseSections before loading them.

The application can add sections either to a subset (which maps to a particular .ini file) or independently (which maps to a single *.prop file using the section name as the file name).


Field Summary
static java.lang.String COPYRIGHT
           
 
Fields inherited from class com.ibm.wbi.util.Database
COPYRIGHT, DEFAULT, purpose, ras, sections, SERVER, SERVER_GROUP, typeNames, USER, USER_GROUP
 
Constructor Summary
protected IniDatabase(java.lang.String name)
          Creates a new IniDatabase.
protected IniDatabase(java.lang.String name, boolean readOnly, int type)
          Creates a new IniDatabase.
protected IniDatabase(java.lang.String name, int type)
          Creates a new IniDatabase.
 
Method Summary
 DatabaseSection createSection(java.lang.String sectionName)
           
 DatabaseSection createSection(java.lang.String sectionName, java.lang.String thisSubsetName)
           
 java.lang.String getDecodedName(java.lang.String name)
          Decode the given name to
 java.lang.String getEncodedName(java.lang.String name)
          Encode the given name to make sure it is a valid properties name.
 java.lang.Object getObjectValue(DatabaseSection section, java.lang.String key, java.lang.Object defaultValue)
          Get the value associated with the specified key (within the major key grouping).
 void loadDatabase()
          ------------------------ Load methods ----------------------------- The database can have sections loaded either from individual or multiple section files.
 void loadDatabase(java.lang.String filename)
          Loads multiple sections of the database from a file in persistent storage.
 DatabaseSection loadSection(java.lang.String propertyName)
          loadSection reads in a single DatabaseSection for a file whose name matches the property name + .prop
static void main(java.lang.String[] args)
           
 void prepareForInitialLoad()
          Prepare for the initial load of a database, when it is first being loaded.
 void removeIfObjectValue(DatabaseSection section, java.lang.String value)
          Remove the value with the given key if it is an object value grouping).
 void saveDatabase()
          Saves entire database to multiple files in persistent storage.
 void saveDatabase(java.lang.String filename)
          Saves a named subset of the database.
 void saveSection(DatabaseSection section)
          Saves a single DatabaseSection to a file with the same name as the section name + .prop
protected static void setHomeKey(java.lang.String key)
          Method to modify key used to look up install directory in system properties.
 void setObjectValue(DatabaseSection section, java.lang.String key, java.lang.Object value)
          Sets the specified key equal to the passed value.
 
Methods inherited from class com.ibm.wbi.util.Database
exists, getLoadedSection, getName, getSection, getSections, getType, getTypeName, removeSection, setPurpose, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

IniDatabase

protected IniDatabase(java.lang.String name,
                      int type)
Creates a new IniDatabase.
Parameters:
name - Name of database.
type - Type of database.

IniDatabase

protected IniDatabase(java.lang.String name)
Creates a new IniDatabase.
Parameters:
name - Name of database.

IniDatabase

protected IniDatabase(java.lang.String name,
                      boolean readOnly,
                      int type)
Creates a new IniDatabase.
Parameters:
name - Name of database.
readOnly - If true, database to be created is read-only.
type - Type of database.
Method Detail

setHomeKey

protected static void setHomeKey(java.lang.String key)
Method to modify key used to look up install directory in system properties.
Parameters:
key - Key for install directory lookup.

createSection

public DatabaseSection createSection(java.lang.String sectionName)
Overrides:
createSection in class Database

createSection

public DatabaseSection createSection(java.lang.String sectionName,
                                     java.lang.String thisSubsetName)
Overrides:
createSection in class Database

loadDatabase

public void loadDatabase()
------------------------ Load methods ----------------------------- The database can have sections loaded either from individual or multiple section files. The first method implies that there is file: installpath + separator + ... + name + separator + name.ini -------------------------------------------------------------------
Overrides:
loadDatabase in class Database

prepareForInitialLoad

public void prepareForInitialLoad()
Prepare for the initial load of a database, when it is first being loaded. Subsequent loads of the database may not invoke this method, if the database user wants the effects of loadDatabase() operations to be cumulative.
Overrides:
prepareForInitialLoad in class Database

loadDatabase

public void loadDatabase(java.lang.String filename)
Loads multiple sections of the database from a file in persistent storage.
Parameters:
filename - Name of file, file type is assumed to be ".ini".
Overrides:
loadDatabase in class Database

loadSection

public DatabaseSection loadSection(java.lang.String propertyName)
loadSection reads in a single DatabaseSection for a file whose name matches the property name + .prop
Parameters:
propertyName - Name of property to load.
Returns:
Database section.
Overrides:
loadSection in class Database

saveDatabase

public void saveDatabase()
Saves entire database to multiple files in persistent storage.
Overrides:
saveDatabase in class Database

saveDatabase

public void saveDatabase(java.lang.String filename)
Saves a named subset of the database. In this case, the subset is associated with a particular file.
Parameters:
filename - Name of the file to save the database in.
Overrides:
saveDatabase in class Database

saveSection

public void saveSection(DatabaseSection section)
Saves a single DatabaseSection to a file with the same name as the section name + .prop
Parameters:
section - Datbase section to be stored.
Overrides:
saveSection in class Database

getEncodedName

public java.lang.String getEncodedName(java.lang.String name)
Encode the given name to make sure it is a valid properties name.
Parameters:
name - string to encode
Returns:
encoded result
Overrides:
getEncodedName in class Database

getDecodedName

public java.lang.String getDecodedName(java.lang.String name)
Decode the given name to
Parameters:
name - string to decode
Returns:
decoded result
Overrides:
getDecodedName in class Database

getObjectValue

public java.lang.Object getObjectValue(DatabaseSection section,
                                       java.lang.String key,
                                       java.lang.Object defaultValue)
Get the value associated with the specified key (within the major key grouping).
Parameters:
section - The database section this is associated with
key - The minor key.
defaultValue - defaultValue to use if no value found for key
Returns:
defaultValue if key not available or the value is returned.
Overrides:
getObjectValue in class Database

removeIfObjectValue

public void removeIfObjectValue(DatabaseSection section,
                                java.lang.String value)
Remove the value with the given key if it is an object value grouping).
Parameters:
section - The database section this is associated with
value - The value to check
Overrides:
removeIfObjectValue in class Database

setObjectValue

public void setObjectValue(DatabaseSection section,
                           java.lang.String key,
                           java.lang.Object value)
Sets the specified key equal to the passed value. By default, changes are saved to persistent storage after this function call.
Parameters:
section - The database section this is associated with
key - The minor key.
value - The new value.
Overrides:
setObjectValue in class Database

main

public static void main(java.lang.String[] args)