Search in sources :

Example 41 with ColumnQuery

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

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

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

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

the class CassandraColumnFamilyManagerTest method shouldDeleteColumnFamily.

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

Example 45 with ColumnQuery

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

the class CassandraColumnFamilyManagerTest method shouldFindById.

@Test
public void shouldFindById() {
    entityManager.insert(getColumnFamily());
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    List<ColumnEntity> columnEntity = entityManager.select(query);
    assertFalse(columnEntity.isEmpty());
    List<Column> columns = columnEntity.get(0).getColumns();
    assertThat(columns.stream().map(Column::getName).collect(toList()), containsInAnyOrder("name", "version", "options", "id"));
    assertThat(columns.stream().map(Column::getValue).map(Value::get).collect(toList()), containsInAnyOrder("Cassandra", 3.2, asList(1, 2, 3), 10L));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Value(org.jnosql.diana.api.Value) 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