public void translate(AlterTable alterTable) throws SQLException {
    Table table = alterTable.getTable();
    for (AlterOperation alterOperation : alterTable.getAlterOperations()) {
      switch (alterOperation.getType()) {
        case ADD:
          {
            AddColumn addColumn = (AddColumn) alterOperation;
            String schemaName = Helper.getSchemaName(this.connector, table);
            String dataType = addColumn.getColumnDefinition().getColDataType().getDataType();
            String columnName = addColumn.getColumnDefinition().getColumnName();
            Integer domainId, type3domainId;
            if ((domainId = getFuzzyDomainId(schemaName, dataType, "5")) != null) {
              type3domainId = Helper.getType3DomainIdRelated(connector, domainId);

              operations.add(
                  new AddFuzzyColumnOperation(
                      connector, schemaName, table.getName(), columnName, domainId, type3domainId));
            }
            break;
          }
        case DROP:
          {
            DropColumn dropColumn = (DropColumn) alterOperation;
            String schemaName = Helper.getSchemaName(this.connector, table);
            String columnName = dropColumn.getColumnOld();
            operations.add(
                new RemoveFuzzyColumnsOperation(
                    connector, schemaName, table.getName(), columnName));
            break;
          }
      }
    }
  }
Beispiel #2
0
  public static String getDomainNameForColumn(Connector c, Table table, String columnName)
      throws SQLException {
    String schemaName = Helper.getSchemaName(c, table);
    String tableName = table.getName();
    String sql =
        "SELECT domain_name "
            + "FROM information_schema_fuzzy.domains AS D JOIN "
            + "information_schema_fuzzy.columns AS C ON (D.domain_id = C.domain_id) "
            + "WHERE C.table_schema = '"
            + schemaName
            + "' "
            + "AND C.table_name = '"
            + tableName
            + "' "
            + "AND C.column_name = '"
            + columnName
            + "'";

    Logger.debug("Looking for domain name with query:\n" + sql);

    ResultSet rs = c.executeRawQuery(sql);
    SQLException e = null;
    try {
      if (rs.first()) {
        return rs.getString("domain_name");
      }
    } catch (SQLException ex) {
      e = ex;
    }
    throw new SQLException(
        "Domain name not found for " + schemaName + "." + tableName + "." + columnName,
        "42000",
        3020,
        e);
  }
 @Override
 public void visit(Drop drop) throws Exception {
   // TODO Auto-generated method stub
   String type = drop.getType();
   if ("TABLE".equalsIgnoreCase(type)) {
     String table = drop.getName();
     operations.add(
         new RemoveFuzzyColumnsOperation(connector, Helper.getSchemaName(connector), table));
   } else if ("FUZZY DOMAIN".equalsIgnoreCase(type)) {
     // TODO remove fuzzy
     operations.add(new DropFuzzyDomainOperation(connector, drop.getName()));
     // Mark this statement to be ignored by the translation execution.
     // This means this statement, when deparsed, won't make sense for the
     // RDBMS.
     this.ignoreAST = true;
   }
 }