示例#1
0
 /** Creates a new Config object and stores the default values in it. */
 protected Config(WoT myWoT) {
   mWoT = myWoT;
   mDB = mWoT.getDB();
   mStringParams = new HashMap<String, String>();
   mIntParams = new HashMap<String, Integer>();
   setDefaultValues(false);
 }
示例#2
0
  /**
   * Loads an existing Config object from the database and adds any missing default values to it,
   * creates and stores a new one if none exists.
   *
   * @return The config object.
   */
  public static Config loadOrCreate(WoT myWoT) {
    ExtObjectContainer db = myWoT.getDB();
    synchronized (db.lock()) {
      Config config;
      ObjectSet<Config> result = db.queryByExample(Config.class);

      if (result.size() == 0) {
        Logger.debug(myWoT, "Creating new Config...");
        config = new Config(myWoT);
        config.storeAndCommit();
      } else {
        if (result.size() > 1) /* Do not throw, we do not want to prevent WoT from starting up. */
          Logger.error(myWoT, "Multiple config objects stored!");

        Logger.debug(myWoT, "Loaded config.");
        config = result.next();
        config.initializeTransient(myWoT);
        config.setDefaultValues(false);
      }

      return config;
    }
  }
示例#3
0
 protected void initializeTransient(WoT myWoT) {
   mWoT = myWoT;
   mDB = myWoT.getDB();
 }