use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class StatementFactory method update.
/**
* Create an {@literal UPDATE} statement by mapping {@link Query} to {@link Update}.
*
* @param query must not be {@literal null}.
* @param update must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the update builder.
* @since 2.1
*/
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update(Query query, Update update, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(update, "Update must not be null");
Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
Assert.notNull(tableName, "Table name must not be null");
Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
Update mappedUpdate = getUpdateMapper().getMappedObject(update, persistentEntity);
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> builder = update(tableName, mappedUpdate, filter);
query.getQueryOptions().filter(UpdateOptions.class::isInstance).map(UpdateOptions.class::cast).map(UpdateOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyUpdateIfCondition(builder, criteriaDefinitions));
query.getQueryOptions().filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(writeOptions -> builder.apply(statement -> addWriteOptions(statement, writeOptions)));
query.getQueryOptions().ifPresent(options -> builder.transform(statementBuilder -> QueryOptionsUtil.addQueryOptions(statementBuilder, options)));
return builder;
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class CassandraTemplate method doSelect.
<T> List<T> doSelect(Query query, Class<?> entityClass, CqlIdentifier tableName, Class<T> returnType) {
CassandraPersistentEntity<?> entity = getRequiredPersistentEntity(entityClass);
EntityProjection<T, ?> projection = entityOperations.introspectProjection(returnType, entityClass);
Columns columns = getStatementFactory().computeColumnsForProjection(projection, query.getColumns(), entity, returnType);
Query queryToUse = query.columns(columns);
StatementBuilder<Select> select = getStatementFactory().select(queryToUse, entity, tableName);
Function<Row, T> mapper = getMapper(projection, tableName);
return doQuery(select.build(), (row, rowNum) -> mapper.apply(row));
}
Aggregations