Beispiel #1
0
  public void deleteEvent(Event event) {
    List<User> list = getUsers();
    Collection<Activity> activities = event.getActivities();
    Set<Activity> tmpActivities = new HashSet<Activity>();
    for (Activity activityEntity : activities) {
      tmpActivities.add(activityEntity);
    }
    for (User user : list) {
      boolean userUpdated = false;
      if (user.getEvents().contains(event)) {
        for (Activity activity : tmpActivities) {
          user.getActivities().remove(activity);
          event.getActivities().remove(activity);
        }
        user.getEvents().remove(event);
        userUpdated = true;
      }
      if (userUpdated) {
        updateObject(user);
      }
    }

    deleteObject(event);
    //        for (Activity activity : tmpActivities) {
    //            deleteObject(activity);
    //        }
  }
  /* (non-Javadoc)
   * @see org.grails.orm.hibernate.cfg.GrailsDomainConfiguration#addDomainClass(org.codehaus.groovy.grails.commons.GrailsDomainClass)
   */
  public GrailsDomainConfiguration addDomainClass(GrailsDomainClass domainClass) {
    if (shouldMapWithGorm(domainClass)) {
      domainClasses.add(domainClass);
    } else {
      addAnnotatedClass(domainClass.getClazz());
    }

    return this;
  }
  /**
   * internal work for responding to a save or update request. This method will add new bundles data
   * if it doesn't exist, otherwise updates the data preserving any current value if its been
   * modified. This approach allows for upgrades to automatically detect and persist new keys, as
   * well as updating any default values that flow in from an upgrade.
   *
   * @param baseName
   * @param moduleName
   * @param newBundle
   * @param loc
   */
  protected void saveOrUpdateInternal(
      String baseName, String moduleName, Map<String, String> newBundle, String loc) {
    String keyName = getIndexKeyName(baseName, moduleName, loc);
    if (indexedList.contains(keyName)) {
      logger.debug("skip saveOrUpdate() as its already happened once for :" + keyName);
      return;
    }

    Set<Entry<String, String>> entrySet = newBundle.entrySet();
    Iterator<Entry<String, String>> entries = entrySet.iterator();

    while (entries.hasNext()) {
      Entry<String, String> entry = entries.next();
      String key = entry.getKey();
      MessageBundleProperty mbp = new MessageBundleProperty();
      mbp.setBaseName(baseName);
      mbp.setModuleName(moduleName);
      mbp.setLocale(loc.toString());
      mbp.setPropertyName(key);
      mbp.setDefaultValue(entry.getValue());
      MessageBundleProperty existingMbp = getProperty(mbp);
      if (existingMbp != null) {
        // don"t update id or value, we don't want to loose that data
        BeanUtils.copyProperties(mbp, existingMbp, new String[] {"id", "value"});
        logger.debug(
            "updating message bundle data for : "
                + getIndexKeyName(mbp.getBaseName(), mbp.getModuleName(), mbp.getLocale()));
        updateMessageBundleProperty(existingMbp);
      } else {
        logger.debug(
            "adding message bundle data for : "
                + getIndexKeyName(mbp.getBaseName(), mbp.getModuleName(), mbp.getLocale()));
        updateMessageBundleProperty(mbp);
      }
    }

    indexedList.add(getIndexKeyName(baseName, moduleName, loc));
  }