Esempio n. 1
0
  public void dropBaseSchema(Connection conn) {
    if (!isLoaded()) {
      throw new TajoInternalError("Schema files are not loaded yet.");
    }

    List<DatabaseObject> failedObjects = new ArrayList<>();
    Statement stmt = null;

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

    for (DatabaseObject object : catalogStore.getSchema().getObjects()) {
      try {
        if (DatabaseObjectType.TABLE == object.getType()
            || DatabaseObjectType.SEQUENCE == object.getType()
            || DatabaseObjectType.VIEW == object.getType()) {
          stmt.executeUpdate(getDropSQL(object.getType(), object.getName()));
        }
      } catch (SQLException e) {
        failedObjects.add(object);
      }
    }
    CatalogUtil.closeQuietly(stmt);

    if (failedObjects.size() > 0) {
      StringBuffer errorMessage = new StringBuffer(64);
      errorMessage.append("Failed to drop database objects ");

      for (int idx = 0; idx < failedObjects.size(); idx++) {
        DatabaseObject object = failedObjects.get(idx);
        errorMessage.append(object.getType().toString()).append(" ").append(object.getName());
        if ((idx + 1) < failedObjects.size()) {
          errorMessage.append(',');
        }
      }

      LOG.warn(errorMessage.toString());
    }
  }
Esempio n. 2
0
    protected List<DatabaseObject> mergeDatabaseObjects(List<DatabaseObject> objects) {
      int maxIdx = -1;

      for (DatabaseObject object : objects) {
        maxIdx = Math.max(maxIdx, object.getOrder());
      }

      final List<DatabaseObject> orderedObjects = createListAndFillNull(maxIdx);
      final List<DatabaseObject> unorderedObjects = new ArrayList<>();
      final List<DatabaseObject> mergedObjects = new ArrayList<>();

      for (DatabaseObject object : objects) {
        if (object.getOrder() > -1) {
          int objIdx = object.getOrder();

          if (objIdx < orderedObjects.size() && orderedObjects.get(objIdx) != null) {
            throw new TajoInternalError(
                "This catalog configuration contains duplicated order of DatabaseObject");
          }

          orderedObjects.add(objIdx, object);
        } else {
          unorderedObjects.add(object);
        }
      }

      for (DatabaseObject object : orderedObjects) {
        if (object != null) {
          mergedObjects.add(object);
        }
      }

      for (DatabaseObject object : unorderedObjects) {
        if (object != null) {
          mergedObjects.add(object);
        }
      }

      return mergedObjects;
    }