/** * Entry point into the {@link CreateTableSpecification}'s fluent API given {@code tableName} to create a table. * Convenient if imported statically. * * @param tableName must not be {@literal null}. * @return a new {@link CreateTableSpecification}. */ public static CreateTableSpecification createTable(CqlIdentifier tableName) { return new CreateTableSpecification(tableName); }
/** * Causes the inclusion of an {@code IF NOT EXISTS} clause. * * @return this */ public CreateTableSpecification ifNotExists() { return ifNotExists(true); }
CreateTableSpecification specification = createTable(entity.getTableName()); specification.partitionKeyColumn(primaryKeyProperty.getRequiredColumnName(), getDataType(primaryKeyProperty)); } else { // cluster column specification.clusteredKeyColumn(primaryKeyProperty.getRequiredColumnName(), getDataType(primaryKeyProperty), primaryKeyProperty.getPrimaryKeyOrdering()); specification.partitionKeyColumn(property.getRequiredColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property))); } else if (property.isClusterKeyColumn()) { specification.clusteredKeyColumn(property.getRequiredColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property)), property.getPrimaryKeyOrdering()); } else { specification.column(property.getRequiredColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property))); if (specification.getPartitionKeyColumns().isEmpty()) { throw new MappingException(String.format("No partition key columns found in entity [%s]", entity.getType()));
private void preambleCql(StringBuilder cql) { cql.append("CREATE TABLE ").append(spec().getIfNotExists() ? "IF NOT EXISTS " : "").append(spec().getName()); }
for (ColumnSpecification col : spec().getColumns()) { col.toCql(cql).append(", "); Map<String, Object> options = spec().getOptions();
/** * Create {@link List} of {@link CreateTableSpecification}. * * @param ifNotExists {@literal true} to create tables using {@code IF NOT EXISTS}. * @return {@link List} of {@link CreateTableSpecification}. */ protected List<CreateTableSpecification> createTableSpecifications(boolean ifNotExists) { return this.mappingContext.getTableEntities() // .stream() // .map(entity -> this.mappingContext.getCreateTableSpecificationFor(entity).ifNotExists(ifNotExists)) // .collect(Collectors.toList()); }
/** * Entry point into the {@link CreateTableSpecification}'s fluent API given {@code tableName} to create a table. * Convenient if imported statically. * * @param tableName must not be {@literal null} or empty. * @return a new {@link CreateTableSpecification}. */ public static CreateTableSpecification createTable(String tableName) { return new CreateTableSpecification(CqlIdentifier.of(tableName)); }
@Override public void createTable(boolean ifNotExists, CqlIdentifier tableName, Class<?> entityClass, Map<String, Object> optionsByName) { CassandraPersistentEntity<?> entity = getConverter().getMappingContext().getRequiredPersistentEntity(entityClass); CreateTableSpecification createTableSpecification = getConverter().getMappingContext() .getCreateTableSpecificationFor(entity).ifNotExists(ifNotExists); getCqlOperations().execute(CreateTableCqlGenerator.toCql(createTableSpecification)); }