use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.
the class SchemaFactory method getCreateUserTypeSpecificationFor.
/**
* Returns a {@link CreateUserTypeSpecification} for the given entity, including all mapping information.
*
* @param entity must not be {@literal null}.
*/
public CreateUserTypeSpecification getCreateUserTypeSpecificationFor(CassandraPersistentEntity<?> entity) {
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
CreateUserTypeSpecification specification = CreateUserTypeSpecification.createType(entity.getTableName());
for (CassandraPersistentProperty property : entity) {
if (property.isEmbedded()) {
CassandraPersistentEntity<?> embeddedEntity = embeddedEntityOperations.getEntity(property);
for (CassandraPersistentProperty embeddedProperty : embeddedEntity) {
DataType dataType = getDataType(embeddedProperty);
specification.field(embeddedProperty.getRequiredColumnName(), dataType);
}
} else {
// Use frozen literal to not resolve types from Cassandra; At this stage, they might be not created yet.
specification.field(property.getRequiredColumnName(), UserTypeUtil.potentiallyFreeze(getDataType(property)));
}
}
if (specification.getFields().isEmpty()) {
throw new MappingException(String.format("No fields in user type [%s]", entity.getType()));
}
return specification;
}
Aggregations