Esempio n. 1
0
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   b.append("ALTER TABLE ").append(table.getFullyQualifiedName()).append(" ADD ");
   if (columnName != null) {
     b.append("COLUMN ").append(columnName).append(" ").append(dataType.toString());
   } else if (pkColumns != null) {
     b.append("PRIMARY KEY (").append(PlainSelect.getStringList(pkColumns)).append(")");
   } else if (ukColumns != null) {
     b.append("UNIQUE KEY ")
         .append(ukName)
         .append(" (")
         .append(PlainSelect.getStringList(ukColumns))
         .append(")");
   } else if (fkColumns != null) {
     b.append("FOREIGN KEY (")
         .append(PlainSelect.getStringList(fkColumns))
         .append(") REFERENCES ")
         .append(fkSourceTable)
         .append(" (")
         .append(PlainSelect.getStringList(fkSourceColumns))
         .append(")");
     if (isOnDeleteCascade()) {
       b.append(" ON DELETE CASCADE");
     } else if (isOnDeleteRestrict()) {
       b.append(" ON DELETE RESTRICT");
     } else if (isOnDeleteSetNull()) {
       b.append(" ON DELETE SET NULL");
     }
   } else if (fkIndex != null) {
     b.append(fkIndex);
   }
   return b.toString();
 }
Esempio n. 2
0
  @Override
  public String toString() {
    String sql = "";

    sql = "CREATE " + (unlogged ? "UNLOGGED " : "") + "TABLE " + table;

    if (select != null) {
      sql += " AS " + select.toString();
    } else {
      sql += " (";

      sql += PlainSelect.getStringList(columnDefinitions, true, false);
      if (indexes != null && indexes.size() != 0) {
        sql += ", ";
        sql += PlainSelect.getStringList(indexes);
      }
      sql += ")";
      String options = PlainSelect.getStringList(tableOptionsStrings, false, false);
      if (options != null && options.length() > 0) {
        sql += " " + options;
      }
    }

    return sql;
  }
Esempio n. 3
0
  public void deParse(Update update) {
    buffer
        .append("UPDATE ")
        .append(PlainSelect.getStringList(update.getTables(), true, false))
        .append(" SET ");
    for (int i = 0; i < update.getColumns().size(); i++) {
      Column column = update.getColumns().get(i);
      buffer.append(column.getFullyQualifiedName()).append(" = ");

      Expression expression = update.getExpressions().get(i);
      expression.accept(expressionVisitor);
      if (i < update.getColumns().size() - 1) {
        buffer.append(", ");
      }
    }

    if (update.getFromItem() != null) {
      buffer.append(" FROM ").append(update.getFromItem());
      if (update.getJoins() != null) {
        for (Join join : update.getJoins()) {
          if (join.isSimple()) {
            buffer.append(", ").append(join);
          } else {
            buffer.append(" ").append(join);
          }
        }
      }
    }

    if (update.getWhere() != null) {
      buffer.append(" WHERE ");
      update.getWhere().accept(expressionVisitor);
    }
  }
Esempio n. 4
0
 @Override
 public String toString() {
   return type
       + " "
       + PlainSelect.getStringList(columnsNames, true, true)
       + (name != null ? " " + name : "");
 }