Search in sources :

Example 71 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.

the class ColumnPageTest method shouldExecutePaginationAsQuery.

@Test
public void shouldExecutePaginationAsQuery() {
    Pagination pagination = Pagination.page(1).size(1);
    ColumnQueryPagination queryPagination = ColumnQueryPagination.of(select().from("person").build(), pagination);
    ColumnQuery query = queryPagination;
    List<Person> people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(0L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(1L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(2L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(3L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(4L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(5L, people.stream().map(Person::getId).findFirst().orElse(-0L));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQuery(jakarta.nosql.column.ColumnQuery) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 72 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByNameOrderByName2.

@Test
public void shouldFindByNameOrderByName2() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of((Person.builder().build())));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sorts.sorts().desc("age").asc("phone"));
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Column.of("name", "name"), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age"), Sort.asc("phone")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 73 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultColumnEventPersistManagerTest method shouldFirePreQuery.

@Test
public void shouldFirePreQuery() {
    ColumnQuery query = select().from("person").build();
    subject.firePreQuery(query);
    ArgumentCaptor<ColumnQueryExecute> captor = ArgumentCaptor.forClass(ColumnQueryExecute.class);
    verify(columnQueryExecute).fire(captor.capture());
    assertEquals(query, captor.getValue().getQuery());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnQueryExecute(jakarta.nosql.mapping.column.ColumnQueryExecute) Test(org.junit.jupiter.api.Test)

Example 74 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldPagingState.

@Test
public void shouldPagingState() {
    for (long index = 1; index <= 10; index++) {
        ColumnEntity columnFamily = getColumnFamily();
        columnFamily.add("id", index);
        entityManager.insert(columnFamily);
    }
    ColumnQuery query = select().from(Constants.COLUMN_FAMILY).build();
    CassandraQuery cassandraQuery = CassandraQuery.of(query);
    assertFalse(cassandraQuery.getPagingState().isPresent());
    List<ColumnEntity> entities = entityManager.select(cassandraQuery).collect(toList());
    assertEquals(10, entities.size());
    assertTrue(cassandraQuery.getPagingState().isPresent());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 75 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldReturnSingleResult.

@Test
public void shouldReturnSingleResult() {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.insert(columnEntity);
    ColumnQuery query = select().from(columnEntity.getName()).where("id").eq(10L).build();
    Optional<ColumnEntity> entity = entityManager.singleResult(query);
    query = select().from(columnEntity.getName()).where("id").eq(-10L).build();
    entity = entityManager.singleResult(query);
    assertFalse(entity.isPresent());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (jakarta.nosql.column.ColumnQuery)160 Test (org.junit.jupiter.api.Test)120 ColumnCondition (jakarta.nosql.column.ColumnCondition)64 Person (jakarta.nosql.tck.entities.Person)50 Column (jakarta.nosql.column.Column)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ColumnEntity (jakarta.nosql.column.ColumnEntity)26 List (java.util.List)26 Collections.singletonList (java.util.Collections.singletonList)10 Value (jakarta.nosql.Value)8 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)8 Arrays.asList (java.util.Arrays.asList)8 Params (jakarta.nosql.Params)7 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)7 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)7 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)6 SelectQuery (jakarta.nosql.query.SelectQuery)6