Ejemplo n.º 1
0
  /**
   * Print a list of definitions in different format: fqdn, vdlt, and vdlx
   *
   * @param writer the target to output the list
   * @param defList a list of definitions
   * @param format the output format
   * @see #FORMAT_FQDN
   * @see #FORMAT_VDLT
   * @see #FORMAT_VDLX NOTE: might be better to move into another module?
   */
  public void printDefinitionList(Writer writer, java.util.List defList, int format)
      throws IOException {
    if (defList == null || defList.isEmpty()) return;
    Definitions defs = new Definitions();
    if (format != FORMAT_FQDN) {
      defs.setDefinition(defList);
      if (format == FORMAT_VDLX) defs.toXML(writer, "");
      else if (format == FORMAT_VDLT) defs.toString(writer);
    } else {
      for (Iterator i = defList.iterator(); i.hasNext(); ) {
        Definition def = (Definition) i.next();

        writer.write(def.identify());
        writer.write("\n");
      }
      writer.flush();
    }
  }
Ejemplo n.º 2
0
 /**
  * This method adds the given Definition to whatever storage is implemented underneath.
  *
  * @param d is the Definition that is ready to be stored.
  * @return true, if new version was stored and database modified
  */
 public boolean store(VDL d) {
   if (d instanceof Definition) {
     this.m_memory = (Definition) d;
     Logging.instance().log("chunk", 0, "found " + m_memory.shortID());
     return true;
   } else {
     Logging.instance().log("chunk", 0, "not a definition: " + d.toString());
     return false;
   }
 }
Ejemplo n.º 3
0
  /**
   * This method implements the interface defined in DefinitionHandler to save definition to
   * database backend.
   *
   * @param d is the Definition that is ready to be stored.
   * @return true, if new version was stored and database modified, false, if the definition was
   *     rejected for any reason.
   */
  public boolean store(Definition d) {
    boolean result = false;
    VDC vdc = (VDC) m_dbschema;

    // NEW: remember all DVs we came across
    if (m_derivations != null && d instanceof Derivation) m_derivations.add(d.shortID());

    try {
      if (m_rejects == null) {
        // rely on saveDefinition to do "the right thing"
        result = vdc.saveDefinition(d, m_overwrite);
      } else {
        // Is the Definition already in the database?
        if (vdc.containsDefinition(d)) {
          if (m_overwrite) {
            // this is time-consuming and ineffective
            Definition old =
                vdc.loadDefinition(d.getNamespace(), d.getName(), d.getVersion(), d.getType());
            old.toXML(m_rejects, "  ");
            result = vdc.saveDefinition(d, true);
          } else {
            // skip, if not forced to overwrite, but save rejects
            d.toXML(m_rejects, "  ");
          }
        } else {
          // not found, insert unconditionally
          result = vdc.saveDefinition(d, true);
        }
      }
    } catch (SQLException sql) {
      // database problems
      for (int i = 0; sql != null; ++i) {
        m_logger.log(
            "database", 0, "SQL error " + i + ": " + sql.getErrorCode() + ": " + sql.getMessage());
        sql = sql.getNextException();
      }
      m_logger.log("database", 0, "ignoring SQL exception(s)");
    } catch (Exception e) {
      m_logger.log("database", 0, "caught " + e + ", ignoring");
      result = false;
    }

    if (result) m_count++;
    else m_rejected++;
    return result;
  }