Search in sources :

Example 36 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldSupportAnUDTElement.

@Test
public void shouldSupportAnUDTElement() {
    ColumnEntity entity = ColumnEntity.of("users");
    entity.add(Column.of("nickname", "Ioda"));
    List<Column> columns = new ArrayList<>();
    columns.add(Column.of("firstname", "Ioda"));
    UDT udt = UDT.builder("fullname").withName("name").addUDT(columns).build();
    entity.add(udt);
    entityManager.insert(entity);
    ColumnQuery query = select().from("users").where("nickname").eq("Ioda").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", "Ioda")));
}
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 37 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldFindAll.

@Test
public void shouldFindAll() {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.insert(columnEntity);
    ColumnQuery query = select().from(columnEntity.getName()).build();
    List<ColumnEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 38 with ColumnEntity

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

the class CassandraColumnFamilyManagerTest method shouldSupportDate.

@Test
public void shouldSupportDate() {
    ColumnEntity entity = ColumnEntity.of("history");
    entity.add(Column.of("name", "World war II"));
    ZoneId defaultZoneId = ZoneId.systemDefault();
    Date dateEnd = Date.from(java.time.LocalDate.of(1945, Month.SEPTEMBER, 2).atStartOfDay(defaultZoneId).toInstant());
    Calendar dataStart = Calendar.getInstance();
    entity.add(Column.of("dataStart", LocalDate.fromYearMonthDay(1939, 9, 1)));
    entity.add(Column.of("dateEnd", dateEnd));
    entityManager.insert(entity);
    ColumnQuery query = select().from("history").where("name").eq("World war II").build();
    ColumnEntity entity1 = entityManager.singleResult(query).get();
    assertNotNull(entity1);
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) ZoneId(java.time.ZoneId) Calendar(java.util.Calendar) Date(java.util.Date) LocalDate(com.datastax.driver.core.LocalDate) Test(org.junit.jupiter.api.Test)

Example 39 with ColumnEntity

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

Example 40 with ColumnEntity

use of org.jnosql.diana.api.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(COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
    columns.forEach(columnFamily::add);
    return columnFamily;
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) HashMap(java.util.HashMap) Column(org.jnosql.diana.api.column.Column)

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