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);
}
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;
}
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);
}
}
}
}
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);
}
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;
}
Aggregations