Search in sources :

Example 11 with CassandraPersistentProperty

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;
}
Also used : CreateUserTypeSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification) DataType(com.datastax.oss.driver.api.core.type.DataType) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) MappingException(org.springframework.data.mapping.MappingException)

Aggregations

CassandraPersistentProperty (org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty)11 ArrayList (java.util.ArrayList)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 CassandraPersistentEntity (org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity)3 EmbeddedEntityOperations (org.springframework.data.cassandra.core.mapping.EmbeddedEntityOperations)3 Columns (org.springframework.data.cassandra.core.query.Columns)3 CriteriaDefinition (org.springframework.data.cassandra.core.query.CriteriaDefinition)3 Filter (org.springframework.data.cassandra.core.query.Filter)3 Nullable (org.springframework.lang.Nullable)3 DataType (com.datastax.oss.driver.api.core.type.DataType)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CreateUserTypeSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification)2 BasicCassandraPersistentEntity (org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity)2 CassandraMappingContext (org.springframework.data.cassandra.core.mapping.CassandraMappingContext)2 ColumnName (org.springframework.data.cassandra.core.query.ColumnName)2 ColumnSelector (org.springframework.data.cassandra.core.query.Columns.ColumnSelector)2