Exemple #1
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;
  }