Search in sources :

Example 6 with QueryOptions

use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.

the class ReactiveStringBasedCassandraQueryUnitTests method shouldApplyQueryOptions.

// DATACASS-146
@Test
void shouldApplyQueryOptions() {
    QueryOptions queryOptions = QueryOptions.builder().pageSize(777).build();
    ReactiveStringBasedCassandraQuery cassandraQuery = getQueryMethod("findByLastname", QueryOptions.class, String.class);
    CassandraParametersParameterAccessor parameterAccessor = new CassandraParametersParameterAccessor(cassandraQuery.getQueryMethod(), queryOptions, "White");
    SimpleStatement actual = cassandraQuery.createQuery(parameterAccessor).block();
    assertThat(actual.getQuery()).isEqualTo("SELECT * FROM person WHERE lastname=?;");
    assertThat(actual.getPositionalValues().get(0)).isEqualTo("White");
    assertThat(actual.getPageSize()).isEqualTo(777);
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 7 with QueryOptions

use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.

the class CassandraParametersParameterAccessorUnitTests method shouldProvideQueryOptions.

// DATACASS-146
@Test
void shouldProvideQueryOptions() throws Exception {
    QueryOptions options = QueryOptions.builder().build();
    Method method = PossibleRepository.class.getMethod("findByFirstname", QueryOptions.class, String.class);
    CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method), options, "firstname");
    assertThat(accessor.getQueryOptions()).isEqualTo(options);
}
Also used : Method(java.lang.reflect.Method) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 8 with QueryOptions

use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.

the class PartTreeCassandraQueryUnitTests method shouldApplyQueryOptions.

// DATACASS-146
@Test
void shouldApplyQueryOptions() {
    QueryOptions queryOptions = QueryOptions.builder().pageSize(777).build();
    SimpleStatement statement = deriveQueryFromMethod(Repo.class, "findByFirstname", new Class[] { QueryOptions.class, String.class }, queryOptions, "Walter");
    assertThat(statement.getQuery()).isEqualTo("SELECT * FROM person WHERE firstname=?");
    assertThat(statement.getPageSize()).isEqualTo(777);
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 9 with QueryOptions

use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.

the class StringBasedCassandraQueryUnitTests method shouldApplyQueryOptions.

// DATACASS-146
@Test
void shouldApplyQueryOptions() {
    QueryOptions queryOptions = QueryOptions.builder().pageSize(777).build();
    StringBasedCassandraQuery cassandraQuery = getQueryMethod("findByLastname", QueryOptions.class, String.class);
    CassandraParametersParameterAccessor parameterAccessor = new CassandraParametersParameterAccessor(cassandraQuery.getQueryMethod(), queryOptions, "Matthews");
    SimpleStatement actual = cassandraQuery.createQuery(parameterAccessor);
    assertThat(actual.getQuery()).isEqualTo("SELECT * FROM person WHERE lastname = ?;");
    assertThat(actual.getPositionalValues().get(0)).isEqualTo("Matthews");
    assertThat(actual.getPageSize()).isEqualTo(777);
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 10 with QueryOptions

use of org.springframework.data.cassandra.core.cql.QueryOptions in project spring-data-cassandra by spring-projects.

the class CassandraTemplateIntegrationTests method selectByQueryWithKeyspaceShouldRetrieveData.

// DATACASS-767
@Test
void selectByQueryWithKeyspaceShouldRetrieveData() {
    assumeThat(cassandraVersion.isGreaterThanOrEqualTo(CASSANDRA_4)).isTrue();
    QueryOptions queryOptions = QueryOptions.builder().keyspace(CqlIdentifier.fromCql(keyspace)).build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
    assertThat(template.select(query, User.class)).isNotEmpty();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Aggregations

QueryOptions (org.springframework.data.cassandra.core.cql.QueryOptions)14 Test (org.junit.jupiter.api.Test)10 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)7 Query (org.springframework.data.cassandra.core.query.Query)4 Select (com.datastax.oss.driver.api.querybuilder.select.Select)3 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)1 BindMarker (com.datastax.oss.driver.api.querybuilder.BindMarker)1 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)1 Condition (com.datastax.oss.driver.api.querybuilder.condition.Condition)1 ConditionBuilder (com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder)1 DeleteSelection (com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection)1 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)1 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)1 ColumnRelationBuilder (com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder)1 Relation (com.datastax.oss.driver.api.querybuilder.relation.Relation)1 Term (com.datastax.oss.driver.api.querybuilder.term.Term)1 Assignment (com.datastax.oss.driver.api.querybuilder.update.Assignment)1 OngoingAssignment (com.datastax.oss.driver.api.querybuilder.update.OngoingAssignment)1