Beispiel #1
0
  public String addTableBody(Table table) {
    String name = SQLStringVisitor.escapeSinglePart(table.getName());
    append(name);

    if (table.getColumns() != null) {
      append(SPACE);
      append(LPAREN);
      boolean first = true;
      for (Column c : table.getColumns()) {
        if (first) {
          first = false;
        } else {
          append(COMMA);
        }
        visit(table, c);
      }
      buildContraints(table);
      append(NEWLINE);
      append(RPAREN);
    }

    // options
    String options = buildTableOptions(table);
    if (!options.isEmpty()) {
      append(SPACE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN);
    }
    return name;
  }
Beispiel #2
0
  private void visit(Table table) {
    if (this.filter != null && !filter.matcher(table.getName()).matches()) {
      return;
    }

    append(CREATE).append(SPACE);
    if (table.isPhysical()) {
      append(FOREIGN_TABLE);
    } else {
      if (table.getTableType() == Table.Type.TemporaryTable) {
        append(GLOBAL).append(SPACE).append(TEMPORARY).append(SPACE).append(TABLE);
      } else {
        append(VIEW);
      }
    }
    append(SPACE);
    String name = addTableBody(table);

    if (table.getTableType() != Table.Type.TemporaryTable) {
      if (table.isVirtual()) {
        append(NEWLINE)
            .append(SQLConstants.Reserved.AS)
            .append(NEWLINE)
            .append(table.getSelectTransformation());
      }
      append(SQLConstants.Tokens.SEMICOLON);

      if (table.isInsertPlanEnabled()) {
        buildTrigger(name, null, INSERT, table.getInsertPlan());
      }

      if (table.isUpdatePlanEnabled()) {
        buildTrigger(name, null, UPDATE, table.getUpdatePlan());
      }

      if (table.isDeletePlanEnabled()) {
        buildTrigger(name, null, DELETE, table.getDeletePlan());
      }

      for (Trigger tr : table.getTriggers().values()) {
        buildTrigger(name, tr.getName(), tr.getEvent().name(), tr.getPlan());
      }
    } else {
      append(SQLConstants.Tokens.SEMICOLON);
    }
  }