/**
   * Intended to be called by doValidationExternal.
   *
   * @param rSession the rets session
   * @param hSession the hibernate session
   * @exception HibernateException if an error occurs
   */
  private void doValidationExternalType(Session hSession) throws HibernateException {
    MetadataTable tValidationExternalTypes =
        getMetadataTable(MetadataTable.VALIDATION_EXTERNAL_TYPE);

    Iterator i = mValidationExternals.values().iterator();
    while (i.hasNext()) {
      ValidationExternal ve = (ValidationExternal) i.next();
      Set hValdationExternalTypes = new HashSet();
      List validationExternalTypes = tValidationExternalTypes.getDataRows(ve.getPath());
      if (validationExternalTypes != null) {
        Iterator j = validationExternalTypes.iterator();
        while (j.hasNext()) {
          Metadata md = (Metadata) j.next();
          ValidationExternalType vet = new ValidationExternalType();

          vet.setValidationExternal(ve);

          String joinedSearchField = md.getAttribute("SearchField");
          String searchField[] = StringUtils.split(joinedSearchField, ",");
          Set searchFieldSet = new HashSet();
          for (int c = 0; c < searchField.length; c++) {
            searchFieldSet.add(StringUtils.trimToEmpty(searchField[c]));
          }
          vet.setSearchField(searchFieldSet);

          String joinedDisplayField = md.getAttribute("DisplayField");
          String displayFields[] = StringUtils.split(joinedDisplayField, ",");
          Set displayFieldSet = new HashSet();
          for (int c = 0; c < displayFields.length; c++) {
            displayFieldSet.add(StringUtils.trimToEmpty(displayFields[c]));
          }
          vet.setDisplayField(displayFieldSet);

          String joinedResultField = md.getAttribute("ResultFields");
          String resultFields[] = StringUtils.split(joinedResultField, ",");
          Map resultFieldMap = new HashMap();
          for (int c = 0; c < resultFields.length; c++) {
            String split[] = StringUtils.split(resultFields[c], "=", 2);
            resultFieldMap.put(
                StringUtils.trimToEmpty(split[0]), StringUtils.trimToEmpty(split[1]));
          }
          vet.setResultFields(resultFieldMap);

          vet.updateLevel();
          hSession.save(vet);
        }
        ve.setValidationExternalTypes(hValdationExternalTypes);
      }
    }
  }
  private void doValidationExternal(Session hSession) throws HibernateException {
    MetadataTable tValidationExternals = getMetadataTable(MetadataTable.VALIDATION_EXTERNAL);

    Iterator i = mResources.values().iterator();
    while (i.hasNext()) {
      Resource resource = (Resource) i.next();
      Set hValidationExternals = new HashSet();
      List validationExternals = tValidationExternals.getDataRows(resource.getPath());
      if (validationExternals != null) {
        Iterator j = validationExternals.iterator();
        while (j.hasNext()) {
          Metadata md = (Metadata) j.next();
          ValidationExternal hValidationExternal = new ValidationExternal();

          hValidationExternal.setResource(resource);

          hValidationExternal.setValidationExternalName(md.getAttribute("ValidationExternalName"));

          // get the search class
          String path = md.getAttribute("SearchResource") + ":" + md.getAttribute("SearchClass");
          MClass clazz = (MClass) mClasses.get(path);
          hValidationExternal.setSearchClass(clazz);

          hValidationExternal.updateLevel();

          hSession.save(hValidationExternal);
          hValidationExternals.add(hValidationExternal);
          mValidationExternals.put(hValidationExternal.getPath(), hValidationExternal);
        }
      }
      resource.setValidationExternals(hValidationExternals);
      hSession.saveOrUpdate(resource);
    }
  }