示例#1
0
  public void upgradeBaseSchema(Connection conn, int currentVersion) {
    if (!isLoaded()) {
      throw new TajoInternalError("Database schema files are not loaded.");
    }

    final List<SchemaPatch> candidatePatches = new ArrayList<>();
    Statement stmt;

    for (SchemaPatch patch : this.catalogStore.getPatches()) {
      if (currentVersion >= patch.getPriorVersion()) {
        candidatePatches.add(patch);
      }
    }

    Collections.sort(candidatePatches);
    try {
      stmt = conn.createStatement();
    } catch (SQLException e) {
      throw new TajoInternalError(e);
    }

    for (SchemaPatch patch : candidatePatches) {
      for (DatabaseObject object : patch.getObjects()) {
        try {
          stmt.executeUpdate(object.getSql());
          LOG.info(object.getName() + " " + object.getType() + " was created or altered.");
        } catch (SQLException e) {
          throw new TajoInternalError(e);
        }
      }
    }

    CatalogUtil.closeQuietly(stmt);
  }
示例#2
0
    protected void mergePatches(List<SchemaPatch> patches) {
      final List<DatabaseObject> objects = new ArrayList<>();

      Collections.sort(patches);

      for (SchemaPatch patch : patches) {
        validatePatch(patches, patch);

        objects.clear();
        List<DatabaseObject> tempObjects = new ArrayList<>();
        tempObjects.addAll(patch.getObjects());
        patch.clearObjects();
        patch.addObjects(mergeDatabaseObjects(tempObjects));

        targetStore.addPatch(patch);
      }
    }
示例#3
0
    protected void validatePatch(List<SchemaPatch> patches, SchemaPatch testPatch) {
      if (testPatch.getPriorVersion() > testPatch.getNextVersion()) {
        throw new TajoInternalError("Prior version cannot proceed to next version of patch.");
      }

      for (SchemaPatch patch : patches) {
        if (testPatch.equals(patch)) {
          continue;
        }

        if (testPatch.getPriorVersion() == patch.getPriorVersion()) {
          LOG.warn("It has the same prior version (" + testPatch.getPriorVersion() + ") of patch.");

          if (testPatch.getNextVersion() == patch.getNextVersion()) {
            throw new TajoInternalError(
                "Duplicate versions of patch found. It will terminate Catalog Store. ");
          }
        }

        if (testPatch.getNextVersion() == patch.getNextVersion()) {
          LOG.warn("It has the same next version (" + testPatch.getPriorVersion() + ") of patch.");
        }
      }
    }