com.ibm.pvccommon.util
Class IniDatabase

java.lang.Object
  |
  +--java.util.Observable
        |
        +--com.ibm.pvccommon.util.Database
              |
              +--com.ibm.pvccommon.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 "properties" 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 "bin" would be installPath\properties, 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).


Inner classes inherited from class com.ibm.pvccommon.util.Database
Database.ResourceType
 
Field Summary
static java.lang.String COPYRIGHT
           
 
Fields inherited from class com.ibm.pvccommon.util.Database
COPYRIGHT, DEFAULT, EMPTY_STRING, ORIGINAL_VALUE, purpose, sections, SERVER, SERVER_GROUP, SUBSET_ASSOCIATION, subsetList, typeNames, USER, USER_GROUP
 
Constructor Summary
protected IniDatabase(java.lang.String name)
          Construct this IniDatabase with the given name for the default resource type.
protected IniDatabase(java.lang.String name, boolean readOnly, Database.ResourceType type)
          Construct this IniDatabase with the given name for the given resource type specifying explicitly whether or not it is readOnly
protected IniDatabase(java.lang.String name, Database.ResourceType type)
          Construct this IniDatabase with the given name for the given resource type.
 
Method Summary
 void deleteDatabase()
          Delete the database -- that is, delete the preference context
 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.
 boolean hasEncodedCharacters(java.lang.String name)
          Answer whether the given string has encoded characters.
 void loadDatabase()
          Load the database
 void loadDatabase(java.lang.String filename)
          Load a subset of the database, where a subset is a collection or related DatabaseSections.
 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)
          Test program.
 void prepareForInitialLoad()
          Prepare for the initial load of a database, when it is first being loaded.
 void removeSection(java.lang.String name)
          Remove a section from the active database.
 void saveDatabase(java.lang.String subsetName)
          Save a named subset of the database.
 void saveSection(java.lang.String sectionName)
          Save 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 install directory up in system properties.
 
Methods inherited from class com.ibm.pvccommon.util.Database
backoutChanges, commitChanges, createSection, exists, getLoadedSection, getName, getSection, getSections, getSections, getSubsetNames, getType, getTypeName, getWhetherChangesPersist, isCoalesced, saveDatabase, saveSection, setPurpose, size, toString
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
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,
                      Database.ResourceType type)
Construct this IniDatabase with the given name for the given resource type.
Parameters:
name - name of the database
type - resource type this database is associated with

IniDatabase

protected IniDatabase(java.lang.String name)
Construct this IniDatabase with the given name for the default resource type.
Parameters:
name - name of the database

IniDatabase

protected IniDatabase(java.lang.String name,
                      boolean readOnly,
                      Database.ResourceType type)
Construct this IniDatabase with the given name for the given resource type specifying explicitly whether or not it is readOnly
Parameters:
name - name of the database
readOnly - whether or not this is to be readOnly
type - resource type this database is associated with
Method Detail

setHomeKey

protected static void setHomeKey(java.lang.String key)
Method to modify key used to look install directory up in system properties.
Parameters:
key - the value of the new key

loadDatabase

public void loadDatabase()
Load the database
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)
Load a subset of the database, where a subset is a collection or related DatabaseSections. The multiple sections of the database that comprise the subset are loaded from a single file in persistent storage. The file type is assumed to be ".ini", and the file is assumed to follow .ini file conventions (section names in brackets, followed by key-value pairs on separate lines, sections separated by blank lines, etc.)
Overrides:
loadDatabase in class Database
Parameters:
filename - Name of the subset to be loaded; the name is used as the database filename to load from;

loadSection

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

deleteDatabase

public void deleteDatabase()
Delete the database -- that is, delete the preference context
Overrides:
deleteDatabase in class Database
Tags copied from class: Database
Throws:
MissingRequiredResourceException -  

saveDatabase

public void saveDatabase(java.lang.String subsetName)
Save a named subset of the database. In this case, the subset is associated with a particular file.
Overrides:
saveDatabase in class Database
Parameters:
filename - name of subset to be saved -- also used as the name of the file to be saved to.

saveSection

public void saveSection(java.lang.String sectionName)
Save a single DatabaseSection to a file with the same name as the section name + .prop
Overrides:
saveSection in class Database
Parameters:
section - to save

getEncodedName

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

getDecodedName

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

hasEncodedCharacters

public boolean hasEncodedCharacters(java.lang.String name)
Answer whether the given string has encoded characters. The assumption here is that we would not expect to find the delimiter character followed by the index (which starts at 0x01) in our text names. If this is not guaranteed to be the case then this method should not be used
Overrides:
hasEncodedCharacters in class Database
Parameters:
name - the name to check
Returns:
true if has encoded characters, false otherwise

removeSection

public void removeSection(java.lang.String name)
Description copied from class: Database
Remove a section from the active database. Specific database implementations should override this method to remove the section from persistent storage, but call this method in the superclass to remove the section from active use.
Overrides:
removeSection in class Database
Tags copied from class: Database
Parameters:
name - The name of the section.

main

public static void main(java.lang.String[] args)
Test program. See source file for information on this test program.
Parameters:
args - The arguments. section this is associated with