コード例 #1
0
  protected String getDropSQL(DatabaseObjectType type, String name) {
    SQLObject foundDropQuery = null;
    String sqlStatement = "DROP " + type.toString() + " " + name;

    for (SQLObject dropQuery : catalogStore.getDropStatements()) {
      if (type == dropQuery.getType()) {
        foundDropQuery = dropQuery;
        break;
      }
    }

    if (foundDropQuery != null
        && foundDropQuery.getSql() != null
        && !foundDropQuery.getSql().isEmpty()) {
      String dropStatement = foundDropQuery.getSql();
      StringBuffer sqlBuffer = new StringBuffer(dropStatement.length() + name.length());
      int identifier = dropStatement.indexOf('?');

      sqlBuffer
          .append(dropStatement.substring(0, identifier))
          .append(name)
          .append(dropStatement.substring(identifier + 1));
      sqlStatement = sqlBuffer.toString();
    }

    return sqlStatement;
  }
コード例 #2
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());
    }
  }