@Override
public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {
Assert.notNull(entity);
final CreateTableSpecification spec = createTable().name(entity.getTableName());
entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
@Override
public void doWithPersistentProperty(CassandraPersistentProperty prop) {
if (prop.isCompositePrimaryKey()) {
CassandraPersistentEntity<?> pkEntity = getPersistentEntity(prop.getRawType());
pkEntity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
@Override
public void doWithPersistentProperty(CassandraPersistentProperty pkProp) {
if (pkProp.isPartitionKeyColumn()) {
spec.partitionKeyColumn(pkProp.getColumnName(), pkProp.getDataType());
} else { // it's a cluster column
spec.clusteredKeyColumn(pkProp.getColumnName(), pkProp.getDataType(), pkProp.getPrimaryKeyOrdering());
}
}
});
} else {
if (prop.isIdProperty() || prop.isPartitionKeyColumn()) {
spec.partitionKeyColumn(prop.getColumnName(), prop.getDataType());
} else if (prop.isClusterKeyColumn()) {
spec.clusteredKeyColumn(prop.getColumnName(), prop.getDataType());
} else {
spec.column(prop.getColumnName(), prop.getDataType());
}
}
}
});
if (spec.getPartitionKeyColumns().isEmpty()) {
throw new MappingException("no partition key columns found in the entity " + entity.getType());
}
return spec;
}