Search in sources :

Example 71 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerAsyncTest method shouldInsertColumnsAsyncWithCallBack.

@Test
public void shouldInsertColumnsAsyncWithCallBack() {
    ColumnEntity columnEntity = getColumnFamily();
    AtomicBoolean callBack = new AtomicBoolean(false);
    columnEntityManager.insert(columnEntity, c -> callBack.set(true));
    await().untilTrue(callBack);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    AtomicReference<List<ColumnEntity>> entities = new AtomicReference<>(emptyList());
    columnEntityManager.select(query, entities::set);
    await().until(() -> entities.get().size(), not(equalTo(0)));
    assertThat(entities.get(), contains(columnEntity));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 72 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerAsyncTest method shouldInsertWithTTl.

@Test
public void shouldInsertWithTTl() throws InterruptedException {
    AtomicBoolean callBack = new AtomicBoolean(false);
    columnEntityManager.insert(getColumnFamily(), Duration.ofSeconds(1L), c -> {
        callBack.set(true);
    });
    await().untilTrue(callBack);
    sleep(2_000L);
    callBack.set(false);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    AtomicReference<List<ColumnEntity>> references = new AtomicReference<>();
    columnEntityManager.select(query, l -> {
        references.set(l);
    });
    await().until(references::get, notNullValue(List.class));
    assertTrue(references.get().isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 73 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldReturnErrorWhenThereIsNotThanOneRsultInSingleResult.

@Test
public void shouldReturnErrorWhenThereIsNotThanOneRsultInSingleResult() {
    entityManager.insert(getEntities());
    ColumnQuery query = select().from(COLUMN_FAMILY).build();
    assertThrows(NonUniqueResultException.class, () -> {
        entityManager.singleResult(query);
    });
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Test(org.junit.jupiter.api.Test)

Example 74 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldSupportUDT.

@Test
public void shouldSupportUDT() {
    ColumnEntity entity = ColumnEntity.of("users");
    entity.add(Column.of("nickname", "ada"));
    List<Column> columns = new ArrayList<>();
    columns.add(Column.of("firstname", "Ada"));
    columns.add(Column.of("lastname", "Lovelace"));
    UDT udt = UDT.builder("fullname").withName("name").addUDT(columns).build();
    entity.add(udt);
    entityManager.insert(entity);
    ColumnQuery query = select().from("users").build();
    ColumnEntity columnEntity = entityManager.singleResult(query).get();
    Column column = columnEntity.find("name").get();
    udt = UDT.class.cast(column);
    List<Column> udtColumns = (List<Column>) udt.get();
    assertEquals("name", udt.getName());
    assertEquals("fullname", udt.getUserType());
    assertThat(udtColumns, Matchers.containsInAnyOrder(Column.of("firstname", "Ada"), Column.of("lastname", "Lovelace")));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.jupiter.api.Test)

Example 75 with ColumnQuery

use of org.jnosql.diana.api.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(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12