/** * Entry point into the {@link AlterUserTypeSpecification}'s fluent API given {@code typeName} to alter a type. * Convenient if imported statically. * * @param typeName must not be {@literal null} or empty. * @return a new {@link AlterUserTypeSpecification}. */ private static AlterUserTypeSpecification alterType(CqlIdentifier typeName) { return new AlterUserTypeSpecification(typeName); }
/** * Adds an {@literal RENAME} to the list of field changes. * * @param from must not be {@literal null}. * @param to must not be {@literal null} or empty. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification rename(CqlIdentifier from, CqlIdentifier to) { return add(new RenameColumnSpecification(from, to)); }
/** * Entry point into the {@link AlterColumnSpecification}'s fluent API given {@code typeName} to alter a user type. * Convenient if imported statically. * * @param typeName must not be {@literal null} or empty. * @return a new {@link AlterUserTypeSpecification}. */ public static AlterUserTypeSpecification alterType(String typeName) { return alterType(CqlIdentifier.of(typeName)); }
@Override public StringBuilder toCql(StringBuilder cql) { Assert.notNull(getSpecification().getName(), "User type name must not be null"); Assert.isTrue(!getSpecification().getChanges().isEmpty(), String.format("User type [%s] does not contain fields", getSpecification().getName())); return changesCql(preambleCql(cql)).append(";"); }
/** * Adds an {@literal ALTER} to the list of field changes. * * @param field must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification alter(String field, DataType type) { return alter(CqlIdentifier.of(field), type); }
private StringBuilder preambleCql(StringBuilder cql) { return cql.append("ALTER TYPE ").append(spec().getName()).append(' '); }
/** * Adds an {@literal RENAME} to the list of field changes. * * @param from must not be {@literal null} or empty. * @param to must not be {@literal null} or empty. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification rename(String from, String to) { return rename(CqlIdentifier.of(from), CqlIdentifier.of(to)); }
private StringBuilder changesCql(StringBuilder cql) { boolean first = true; boolean lastChangeWasRename = false; for (ColumnChangeSpecification change : spec().getChanges()) { if (!first) { cql.append(' '); } getCqlGeneratorFor(change, lastChangeWasRename).toCql(cql); lastChangeWasRename = change instanceof RenameColumnSpecification; first = false; } return cql; }
/** * Adds an {@literal ADD} to the list of field changes. * * @param field must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification add(String field, DataType type) { return add(CqlIdentifier.of(field), type); }
/** * Adds an {@literal ADD} to the list of field changes. * * @param field must not be {@literal null}. * @param type must not be {@literal null}. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification add(CqlIdentifier field, DataType type) { return add(AddColumnSpecification.addColumn(field, type)); }
/** * Adds an {@literal ALTER} to the list of field changes. * * @param field must not be {@literal null}. * @param type must not be {@literal null}. * @return {@code this} {@link AlterUserTypeSpecification}. */ public AlterUserTypeSpecification alter(CqlIdentifier field, DataType type) { return add(AlterColumnSpecification.alterColumn(field, type)); }