use of org.springframework.data.cassandra.core.query.Columns.Selector in project spring-data-cassandra by spring-projects.
the class QueryMapper method getMappedSelectors.
/**
* Map {@link Columns} with a {@link CassandraPersistentEntity type hint} to {@link ColumnSelector}s.
*
* @param columns must not be {@literal null}.
* @param entity must not be {@literal null}.
* @return the mapped {@link Selector}s.
*/
public List<Selector> getMappedSelectors(Columns columns, CassandraPersistentEntity<?> entity) {
Assert.notNull(columns, "Columns must not be null");
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
if (columns.isEmpty()) {
return Collections.emptyList();
}
List<Selector> selectors = new ArrayList<>();
for (ColumnName column : columns) {
Field field = createPropertyField(entity, column);
columns.getSelector(column).ifPresent(selector -> {
List<CqlIdentifier> mappedColumnNames = getCqlIdentifier(column, field);
for (CqlIdentifier mappedColumnName : mappedColumnNames) {
selectors.add(getMappedSelector(selector, mappedColumnName));
}
});
}
if (columns.isEmpty()) {
addColumns(entity, selectors);
}
return selectors;
}
use of org.springframework.data.cassandra.core.query.Columns.Selector in project spring-data-cassandra by spring-projects.
the class QueryMapper method getMappedColumnNames.
/**
* Map {@link Columns} with a {@link CassandraPersistentEntity type hint} to column names for included columns.
* Function call selectors or other {@link org.springframework.data.cassandra.core.query.Columns.Selector} types are
* not included.
*
* @param columns must not be {@literal null}.
* @param entity must not be {@literal null}.
* @return the mapped column names.
*/
public List<CqlIdentifier> getMappedColumnNames(Columns columns, CassandraPersistentEntity<?> entity) {
Assert.notNull(columns, "Columns must not be null");
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
if (columns.isEmpty()) {
return Collections.emptyList();
}
List<CqlIdentifier> columnNames = new ArrayList<>();
Set<PersistentProperty<?>> seen = new HashSet<>();
for (ColumnName column : columns) {
Field field = createPropertyField(entity, column);
field.getProperty().ifPresent(seen::add);
columns.getSelector(column).filter(selector -> selector instanceof ColumnSelector).ifPresent(columnSelector -> columnNames.addAll(getCqlIdentifier(column, field)));
}
if (columns.isEmpty()) {
entity.doWithProperties((PropertyHandler<CassandraPersistentProperty>) property -> {
if (property.isCompositePrimaryKey()) {
return;
}
if (seen.add(property)) {
columnNames.add(property.getRequiredColumnName());
}
});
}
return columnNames;
}
Aggregations