Search in sources :

Example 1 with CassandraPersistentProperty

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.

the class ColumnTypeResolverUnitTests method UuidshouldMapToUUIDByDefault.

// DATACASS-375, DATACASS-743
@Test
void UuidshouldMapToUUIDByDefault() {
    CassandraPersistentProperty uuidProperty = mappingContext.getRequiredPersistentEntity(TypeWithUUIDColumn.class).getRequiredPersistentProperty("uuid");
    CassandraPersistentProperty timeUUIDProperty = mappingContext.getRequiredPersistentEntity(TypeWithUUIDColumn.class).getRequiredPersistentProperty("timeUUID");
    assertThat(resolver.resolve(uuidProperty).getDataType()).isEqualTo(DataTypes.UUID);
    assertThat(resolver.resolve(timeUUIDProperty).getDataType()).isEqualTo(DataTypes.TIMEUUID);
}
Also used : CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) Test(org.junit.jupiter.api.Test)

Example 2 with CassandraPersistentProperty

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.

the class StatementFactory method computeColumnsForProjection.

/**
 * Compute the {@link Columns} to include type if the {@code returnType} is a {@literal DTO projection} or a
 * {@literal closed interface projection}.
 *
 * @param columns must not be {@literal null}.
 * @param domainType must not be {@literal null}.
 * @param returnType must not be {@literal null}.
 * @return {@link Columns} with columns to be included.
 * @since 2.2
 */
Columns computeColumnsForProjection(EntityProjection<?, ?> projection, Columns columns, CassandraPersistentEntity<?> domainType, Class<?> returnType) {
    if (!columns.isEmpty() || ClassUtils.isAssignable(domainType.getType(), returnType)) {
        return columns;
    }
    if (projection.getMappedType().getType().isInterface()) {
        projection.forEach(propertyPath -> columns.include(propertyPath.getPropertyPath().getSegment()));
    } else {
        // DTO projections use merged metadata between domain type and result type
        PersistentPropertyTranslator translator = PersistentPropertyTranslator.create(domainType, Predicates.negate(CassandraPersistentProperty::hasExplicitColumnName));
        CassandraPersistentEntity<?> persistentEntity = getQueryMapper().getConverter().getMappingContext().getRequiredPersistentEntity(projection.getMappedType());
        for (CassandraPersistentProperty property : persistentEntity) {
            columns.include(translator.translate(property).getColumnName());
        }
    }
    Columns projectedColumns = Columns.empty();
    if (returnType.isInterface()) {
        ProjectionInformation projectionInformation = cassandraConverter.getProjectionFactory().getProjectionInformation(returnType);
        if (projectionInformation.isClosed()) {
            for (PropertyDescriptor inputProperty : projectionInformation.getInputProperties()) {
                projectedColumns = projectedColumns.include(inputProperty.getName());
            }
        }
    } else {
        for (PersistentProperty<?> property : domainType) {
            projectedColumns = projectedColumns.include(property.getName());
        }
    }
    return projectedColumns;
}
Also used : ProjectionInformation(org.springframework.data.projection.ProjectionInformation) PropertyDescriptor(java.beans.PropertyDescriptor) Columns(org.springframework.data.cassandra.core.query.Columns) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) PersistentPropertyTranslator(org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator)

Example 3 with CassandraPersistentProperty

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.

the class SchemaTestUtils method potentiallyCreateUdtFor.

private static void potentiallyCreateUdtFor(CassandraPersistentEntity<?> persistentEntity, CassandraOperations operations, SchemaFactory schemaFactory) {
    if (persistentEntity.isUserDefinedType()) {
        CreateUserTypeSpecification udtspec = schemaFactory.getCreateUserTypeSpecificationFor(persistentEntity).ifNotExists();
        operations.getCqlOperations().execute(CreateUserTypeCqlGenerator.toCql(udtspec));
    } else {
        for (CassandraPersistentProperty property : persistentEntity) {
            if (!property.isEntity()) {
                continue;
            }
            if (property.isEmbedded()) {
                potentiallyCreateUdtFor(new EmbeddedEntityOperations(operations.getConverter().getMappingContext()).getEntity(property), operations, schemaFactory);
            } else {
                potentiallyCreateUdtFor(operations.getConverter().getMappingContext().getRequiredPersistentEntity(property), operations, schemaFactory);
            }
        }
    }
}
Also used : CreateUserTypeSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification) EmbeddedEntityOperations(org.springframework.data.cassandra.core.mapping.EmbeddedEntityOperations) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty)

Example 4 with CassandraPersistentProperty

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.

the class MappingCassandraEntityInformation method getId.

/* (non-Javadoc)
	 * @see org.springframework.data.repository.core.EntityInformation#getId(java.lang.Object)
	 */
@SuppressWarnings("unchecked")
@Override
@Nullable
public ID getId(T entity) {
    Assert.notNull(entity, "Entity must not be null");
    CassandraPersistentProperty idProperty = this.entityMetadata.getIdProperty();
    return idProperty != null ? (ID) this.entityMetadata.getIdentifierAccessor(entity).getIdentifier() : (ID) converter.getId(entity, entityMetadata);
}
Also used : CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) Nullable(org.springframework.lang.Nullable)

Example 5 with CassandraPersistentProperty

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty in project spring-data-cassandra by spring-projects.

the class CassandraQueryCreator method create.

/* (non-Javadoc)
	 * @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
	 */
@Override
protected Filter create(Part part, Iterator<Object> iterator) {
    PersistentPropertyPath<CassandraPersistentProperty> path = getMappingContext().getPersistentPropertyPath(part.getProperty());
    CassandraPersistentProperty property = path.getLeafProperty();
    Assert.state(property != null && path.toDotPath() != null, "Leaf property must not be null");
    Object filterOrCriteria = from(part, property, Criteria.where(path.toDotPath()), (PotentiallyConvertingIterator) iterator);
    if (filterOrCriteria instanceof CriteriaDefinition) {
        return Filter.from((CriteriaDefinition) filterOrCriteria);
    }
    return (Filter) filterOrCriteria;
}
Also used : Filter(org.springframework.data.cassandra.core.query.Filter) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition)

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