/** * Create a new {@link ColumnSpecification} for the given {@code name}. * * @param name must not be {@literal null}. * @return a new {@link ColumnSpecification} for {@code name}. */ public static ColumnSpecification name(CqlIdentifier name) { Assert.notNull(name, "CqlIdentifier must not be null"); return new ColumnSpecification(name); }
/** * Identifies this column as a clustered key column with default ordering. Sets the column's {@link #keyType} to * {@link PrimaryKeyType#CLUSTERED} and its {@link #ordering} to {@link #DEFAULT_ORDERING}. * * @return this */ public ColumnSpecification clustered() { return clustered(DEFAULT_ORDERING); }
/** * Identifies this column as a primary key column that is also part of a partition key. Sets the column's * {@link #keyType} to {@link PrimaryKeyType#PARTITIONED} and its {@link #ordering} to {@literal null}. * * @return this */ public ColumnSpecification partitioned() { return partitioned(true); }
@SuppressWarnings("unchecked") protected T column(CqlIdentifier name, DataType type, Optional<PrimaryKeyType> optionalKeyType, Optional<Ordering> optionalOrdering) { Assert.notNull(name, "Name must not be null"); Assert.notNull(type, "DataType must not be null"); Assert.notNull(optionalKeyType, "PrimaryKeyType must not be null"); Assert.notNull(optionalOrdering, "Ordering must not be null"); ColumnSpecification column = ColumnSpecification.name(name).type(type); optionalKeyType.ifPresent(keyType -> { column.keyType(keyType); optionalOrdering.filter(o -> keyType == CLUSTERED).ifPresent(column::ordering); if (keyType == PrimaryKeyType.PARTITIONED) { this.partitionKeyColumns.add(column); } if (keyType == PrimaryKeyType.CLUSTERED) { this.clusteredKeyColumns.add(column); } }); this.columns.add(column); if (!optionalKeyType.isPresent()) { this.nonKeyColumns.add(column); } return (T) this; }
private static StringBuilder createOrderingClause(List<ColumnSpecification> columns) { StringBuilder ordering = new StringBuilder(); boolean first = true; for (ColumnSpecification col : columns) { if (col.getOrdering() != null) { // then ordering specified if (!StringUtils.hasText(ordering)) { // then initialize ordering clause ordering.append("CLUSTERING ORDER BY ("); } if (first) { first = false; } else { ordering.append(", "); } ordering.append(col.getName()).append(" ").append(col.getOrdering().cql()); } } if (StringUtils.hasText(ordering)) { // then end ordering option ordering.append(")"); } return ordering; }
List<ColumnSpecification> clusterKeys = new ArrayList<>(); for (ColumnSpecification col : spec().getColumns()) { col.toCql(cql).append(", "); if (col.getKeyType() == PARTITIONED) { partitionKeys.add(col); } else if (col.getKeyType() == CLUSTERED) { clusterKeys.add(col);
public String toCql() { return toCql(new StringBuilder()).toString(); }
private static void appendColumnNames(StringBuilder str, List<ColumnSpecification> columns) { boolean first = true; for (ColumnSpecification col : columns) { if (first) { first = false; } else { str.append(", "); } str.append(col.getName()); } } }
/** * Create a new {@link ColumnSpecification} for the given {@code name}. * * @param name must not be {@literal null} or empty. * @return a new {@link ColumnSpecification} for {@code name}. */ public static ColumnSpecification name(String name) { return name(of(name)); }
@Override public String toString() { return toCql(new StringBuilder()).append(" /* keyType=").append(keyType).append(", ordering=").append(ordering) .append(" */ ").toString(); } }
/** * Identifies this column as a clustered key column with the given ordering. Sets the column's {@link #keyType} to * {@link PrimaryKeyType#CLUSTERED} and its {@link #ordering} to the given {@link Ordering}. * * @return this */ public ColumnSpecification clustered(Ordering order) { return clustered(order, true); }