DatabaseEdit.java :  » J2EE » Enhydra-Application-Framework » org » enhydra » server » Java Open Source

Java Open Source » J2EE » Enhydra Application Framework 
Enhydra Application Framework » org » enhydra » server » DatabaseEdit.java
/**
 * Title:        AdminGui
 * Description:  Edit DatabaseManager parameters from configuration file.
 * @Author       tufeX, tufex@uns.ns.ac.yu & Vladimir Radisic
 * @Version      1.1.0
 */

package org.enhydra.server;

import org.enhydra.util.ConfigFileInterface;

import com.lutris.util.Config;
import com.lutris.util.ConfigException;
import com.lutris.util.KeywordValueException;

/**
 * Instances of this class are used in manipulation and editing of DatabaseManager
 * section parameters, defined in application configuration file. Also this class
 * contains method saveState which provides saving changed configuration onto disk.
 */
public class DatabaseEdit {

/**
 * Array of database names used within application.
 */
  private String [] databases = null;

/**
 * Current database. This variable points to database, which parmeters are
 * currently holding in the temporary private variables of the object.
 */
  private String currentDatabase = null;

/**
 * Temporary storage for current database parameters. This parameters are an image
 * of parameters from the configuration file of the application, which are led
 * width DatabaseManager section. Parameters are invoked only in aim of faster
 * response in getter methods (otherwise they can be found fromConfig object).
 */
  private String defaultDatabase = "N/A";
  private String debug = "N/A";
  private String dBnameClassType = "N/A";
  private String dBnameJdbcDriver = "N/A";
  private String dBnameConnectionUrl = "N/A";
  private String dBnameConnectionUser = "N/A";
  private String dBnameConnectionPassword = "N/A";
  private String dBnameConnectionMaxPoolSize = "N/A";
  private String dBnameConnectionAllocationTimeout = "N/A";
  private String dBnameConnectionLogging = "N/A";
  private String dBnameObjectIdCacheSize = "N/A";
  private String dBnameObjectIdMinValue = "N/A";

/**
 * Storage for application configure parameters represented as Config object
 */
  private Config configTemp;

/**
 * Storage for application configure parameters represented as Config object. this
 * is reference to original application configuration file.
 */
  private Config configOriginal;

/**
 * Construction of DatabaseEdit object for particular application with given
 * configuration file.
 * @param config configuration file of the application represented as Config
 * object.
 * @exception ConfigException
 * @exception KeywordValueException
 */
  public DatabaseEdit (Config config) throws ConfigException, KeywordValueException {
    this.configOriginal = config; // saving reference to original Config object
    this.configTemp = config.getClonedConfig(); // template Config file used for manipulation

    if(configTemp.containsKey("DatabaseManager.Databases"))
      databases = configTemp.getStrings("DatabaseManager.Databases");
    if(configTemp.containsKey("DatabaseManager.DefaultDatabase")) {
      defaultDatabase = configTemp.getString("DatabaseManager.DefaultDatabase");
      currentDatabase =defaultDatabase;
    }
    if (configTemp.containsKey("DatabaseManager.Debug"))
      debug = configTemp.getString("DatabaseManager.Debug");
    if (currentDatabase == null && databases != null)
      currentDatabase = databases[0];

    this.refreshAllDbParameters(currentDatabase);
  }

/**
 * Finds all parameters for specified database in configuration file and sets
 * they to temporary object arguments.
 * @param dBname name of database which parameters are searched.
 * @exception KeywordValueException
 */
  public void refreshAllDbParameters(String dBname) throws KeywordValueException {

    this.databases = null;
    this.currentDatabase = null;

    this.defaultDatabase = "N/A";
    this.debug = "N/A";
    this.dBnameClassType = "N/A";
    this.dBnameJdbcDriver = "N/A";
    this.dBnameConnectionUrl = "N/A";
    this.dBnameConnectionUser = "N/A";
    this.dBnameConnectionPassword = "N/A";
    this.dBnameConnectionMaxPoolSize = "N/A";
    this.dBnameConnectionAllocationTimeout = "N/A";
    this.dBnameConnectionLogging = "N/A";
    this.dBnameObjectIdCacheSize = "N/A";
    this.dBnameObjectIdMinValue = "N/A";

    Config tempParentConfig = null;
//    Config tempConfig = (Config) configTemp.getSection("DatabaseManager.");
    Config tempConfig = (Config) configTemp.getSection("DatabaseManager");
    if (tempConfig != null) {
      if(tempConfig.containsKey("Databases")) {
        this.databases = tempConfig.getStrings("Databases");
// checks given parameter (dBname) for existing in configTemp file
        if(this.existDbName(dBname))
          this.currentDatabase = dBname;
      }
      if(tempConfig.containsKey("DefaultDatabase"))
        defaultDatabase = tempConfig.getString("DefaultDatabase");

      if (tempConfig.containsKey("Debug"))
        debug = tempConfig.getString("Debug");

      if(currentDatabase == null)
        return;

// Finds parameters for specified database
      tempParentConfig = tempConfig;
      tempConfig = (Config) tempConfig.getSection("DB." + dBname);
      if(tempConfig!=null) {
        if (tempConfig.containsKey("ClassType"))
          dBnameClassType = tempConfig.getString("ClassType");
        if (tempConfig.containsKey("JdbcDriver"))
          dBnameJdbcDriver = tempConfig.getString("JdbcDriver");

        tempParentConfig = tempConfig;
        tempConfig = (Config) tempConfig.getSection("Connection");
        if(tempConfig!=null) {
          if (tempConfig.containsKey("Url"))
            dBnameConnectionUrl = tempConfig.getString("Url");
          if (tempConfig.containsKey("User"))
            dBnameConnectionUser = tempConfig.getString("User");
          if (tempConfig.containsKey("Password"))
            dBnameConnectionPassword = tempConfig.getString("Password");
          if (tempConfig.containsKey("MaxPoolSize"))
            dBnameConnectionMaxPoolSize = tempConfig.getString("MaxPoolSize");
          if (tempConfig.containsKey("AllocationTimeout"))
            dBnameConnectionAllocationTimeout = tempConfig.getString("AllocationTimeout");
          if (tempConfig.containsKey("Logging"))
            dBnameConnectionLogging = tempConfig.getString("Logging");
        }
        tempConfig = tempParentConfig;
        tempConfig = (Config) tempConfig.getSection("ObjectId");
        if(tempConfig!=null) {
          if (tempConfig.containsKey("CacheSize"))
            dBnameObjectIdCacheSize = tempConfig.getString("CacheSize");
          if (tempConfig.containsKey("MinValue"))
            dBnameObjectIdMinValue = tempConfig.getString("MinValue");
        }
      }
    }
  }

/**
 * Checks existence of given database name in the list of already defined
 * databases for application.
 * @param dBname the name of the database.
 * @return true = database name already exists, false = database name does not
 * exist.
 */
public boolean existDbName(String dBname) {
  if(dBname == null || databases == null)
    return false;
  for (int i = 0; i < this.databases.length; i++) {
    if (databases[i].equalsIgnoreCase(dBname))
      return true;
  }
  return false;

}

/**
 * Adds database name to list of databases used by application. This list is
 * represented by "Datasbase" parameter in configuration file of the application.
 * @param dBname the name of the database.
 * @return true = database name is sucessfuly added, false = database name is
 * not added.
 * @exception KeywordValueException
 */
  public boolean addDatabase(String dBname) throws KeywordValueException{
    if(this.existDbName(dBname))
      return false;

    String[] newDbString = null;
    if(this.databases == null) //handles adding of first item in database list
      newDbString = new String[1];
    else
      newDbString = new String[this.databases.length+1];

    newDbString[newDbString.length-1] = dBname;

    for (int i = 0; i < newDbString.length-1; i++)
      newDbString[i] = this.databases[i];

    this.configTemp.set("DatabaseManager.Databases", newDbString);
    this.databases = newDbString;

// sets initial values for all parameters. This values should be later changed
// width real values
    this.setDBnameClassType("Standard", dBname);
    this.setDBnameJdbcDriver("sun.jdbc.odbc.JdbcOdbcDriver", dBname);
    this.setDBnameConnectionAllocationTimeout("10000", dBname);
    this.setDBnameConnectionLogging("false", dBname);
    this.setDBnameConnectionMaxPoolSize("30", dBname);
    this.setDBnameConnectionUrl("jdbc:odbc:"+dBname, dBname);
    this.setDBnameConnectionPassword("tiger", dBname);
    this.setDBnameConnectionUser("miga", dBname);
    this.setDBnameObjectIdCacheSize("20", dBname);
    this.setDBnameObjectIdMinValue("1000000", dBname);

    return true;
  }

/**
 * Removes database name from array of databases used by application. This list is
 * represented by "Datasbase" parameter in configuration file of the application.
 * @param dBname the name of the database.
 * @return true = database name is sucessfuly removed, false = database name is
 * not removed.
 * @exception KeywordValueException
 */
  public boolean removeDatabase(String dBname) throws KeywordValueException {
    if(!this.existDbName(dBname))
      return false;
    String[] newDbString = new String[this.databases.length-1];

    for (int i=0,j=0; i < newDbString.length; i++) {
      if(!this.databases[j].equalsIgnoreCase(dBname))
        newDbString[i] = this.databases[j];
      else
        i--;
      j++;
    }

    if(this.currentDatabase!=null && this.currentDatabase.equalsIgnoreCase(dBname)) {
      this.currentDatabase = null;
    }

// remowes all keys connected with removed database;
    String testDefaultDb = null;
    if(configTemp.containsKey("DatabaseManager.DefaultDatabase"))
      testDefaultDb = (String)configTemp.get("DatabaseManager.DefaultDatabase");
    if( (testDefaultDb!=null && !testDefaultDb.trim().equals("")) &&
        testDefaultDb.equalsIgnoreCase(dBname)) {
      this.configTemp.remove("DatabaseManager.DefaultDatabase");
      this.defaultDatabase = "N/A";
    }

    this.configTemp.remove("DatabaseManager.DB." + dBname + ".ClassType");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".JdbcDriver");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Logging");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Url");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Password");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.User");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize");
    this.configTemp.remove("DatabaseManager.DB." + dBname + ".ObjectId.MinValue");

    if(newDbString.length == 0) { //handles removing of last item in database list
      this.configTemp.remove("DatabaseManager.Databases");
      this.databases = null;
      this.currentDatabase = null;
    }
    else {
      this.configTemp.set("DatabaseManager.Databases", newDbString);
      this.databases = newDbString;
    }
    return true;
  }

/**
 * Sets list of database names. Old settings are remowed and are swapped with
 * given new list. All corresponding database parameters, for given database names
 * in list, with its default initial values will be added too
 * @param databases list of database names.
 * @exception KeywordValueException
 */
  public void setDatabases(String [] databases) throws KeywordValueException {
    String newDbParam = "";
    StringBuffer newDbParamBuffer = new StringBuffer(newDbParam);
    for (int i = 0; i < databases.length; i++) {
      if(i==0)
        newDbParamBuffer = new StringBuffer("\"" + this.databases[i] + "\"");
      else
        newDbParamBuffer.append(", \"" + this.databases[i] + "\"");
    }
    newDbParam = newDbParamBuffer.toString();
// removes all keys connected width old database parameters
    for (int i = 0; i < this.databases.length; i++) {
      this.removeDatabase(databases[i]);
    }

    this.configTemp.set("DatabaseManager.Databases", newDbParam);
    this.databases = databases;

// adds keys for new database parameters
    for (int i = 0; i < this.databases.length; i++) {
      this.addDatabase(databases[i]);
    }

  }

/**
 * Gets list of available database names.
 * @return list of available databases represented as String array
 * @exception KeywordValueException
 */
  public String[] getDatabases() {
    return this.databases;
  }

/**
 * Sets value of ClassType parameter for given database name in Config
 * object of application.
 * @param value given value of ClassType parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameClassType(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameClassType = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".ClassType", "");
      }
      else {
        this.dBnameClassType = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".ClassType", value);
      }
    }
  }

/**
 * Gets value of ClassType parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameClassType( String dBname) throws KeywordValueException {
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameClassType;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.AllocationTimeout parameter for given database name
 * in Config object of application.
 * @param value given value of Connection.AllocationTimeout parameter represented
 * as String.
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionAllocationTimeout(String value, String dBname) throws KeywordValueException {
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameConnectionAllocationTimeout = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout", "");
      }
      else {
        this.dBnameConnectionAllocationTimeout = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout", value);
      }
    }
  }

  /**
   * Gets value of Connection. AllocationTimeout parameter for given database name
   * from Config object of application.
   * @param dBname name of database which parameter's value is changed or set.
   * @return value of parameter represented as String
   * @throws KeywordValueException
   */
  public String getDBnameConnectionAllocationTimeout( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionAllocationTimeout;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.Logging parameter for given database name in Config
 * object of application.
 * @param value given value of Connection.Logging parameter represented as String.
 * Allowable values for this parameter are "true" and "false". Any other value
 * will be treated as N/A (not available).
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionLogging(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("") ||
        !(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) ) {
        this.dBnameConnectionLogging = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Logging", "");
      }
      else {
        this.dBnameConnectionLogging = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Logging", value);
      }
    }
  }

/**
 * Gets value of Connection.Logging parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String. It could has values "true",
 * "false" or "N/A" in case of parameter absence.
 * @throws KeywordValueException
 */
  public String getDBnameConnectionLogging( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionLogging;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.MaxPoolSize parameter for given database name in Config
 * object of application.
 * @param value given value of Connection.MaxPoolSize parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionMaxPoolSize(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameConnectionMaxPoolSize = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize", "");
      }
      else {
        this.dBnameConnectionMaxPoolSize = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize", value);
      }
    }
  }

/**
 * Gets value of Connection.MaxPoolSize parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameConnectionMaxPoolSize( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionMaxPoolSize;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.Password parameter for given database name in Config
 * object of application.
 * @param value given value of Connection.Password parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionPassword(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameConnectionPassword = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Password", "");
      }
      else {
        this.dBnameConnectionPassword = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Password", value);
      }
    }
  }

/**
 * Gets value of Connection.Password parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameConnectionPassword( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionPassword;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.Url parameter for given database name in Config
 * object of application.
 * @param value given value of Connection.Url parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionUrl(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameConnectionUrl = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Url", "");
      }
      else {
        this.dBnameConnectionUrl = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Url", value);
      }
    }
  }

/**
 * Gets value of Connection.Url parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameConnectionUrl( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionUrl;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Connection.User parameter for given database name in Config
 * object of application.
 * @param value given value of Connection.User parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameConnectionUser(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameConnectionUser = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.User", "");
      }
      else {
        this.dBnameConnectionUser = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".Connection.User", value);
      }
    }
  }

/**
 * Gets value of Connection.User parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameConnectionUser( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameConnectionUser;
    }
    else
      return "N/A";
  }

/**
 * Sets value of JdbcDriver parameter for given database name in Config
 * object of application.
 * @param value given value of JdbcDriver parameter represented as String.
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameJdbcDriver(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameJdbcDriver = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".JdbcDriver", "");
      }
      else {
        this.dBnameJdbcDriver = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".JdbcDriver", value);
      }
    }
  }

/**
 * Gets value of JdbcDriver parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameJdbcDriver( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameJdbcDriver;
    }
    else
      return "N/A";
  }

/**
 * Sets value of ObjectId.CacheSize parameter for given database name in Config
 * object of application.
 * @param value given value of ObjectId.CacheSize parameter represented as String.
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameObjectIdCacheSize(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameObjectIdCacheSize = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize", "");
      }
      else {
        this.dBnameObjectIdCacheSize = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize", value);
      }
    }
  }

/**
 * Gets value of ObjectId.CacheSize parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameObjectIdCacheSize( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameObjectIdCacheSize;
    }
    else
      return "N/A";
  }

/**
 * Sets value of ObjectId.MinValue parameter for given database name in Config
 * object of application.
 * @param value given value of ObjectId.MinValue parameter represented as String
 * @param dBname name of database which parameter's value is changed or set.
 * @throws KeywordValueException
 */
  public void setDBnameObjectIdMinValue(String value, String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      if(value==null || value.trim().equals("")) {
        this.dBnameObjectIdMinValue = "N/A";
        configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.MinValue", "");
      }
      else {
        this.dBnameObjectIdMinValue = value;
        configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.MinValue", value);
      }
    }
  }

/**
 * Gets value of ObjectId.MinValue parameter for given database name from Config
 * object of application.
 * @param dBname name of database which parameter's value is changed or set.
 * @return value of parameter represented as String
 * @throws KeywordValueException
 */
  public String getDBnameObjectIdMinValue( String dBname) throws KeywordValueException{
    if(this.existDbName(dBname)) {
      if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
        this.refreshAllDbParameters(dBname);
      return this.dBnameObjectIdMinValue;
    }
    else
      return "N/A";
  }

/**
 * Sets value of Debug parameter in Config object of application.
 * @param debug value of parameter represented as String. It can takes values
 * "true" or "false". If wrong value is specified, it will be treated as "false".
 * Also if values are null or empty String, or "N/A" DatabaseManager.Debug parameter
 * will be removed.
 * @throws KeywordValueException
 */
  public void setDebug(String debug) throws KeywordValueException{
    if(debug==null || debug.trim().equals("") || debug.equalsIgnoreCase("N/A")) {
      this.debug = "N/A";
      configTemp.remove("DatabaseManager.Debug");
    }
    else if(debug.equalsIgnoreCase("true")) {
      this.debug = debug;
      configTemp.set("DatabaseManager.Debug", debug);
    }
    else {
      this.debug = "false";
      configTemp.set("DatabaseManager.Debug", "false");
    }
  }

/**
 * Gets value of Debug parameter in Config object of application.
 * @return value of parameter represented as String. It could has values
 * "true", "false" or "N/A" in case of parameter absence.
 * @throws KeywordValueException
 */
  public String getDebug() throws KeywordValueException {
    this.refreshAllDbParameters(null);
    return this.debug;
  }

/**
 * Sets value of DefaultDatabase parameter in Config object of application.
 * @param dBname given value of parameter DefaultDatabase represented as String.
 * @throws KeywordValueException
 */
  public void setDefaultDatabase(String dBname) throws KeywordValueException {
    if(this.existDbName(dBname)) {
      configTemp.set("DatabaseManager.DefaultDatabase",dBname);
      this.defaultDatabase = dBname;
    }
    else if(dBname==null || dBname.trim().equals(""))
      configTemp.remove("DatabaseManager.DefaultDatabase");
      this.defaultDatabase = "N/A";
  }

/**
 * Gets value of DefaultDatabase parameter in Config object of application.
 * @return value of parameter represented as String.
 * @throws KeywordValueException
 */
  public String getDefaultDatabase() throws KeywordValueException {
    this.refreshAllDbParameters(null);
    return this.defaultDatabase;
  }

/**
 * Save state of DatabaseManager configuration parameters into application
 * configuration file.
 * @return true = state is successfully saved, false = otherwise
 */
  public boolean saveState(){
    try{
      this.configOriginal.importConfig(this.configTemp);
      ConfigFileInterface confFile = configOriginal.getConfigFile();
      confFile.write();
    }
    catch(Exception e) {
      return false;
    }
    return true;
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.