DbtuTools project
Java Library

org.dbtutools.DbtuTools.core
Class ConfigService

java.lang.Object
  |
  +--org.dbtutools.DbtuTools.core.ConfigService

public class ConfigService
extends java.lang.Object

One of the central services offered to all the DbtuTools tools (of course, others can use them as well).

The class works as a wrapper, covering the configuration stuff and hiding the different Config Sources and their types. Currently, Unix configuration files located in the /opt/dbtutools tree [UNIX][Wintel] are the only Config Source type, but other configuration file types like Windows INI, XML etc. as well as directory services like LDAP might be an option too.

More information about the Unix configuration file format can be found in the detailed description of the UnixCfgParser class.

Author:
Daniel Scheibli <daniel.scheibli at edelbyte.org>

Field Summary
static int CONFIG_SOURCE_UNIXCFG
          Constant standing for a Unix Configuration files as Config Source.
static int CONFIG_SOURCE_UNKNOWN
          Constant standing for an unknown Config Source.
protected  int iConfigSourceType
          Field holding the Config Source type.
protected  java.util.Hashtable oDatabaseNames
          Field holding the given DB2 Database name(s).
protected  java.util.Hashtable oDatabaseProperties
          Field holding the Database level properties read from the Config Source.
protected  java.lang.String oInstanceName
          Field holding the given DB2 Instance name.
protected  java.util.Properties oInstanceProperties
          Field holding the Instance level properties read from the Config Source.
protected  java.lang.String oOptTreeInstanceCfg
          Field holding the path for the DB2 Instance configuration files within the /opt/dbtutools tree.
protected  java.lang.String oOptTreeRoot
          Field holding the machine wide /opt/dbtutools tree root.
 
Constructor Summary
ConfigService()
          Creates a new instance of this class which addresses the current DB2 Instance, but no DB2 database(s).
ConfigService(java.lang.String oInstanceName)
          Creates a new instance of this class which addresses the given DB2 Instance, but no DB2 database(s).
ConfigService(java.lang.String oInstanceName, java.lang.String oDatabaseName)
          Creates a new instance of this class which addresses the given DB2 Instance, as well as the given DB2 database.
ConfigService(java.lang.String oInstanceName, java.lang.String[] oDatabaseNames)
          Creates a new instance of this class which addresses the given DB2 Instance, as well as the given DB2 database(s).
 
Method Summary
protected  void getConfigSourceSettings()
          This method determines how to find and read the Config Sources.
 java.lang.String getProperty(java.lang.String oLevels, java.lang.String oDatabaseName, java.lang.String oKey)
          Searches the different properties fields for the specified property key.
 java.lang.String getProperty(java.lang.String oLevels, java.lang.String oDatabaseName, java.lang.String oKey, java.lang.String oDefaultValue)
          Searches the different properties fields for the specified property key.
 void refresh(boolean bInstanceFlag)
          As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.

Please notice, that this method covers the Config Source for the DB2 Instance only.
 void refresh(boolean bInstanceFlag, java.lang.String oDatabaseName)
          As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.
 void refresh(boolean bInstanceFlag, java.lang.String[] oDatabaseNames)
          As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.
 void refreshAll()
          As the name says, the method (re)reads all Config Sources and stores all found properties in the corresponding object fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_SOURCE_UNKNOWN

public static final int CONFIG_SOURCE_UNKNOWN
Constant standing for an unknown Config Source.

CONFIG_SOURCE_UNIXCFG

public static final int CONFIG_SOURCE_UNIXCFG
Constant standing for a Unix Configuration files as Config Source.

oInstanceName

protected java.lang.String oInstanceName
Field holding the given DB2 Instance name.

oDatabaseNames

protected java.util.Hashtable oDatabaseNames
Field holding the given DB2 Database name(s).

oInstanceProperties

protected java.util.Properties oInstanceProperties
Field holding the Instance level properties read from the Config Source.

oDatabaseProperties

protected java.util.Hashtable oDatabaseProperties
Field holding the Database level properties read from the Config Source.

oOptTreeRoot

protected java.lang.String oOptTreeRoot
Field holding the machine wide /opt/dbtutools tree root.

oOptTreeInstanceCfg

protected java.lang.String oOptTreeInstanceCfg
Field holding the path for the DB2 Instance configuration files within the /opt/dbtutools tree.

iConfigSourceType

protected int iConfigSourceType
Field holding the Config Source type.
Constructor Detail

ConfigService

public ConfigService()
              throws UnknownValueException
Creates a new instance of this class which addresses the current DB2 Instance, but no DB2 database(s). During the instantiation, the refresh(boolean, java.lang.String[]) method is called implicitly.
Throws:
UnknownValueException - For the case, that the name of the current DB2 Instance could not be detected. If the /opt/dbtutools tree could not be located, the exception is thrown as well.

ConfigService

public ConfigService(java.lang.String oInstanceName)
              throws UnknownValueException
Creates a new instance of this class which addresses the given DB2 Instance, but no DB2 database(s). During the instantiation, the refresh(boolean, java.lang.String[]) method is called implicitly.
Parameters:
oInstanceName - The DB2 Instance to be addressed. If null is given, the current DB2 Instance will be used.
Throws:
UnknownValueException - For the case, that the name of the current DB2 Instance could not be detected. If the /opt/dbtutools tree could not be located, the exception is thrown as well.

ConfigService

public ConfigService(java.lang.String oInstanceName,
                     java.lang.String oDatabaseName)
              throws UnknownValueException
Creates a new instance of this class which addresses the given DB2 Instance, as well as the given DB2 database. During the instantiation, the refresh(boolean, java.lang.String[]) method is called implicitly.
Parameters:
oInstanceName - The DB2 Instance to be addressed. If null is given, the current DB2 Instance will be used.
oDatabaseName - The DB2 Database to be addressed. If null is given, no DB2 Database will be used.
Throws:
UnknownValueException - For the case, that the name of the current DB2 Instance could not be detected. If the /opt/dbtutools tree could not be located, the exception is thrown as well.

ConfigService

public ConfigService(java.lang.String oInstanceName,
                     java.lang.String[] oDatabaseNames)
              throws UnknownValueException
Creates a new instance of this class which addresses the given DB2 Instance, as well as the given DB2 database(s). During the instantiation, the refresh(boolean, java.lang.String[]) method is called implicitly.
Parameters:
oInstanceName - The DB2 Instance to be addressed. If null is given, the current DB2 Instance will be used.
oDatabaseNames - The DB2 Database(s) to be addressed. If null is given, no DB2 Databases will be used.
Throws:
UnknownValueException - For the case, that the name of the current DB2 Instance could not be detected. If the /opt/dbtutools tree could not be located, the exception is thrown as well.
Method Detail

getConfigSourceSettings

protected void getConfigSourceSettings()
                                throws UnknownValueException
This method determines how to find and read the Config Sources. Therefore it reads the dbtuswitch.cfg file [UNIX][Wintel] and stores the information in the object fields.

The method is called by the refresh(boolean, java.lang.String[]) method.
Throws:
UnknownValueException - For the case, that the dbtuswitch.cfg could not be found or read. If there is no entry for the DB2 instance (addressed by this object), the exception is thrown as well.

getProperty

public java.lang.String getProperty(java.lang.String oLevels,
                                    java.lang.String oDatabaseName,
                                    java.lang.String oKey)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.NullPointerException
Searches the different properties fields for the specified property key.
Parameters:
oLevels - Defines the levels to search, as well as the search order. "I" stands for the DB2 Instance level and "D" stands for the DB2 Database level. Of course you can combine them to "DI" or "ID". Please notice that every defined level is searched whether there was a match in before or not. So the last match wins.
oDatabaseName - The name of the DB2 Database to search the properties. If null is given, the DB2 Instance properties are searched only.
oKey - The properties key (ignoring case considerations).
Throws:
java.lang.IllegalArgumentException - For the case there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.

getProperty

public java.lang.String getProperty(java.lang.String oLevels,
                                    java.lang.String oDatabaseName,
                                    java.lang.String oKey,
                                    java.lang.String oDefaultValue)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.NullPointerException
Searches the different properties fields for the specified property key.
Parameters:
oLevels - Defines the levels to search, as well as the search order. "I" stands for the DB2 Instance level and "D" stands for the DB2 Database level. Of course you can combine them to "DI" or "ID". Please notice that every defined level is searched whether there was a match in before or not. So the last match wins.
oDatabaseName - The name of the DB2 Database to search the properties. If null is given, the DB2 Instance properties are searched only.
oKey - The properties key (ignoring case considerations).
oDefaultKey - For the case, that there was no match, this default value is returned.
Throws:
java.lang.IllegalArgumentException - For the case there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.

refresh

public void refresh(boolean bInstanceFlag)
             throws java.lang.IllegalArgumentException,
                    java.lang.NullPointerException,
                    UnknownValueException
As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.

Please notice, that this method covers the Config Source for the DB2 Instance only.
Parameters:
bInstanceFlag - Indicates whether or not the properties for the DB2 Instance should be (re)read. When called with false, this method has nothing to do.
Throws:
java.lang.IllegalArgumentException - For the case, that there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.
UnknownValueException - For the case, that the Config Source could not be read.

refresh

public void refresh(boolean bInstanceFlag,
                    java.lang.String oDatabaseName)
             throws java.lang.IllegalArgumentException,
                    java.lang.NullPointerException,
                    UnknownValueException
As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.
Parameters:
bInstanceFlag - Indicates whether or not the properties for the DB2 Instance should be (re)read.
oDatabaseName - The name of the DB2 Database for which the properties should be (re)read. If null is given, no DB2 Databases are taken into account.
Throws:
java.lang.IllegalArgumentException - For the case, that there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.
UnknownValueException - For the case, that the Config Source could not be read.

refresh

public void refresh(boolean bInstanceFlag,
                    java.lang.String[] oDatabaseNames)
             throws java.lang.IllegalArgumentException,
                    java.lang.NullPointerException,
                    UnknownValueException
As the name says, the method (re)reads the Config Sources and stores all found properties in the corresponding object fields.
Parameters:
bInstanceFlag - Indicates whether or not the properties for the DB2 Instance should be (re)read.
oDatabaseNames - The name of the DB2 Database(s) for which the properties should be (re)read. If null is given, no DB2 Databases are taken into account.
Throws:
java.lang.IllegalArgumentException - For the case, that there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.
UnknownValueException - For the case, that the Config Source could not be read.

refreshAll

public void refreshAll()
                throws java.lang.IllegalArgumentException,
                       java.lang.NullPointerException,
                       UnknownValueException
As the name says, the method (re)reads all Config Sources and stores all found properties in the corresponding object fields. The method internally calls the refresh(boolean, java.lang.String[]) method.
Throws:
java.lang.IllegalArgumentException - For the case, that there is an invalid parameter.
java.lang.NullPointerException - If one of the arguments was null.
UnknownValueException - For the case, that the Config Source could not be read.

DbtuTools project
Java Library