use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method selectByQueryWithNonExistingKeyspaceShouldThrowThatKeyspaceDoesNotExists.
// DATACASS-767
@Test
void selectByQueryWithNonExistingKeyspaceShouldThrowThatKeyspaceDoesNotExists() {
assumeThat(cassandraVersion.isGreaterThanOrEqualTo(CASSANDRA_4)).isTrue();
QueryOptions queryOptions = QueryOptions.builder().keyspace(CqlIdentifier.fromCql("non_existing")).build();
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
assertThatThrownBy(() -> assertThat(template.select(query, User.class)).isEmpty()).isInstanceOf(CassandraInvalidQueryException.class).hasMessageContaining("Keyspace 'non_existing' does not exist");
}
use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method selectShouldApplyQueryOptions.
// DATACASS-708
@Test
void selectShouldApplyQueryOptions() {
QueryOptions queryOptions = //
QueryOptions.builder().executionProfile(//
"foo").serialConsistencyLevel(//
DefaultConsistencyLevel.QUORUM).build();
StatementBuilder<Select> select = statementFactory.select(Query.empty().queryOptions(queryOptions), converter.getMappingContext().getRequiredPersistentEntity(Group.class));
SimpleStatement statement = select.build();
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.
the class CompositeKeyCrudIntegrationTests method test.
@Test
void test() {
operations.insert(correlationEntity1);
operations.insert(correlationEntity2);
Select select = QueryBuilder.selectFrom("identity_correlations").all().where(Relation.column("type").isEqualTo(QueryBuilder.literal("a")), Relation.column("value").isEqualTo(QueryBuilder.literal("b")));
List<CorrelationEntity> correlationEntities = operations.select(select.build(), CorrelationEntity.class);
assertThat(correlationEntities).hasSize(2);
QueryOptions queryOptions = QueryOptions.builder().consistencyLevel(DefaultConsistencyLevel.ONE).build();
operations.delete(correlationEntity1, queryOptions);
operations.delete(correlationEntity2, queryOptions);
correlationEntities = operations.select(select.build(), CorrelationEntity.class);
assertThat(correlationEntities).isEmpty();
}
use of org.springframework.data.cassandra.core.cql.QueryOptions 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;
}
Aggregations