Java Code Examples for liquibase.util.StringUtils#splitAndTrim()

The following examples show how to use liquibase.util.StringUtils#splitAndTrim() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public String escapeColumnNameList(final String columnNames) {
    StringBuilder sb = new StringBuilder();
    for (String columnName : StringUtils.splitAndTrim(columnNames, ",")) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        boolean descending = false;
        if (columnName.matches("(?i).*\\s+DESC")) {
            columnName = columnName.replaceFirst("(?i)\\s+DESC$", "");
            descending = true;
        } else if (columnName.matches("(?i).*\\s+ASC")) {
            columnName = columnName.replaceFirst("(?i)\\s+ASC$", "");
        }
        sb.append(escapeObjectName(columnName, Column.class));
        if (descending) {
            sb.append(" DESC");
        }
    }
    return sb.toString();
}
 
Example 2
@Override
public String generateAlterStatement(Database database) {
    StringBuilder alter = new StringBuilder();

    alter.append("ADD ");
    if (StringUtil.isNotEmpty(getConstraintName())) {
        alter.append("CONSTRAINT ");
        alter.append(database.escapeConstraintName(getConstraintName()));
        alter.append(" ");
    }
    alter.append("UNIQUE (");
    List<String> columns = StringUtils.splitAndTrim(getColumnNames(), ",");
    if (columns == null) columns = Collections.emptyList();
    alter.append(database.escapeColumnNameList(StringUtils.join(columns, ", ")));
    alter.append(")");

    return alter.toString();
}
 
Example 3
@Override
public String generateAlterStatement(Database database) {
    StringBuilder alter = new StringBuilder();

    alter.append("ADD CONSTRAINT ");
    if (StringUtil.isNotEmpty(getConstraintName())) {
        alter.append(database.escapeConstraintName(getConstraintName())).append(" ");
    }
    alter.append("FOREIGN KEY ");

    alter.append("(");
    List<String> baseColumns = StringUtils.splitAndTrim(getBaseColumnNames(), ",");
    if (baseColumns == null) baseColumns = Collections.emptyList();
    alter.append(database.escapeColumnNameList(StringUtils.join(baseColumns, ", ")));
    alter.append(") ");

    alter.append("REFERENCES ");
    String referencedTable = PerconaChangeUtil.resolveReferencedPerconaTableName(getBaseTableName(), getReferencedTableName());
    alter.append(database.escapeTableName(getReferencedTableCatalogName(), getReferencedTableSchemaName(), referencedTable)).append(" ");
    alter.append("(");
    List<String> referencedColumns = StringUtils.splitAndTrim(getReferencedColumnNames(), ",");
    if (referencedColumns == null) referencedColumns = Collections.emptyList();
    alter.append(database.escapeColumnNameList(StringUtils.join(referencedColumns, ", ")));
    alter.append(")");

    if (getOnDelete() != null) {
        alter.append(" ON DELETE ").append(getOnDelete());
    }
    if (getOnUpdate() != null) {
        alter.append(" ON UPDATE ").append(getOnUpdate());
    }

    if (getDeferrable() != null && getDeferrable()) {
        alter.append(" DEFERRABLE");
    }
    if (getInitiallyDeferred() != null && getInitiallyDeferred()) {
        alter.append(" INITIALLY DEFERRED");
    }

    return alter.toString();
}