Search in sources :

Example 51 with ColumnEntity

use of jakarta.nosql.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 : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) 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) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ColumnDeleteQuery.delete(jakarta.nosql.column.ColumnDeleteQuery.delete) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) Thread.sleep(java.lang.Thread.sleep) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Columns(jakarta.nosql.column.Columns) ColumnEntity(jakarta.nosql.column.ColumnEntity) Month(java.time.Month) Matchers(org.hamcrest.Matchers) ColumnQuery.select(jakarta.nosql.column.ColumnQuery.select) Instant(java.time.Instant) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Column(jakarta.nosql.column.Column) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ColumnQuery(jakarta.nosql.column.ColumnQuery) Assert(org.junit.Assert) ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.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)

Example 52 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldSupportListUDTs.

@Test
public void shouldSupportListUDTs() {
    ColumnEntity entity = createEntityWithIterable();
    entityManager.insert(entity);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 53 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method getColumnFamily.

private ColumnEntity getColumnFamily() {
    Map<String, Object> fields = new HashMap<>();
    fields.put("name", "Cassandra");
    fields.put("version", 3.2);
    fields.put("options", asList(1, 2, 3));
    List<Column> columns = Columns.of(fields);
    ColumnEntity columnFamily = ColumnEntity.of(Constants.COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
    columns.forEach(columnFamily::add);
    return columnFamily;
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) HashMap(java.util.HashMap) Column(jakarta.nosql.column.Column)

Example 54 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method createEntityWithIterable.

private ColumnEntity createEntityWithIterable() {
    ColumnEntity entity = ColumnEntity.of("contacts");
    entity.add(Column.of("user", "otaviojava"));
    List<Iterable<Column>> columns = new ArrayList<>();
    columns.add(asList(Column.of("firstname", "Poliana"), Column.of("lastname", "Santana")));
    columns.add(asList(Column.of("firstname", "Ada"), Column.of("lastname", "Lovelace")));
    columns.add(asList(Column.of("firstname", "Maria"), Column.of("lastname", "Goncalves")));
    UDT udt = UDT.builder("fullname").withName("names").addUDTs(columns).build();
    entity.add(udt);
    return entity;
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ArrayList(java.util.ArrayList)

Example 55 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldInsertColumns.

@Test
public void shouldInsertColumns() {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.insert(columnEntity);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (jakarta.nosql.column.ColumnEntity)146 Test (org.junit.jupiter.api.Test)103 Column (jakarta.nosql.column.Column)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Arrays.asList (java.util.Arrays.asList)11 Person (jakarta.nosql.tck.entities.Person)9 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Value (jakarta.nosql.Value)6 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)5 Actor (jakarta.nosql.tck.entities.Actor)5 Director (jakarta.nosql.tck.entities.Director)5 Movie (jakarta.nosql.tck.entities.Movie)5