Exemplo n.º 1
0
  private void doUpdate(Session hSession) throws HibernateException {
    MetadataTable tUpdates = getMetadataTable(MetadataTable.UPDATE);

    Iterator i = mClasses.values().iterator();
    while (i.hasNext()) {
      MClass clazz = (MClass) i.next();
      Set hUpdates = new HashSet();
      List updates = tUpdates.getDataRows(clazz.getPath());
      if (updates != null) {
        Iterator j = updates.iterator();
        while (j.hasNext()) {
          Metadata md = (Metadata) j.next();
          Update hUpdate = new Update();

          hUpdate.setMClass(clazz);

          hUpdate.setUpdateName(md.getAttribute("UpdateName"));
          hUpdate.setDescription(md.getAttribute("Description"));
          hUpdate.setKeyField(md.getAttribute("KeyField"));

          hUpdate.updateLevel();

          hSession.save(hUpdate);
          hUpdates.add(hUpdate);
          mUpdates.put(hUpdate.getPath(), hUpdate);
        }
      }
      clazz.setUpdates(hUpdates);
      hSession.saveOrUpdate(clazz);
    }
  }
 private void loadMetadata() throws RetsServerException {
   MetadataLoader loader = new MetadataLoader();
   MSystem system = loader.parseMetadataDirectory();
   Iterator j = system.getResources().iterator();
   while (j.hasNext()) {
     Resource res = (Resource) j.next();
     Iterator k = res.getClasses().iterator();
     while (k.hasNext()) {
       MClass clazz = (MClass) k.next();
       mClasses.put(clazz.getPath(), clazz);
       Iterator l = clazz.getTables().iterator();
       while (l.hasNext()) {
         Table table = (Table) l.next();
         mTables.put(table.getPath(), table);
       }
     }
   }
 }
Exemplo n.º 3
0
  private void doClasses(Session hSession) throws HibernateException {
    MetadataTable tClass = getMetadataTable(MetadataTable.CLASS);

    Iterator i = mResources.values().iterator();
    while (i.hasNext()) {
      Resource resource = (Resource) i.next();
      Set hClasses = new HashSet();
      List classes = tClass.getDataRows(resource.getPath());
      Iterator j = classes.iterator();
      while (j.hasNext()) {
        Metadata md = (Metadata) j.next();
        MClass hClass = new MClass();

        hClass.setResource(resource);
        String className = md.getAttribute("ClassName");
        hClass.setClassName(className);
        hClass.setStandardName(ClassStandardNameEnum.fromString(md.getAttribute("StandardName")));
        hClass.setVisibleName(md.getAttribute("VisibleName"));
        hClass.setDescription(md.getAttribute("Description"));

        StringBuffer tmp = new StringBuffer("rets_");
        tmp.append(resource.getResourceID()).append("_");
        tmp.append(hClass.getClassName());
        hClass.setDbTable(tmp.toString());

        hClass.updateLevel();

        hSession.save(hClass);
        hClasses.add(hClass);
        mClasses.put(hClass.getPath(), hClass);
      }

      resource.setClasses(hClasses);
      hSession.saveOrUpdate(resource);
    }
  }
Exemplo n.º 4
0
  private void doTable(Session hSession) throws HibernateException {
    MetadataTable tTables = getMetadataTable(MetadataTable.TABLE);

    Iterator i = mClasses.values().iterator();
    while (i.hasNext()) {
      MClass hClass = (MClass) i.next();
      Set hTables = new HashSet();
      List tables = tTables.getDataRows(hClass.getPath());
      if (tables != null) {
        Iterator j = tables.iterator();
        while (j.hasNext()) {
          Metadata md = (Metadata) j.next();
          Table hTable = new Table();

          hTable.setMClass(hClass);

          hTable.setSystemName(md.getAttribute("SystemName"));

          String standardName = md.getAttribute("StandardName");
          TableStandardName tsn = lookupTableStandardName(standardName);
          if (tsn == null) {
            if (!standardName.equals("")) {
              tsn = new TableStandardName(standardName);
              mTableStandardNames.put(standardName, tsn);
              hSession.save(tsn);
            }
          }
          hTable.setStandardName(tsn);

          hTable.setLongName(md.getAttribute("LongName"));

          String tmp = md.getAttribute("DbName");
          if (tmp.startsWith("r_")) {
            hTable.setDbName(StringUtils.substring(tmp, 0, 10));
          } else {
            hTable.setDbName(StringUtils.substring("r_" + tmp, 0, 10));
          }

          hTable.setShortName(md.getAttribute("ShortName"));
          hTable.setMaximumLength(Integer.parseInt(md.getAttribute("MaximumLength")));
          hTable.setDataType(DataTypeEnum.fromString(md.getAttribute("DataType")));
          hTable.setPrecision(Integer.parseInt(md.getAttribute("Precision")));
          hTable.setSearchable(boolValue(md.getAttribute("Searchable")));
          hTable.setInterpretation(
              InterpretationEnum.fromString(md.getAttribute("Interpretation")));
          hTable.setAlignment(AlignmentEnum.fromString(md.getAttribute("Alignment")));
          hTable.setUseSeparator(boolValue(md.getAttribute("UseSeparator")));

          String editMasksJoined = md.getAttribute("EditMaskID");
          String resourcePath = hClass.getResource().getPath();
          String path = null;
          Set hEditMasks = new HashSet();
          if (editMasksJoined != null) {
            String editMasks[] = StringUtils.split(editMasksJoined, ",");

            for (int c = 0; c < editMasks.length; c++) {
              path = resourcePath + ":" + StringUtils.trimToEmpty(editMasks[c]);
              EditMask em = (EditMask) mEditMasks.get(path);
              hEditMasks.add(em);
              if (em == null) {
                LOG.error("edit mask null for path: " + path);
              }
            }
          }
          hTable.setEditMasks(hEditMasks);

          String lookupName = md.getAttribute("LookupName");
          path = resourcePath + ":" + lookupName;
          Lookup lookup = (Lookup) mLookups.get(path);
          hTable.setLookup(lookup);

          hTable.setMaxSelect(Integer.parseInt(md.getAttribute("MaxSelect")));

          hTable.setUnits(UnitEnum.fromString(md.getAttribute("Units")));

          hTable.setIndex(Integer.parseInt(md.getAttribute("Index")));

          hTable.setMinimum(Integer.parseInt(md.getAttribute("Minimum")));

          hTable.setMaximum(Integer.parseInt(md.getAttribute("Maximum")));

          hTable.setDefault(Integer.parseInt(md.getAttribute("Default")));

          hTable.setRequired(Integer.parseInt(md.getAttribute("Required")));

          String searchHelpID = md.getAttribute("SearchHelpID");
          path = resourcePath + ":" + searchHelpID;
          SearchHelp searchHelp = (SearchHelp) mSearchHelps.get(path);
          hTable.setSearchHelp(searchHelp);

          // String = md.getAttribute("unique");
          hTable.setUnique(boolValue(md.getAttribute("Unique")));

          hTable.updateLevel();

          hSession.save(hTable);
          hTables.add(hTable);
          mTables.put(hTable.getPath(), hTable);
        }
        hClass.setTables(hTables);
        hSession.saveOrUpdate(hClass);
      }
    }
  }