use of org.springframework.data.cassandra.core.convert.Where in project spring-data-cassandra by spring-projects.
the class StatementFactory method selectOneById.
/**
* Create an {@literal SELECT} statement by mapping {@code id} to {@literal SELECT … WHERE} considering
* {@link UpdateOptions}.
*
* @param id must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the select builder.
*/
StatementBuilder<Select> selectOneById(Object id, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Where where = new Where();
cassandraConverter.write(id, where, persistentEntity);
return StatementBuilder.of(QueryBuilder.selectFrom(tableName).all().limit(1)).bind((statement, factory) -> statement.where(toRelations(where, factory)));
}
use of org.springframework.data.cassandra.core.convert.Where in project spring-data-cassandra by spring-projects.
the class StatementFactory method deleteById.
/**
* Create an {@literal DELETE} statement by mapping {@code id} to {@literal SELECT … WHERE} considering
* {@link UpdateOptions}.
*
* @param id must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the delete builder.
*/
StatementBuilder<Delete> deleteById(Object id, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Where where = new Where();
cassandraConverter.write(id, where, persistentEntity);
return StatementBuilder.of(QueryBuilder.deleteFrom(tableName).where()).bind((statement, factory) -> statement.where(toRelations(where, factory)));
}
use of org.springframework.data.cassandra.core.convert.Where in project spring-data-cassandra by spring-projects.
the class StatementFactory method delete.
/**
* Create an {@literal DELETE} statement by mapping {@code entity} to {@link Delete DELETE … WHERE} considering
* {@link WriteOptions}.
*
* @param entity must not be {@literal null}.
* @param options must not be {@literal null}.
* @param entityWriter must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the delete builder.
*/
StatementBuilder<Delete> delete(Object entity, QueryOptions options, EntityWriter<Object, Object> entityWriter, CqlIdentifier tableName) {
Assert.notNull(tableName, "TableName must not be null");
Assert.notNull(entity, "Object to builder must not be null");
Assert.notNull(entityWriter, "EntityWriter must not be null");
Where where = new Where();
entityWriter.write(entity, where);
StatementBuilder<Delete> builder = StatementBuilder.of(QueryBuilder.deleteFrom(tableName).where()).bind((statement, factory) -> statement.where(toRelations(where, factory)));
Optional.of(options).filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(it -> builder.apply(statement -> addWriteOptions(statement, it)));
Optional.of(options).filter(DeleteOptions.class::isInstance).map(DeleteOptions.class::cast).map(DeleteOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyDeleteIfCondition(builder, criteriaDefinitions));
builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options));
return builder;
}
use of org.springframework.data.cassandra.core.convert.Where in project spring-data-cassandra by spring-projects.
the class StatementFactory method update.
/**
* Create an {@literal UPDATE} statement by mapping {@code objectToUpdate} to {@link Update} considering
* {@link UpdateOptions}.
*
* @param objectToUpdate must not be {@literal null}.
* @param options must not be {@literal null}.
* @param entity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the update builder.
*/
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update(Object objectToUpdate, WriteOptions options, CassandraPersistentEntity<?> entity, CqlIdentifier tableName) {
Assert.notNull(tableName, "TableName must not be null");
Assert.notNull(objectToUpdate, "Object to builder must not be null");
Assert.notNull(options, "WriteOptions must not be null");
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
Where where = new Where();
cassandraConverter.write(objectToUpdate, where, entity);
Map<CqlIdentifier, Object> object = new LinkedHashMap<>();
cassandraConverter.write(objectToUpdate, object, entity);
where.forEach((cqlIdentifier, o) -> object.remove(cqlIdentifier));
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> builder = StatementBuilder.of(QueryBuilder.update(tableName).set().where()).bind((statement, factory) -> ((UpdateWithAssignments) statement).set(toAssignments(object, factory)).where(toRelations(where, factory))).apply(update -> addWriteOptions(update, options));
Optional.of(options).filter(UpdateOptions.class::isInstance).map(UpdateOptions.class::cast).map(UpdateOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyUpdateIfCondition(builder, criteriaDefinitions));
builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options));
return builder;
}
Aggregations