示例#1
0
  /**
   * @param application
   * @param propertyName
   * @return
   * @throws ValidationException
   */
  @Override
  public Property addProperty(Application application, String propertyName)
      throws ValidationException {
    Application app = applicationDAO.findById(application.getId());

    if (app == null) {
      String[] inserts = new String[] {application.getId().toString()};
      throw validationException(INVALID_APPLICATION_MESSAGE, inserts);
    }

    for (Property p : app.getPropertyList()) {
      if (p.getName().equals(propertyName)) {
        String[] inserts = new String[] {propertyName, app.getName()};
        throw validationException(DUPLICATE_PROPERTY_MESSAGE, inserts);
      }
    }

    Property p = new Property();
    p.setName(propertyName);
    app.addProperty(p);
    p = propertyDAO.create(p);

    for (Environment e : app.getEnvironmentList()) {
      EnvironmentProperty ep = new EnvironmentProperty();
      ep.setEnvironment(e);
      ep.setProperty(p);
      environmentPropertyDAO.create(ep);
    }

    return p;
  }
 /**
  * Get a property
  *
  * @param cat The category of the configuration property
  * @param propKey The property key
  * @param defVal The default value to return if the requested property does not exist.
  * @return The property value.
  */
 public String getProperty(String cat, String propKey, String defVal) {
   Property prop = _dao.getProperty(cat, propKey);
   if (prop == null) {
     return defVal;
   } else {
     return prop.getValue();
   }
 }
 /**
  * Update the configuration properties for a category
  *
  * @param cat The category of the configuration properties
  * @param key The property key of the configuration properties
  * @param value The new value of the configuration properties
  * @return status
  */
 public boolean updateProperties(String cat, String key, String value) {
   boolean status = false;
   int result = _dao.updateProperty(cat, key, value);
   if (result != -1) {
     status = true;
   }
   return status;
 }
  /**
   * Get the configuration properties for a category
   *
   * @param cat The category of the configuration properties
   * @return The Properties for a category
   */
  public Properties getProperties(String cat) {
    Properties props = new Properties();
    List propList = _dao.getPropertyList(cat);
    if (propList != null) {
      for (Object obj : propList) {
        Property prop = (Property) obj;
        if (prop.getValue() != null) {
          props.put(prop.getKey(), prop.getValue());
        }
      }
    }

    return props;
  }
 /**
  * #1105 - TWX 20091107 Acquire a row lock on the Property identified by the given cat and key.
  *
  * @param cat The category of the configuration properties
  * @param key The property key of the configuration properties
  * @return true if the db can lock the given property record. false if other thread already
  *     locking the record.
  * @throws Throwable if system level exception occured
  */
 public boolean lockProperty(String cat, String key) throws Throwable {
   return _dao.lockPropertyNoWait(cat, key);
 }