use of org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator 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;
}
Aggregations