Search in sources :

Example 61 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity 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 62 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldUpdateColumn.

@Test
public void shouldUpdateColumn() {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.update(columnEntity);
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 63 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldDeleteColumnFamilyWithConsistencyLevel.

@Test
public void shouldDeleteColumnFamilyWithConsistencyLevel() {
    entityManager.insert(getColumnFamily());
    ColumnEntity.of(COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
    ColumnDeleteQuery deleteQuery = delete().from(COLUMN_FAMILY).where("id").eq(10L).build();
    entityManager.delete(deleteQuery, CONSISTENCY_LEVEL);
    List<ColumnEntity> entities = entityManager.cql("select * from newKeySpace.newColumnFamily where id=10;");
    assertTrue(entities.isEmpty());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 64 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity 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)

Example 65 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldReturnListUDT.

@Test
public void shouldReturnListUDT() {
    ColumnEntity entity = createEntityWithIterable();
    entityManager.insert(entity);
    ColumnQuery query = select().from("contacts").where("user").eq("otaviojava").build();
    ColumnEntity columnEntity = entityManager.singleResult(query).get();
    List<List<Column>> names = (List<List<Column>>) columnEntity.find("names").get().get();
    assertEquals(3, names.size());
    assertTrue(names.stream().allMatch(n -> n.size() == 2));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) EmbeddedCassandraServerHelper(org.cassandraunit.utils.EmbeddedCassandraServerHelper) TTransportException(org.apache.thrift.transport.TTransportException) Date(java.util.Date) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) HashMap(java.util.HashMap) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) Calendar(java.util.Calendar) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Session(com.datastax.driver.core.Session) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) Map(java.util.Map) Columns(org.jnosql.diana.api.column.Columns) Thread.sleep(java.lang.Thread.sleep) Collections.singletonMap(java.util.Collections.singletonMap) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) KEY_SPACE(org.jnosql.diana.cassandra.column.Constants.KEY_SPACE) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Month(java.time.Month) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) COLUMN_FAMILY(org.jnosql.diana.cassandra.column.Constants.COLUMN_FAMILY) ZoneId(java.time.ZoneId) Column(org.jnosql.diana.api.column.Column) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LocalDate(com.datastax.driver.core.LocalDate) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) 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) 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)

Aggregations

ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)88 Test (org.junit.jupiter.api.Test)76 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)26 Column (org.jnosql.diana.api.column.Column)22 Arrays.asList (java.util.Arrays.asList)17 List (java.util.List)17 Consumer (java.util.function.Consumer)14 Collections.singletonList (java.util.Collections.singletonList)13 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)13 Person (org.jnosql.artemis.model.Person)12 Duration (java.time.Duration)11 Collections.emptyList (java.util.Collections.emptyList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)9 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)9 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8