Search in sources :

Example 76 with ColumnQuery

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

the class CassandraColumnFamilyManagerTest method shouldDeleteColumnFamily.

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

Example 77 with ColumnQuery

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

the class CassandraColumnFamilyManagerTest method shouldCreateUDTWithSet.

@Test
public void shouldCreateUDTWithSet() {
    ColumnEntity entity = createEntityWithIterableSet();
    entityManager.insert(entity);
    ColumnQuery query = ColumnQuery.select().from("agenda").build();
    final ColumnEntity result = entityManager.singleResult(query).get();
    Assert.assertEquals(Column.of("user", "otaviojava"), result.find("user").get());
    Assert.assertEquals(2, result.size());
    List<List<Column>> names = (List<List<Column>>) result.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 78 with ColumnQuery

use of jakarta.nosql.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(Constants.COLUMN_FAMILY).where("id").eq(10L).build();
    List<ColumnEntity> columnEntity = entityManager.select(query).collect(toList());
    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(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) Value(jakarta.nosql.Value) Test(org.junit.jupiter.api.Test)

Example 79 with ColumnQuery

use of jakarta.nosql.column.ColumnQuery 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 80 with ColumnQuery

use of jakarta.nosql.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(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.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)

Aggregations

ColumnQuery (jakarta.nosql.column.ColumnQuery)160 Test (org.junit.jupiter.api.Test)120 ColumnCondition (jakarta.nosql.column.ColumnCondition)64 Person (jakarta.nosql.tck.entities.Person)50 Column (jakarta.nosql.column.Column)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ColumnEntity (jakarta.nosql.column.ColumnEntity)26 List (java.util.List)26 Collections.singletonList (java.util.Collections.singletonList)10 Value (jakarta.nosql.Value)8 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)8 Arrays.asList (java.util.Arrays.asList)8 Params (jakarta.nosql.Params)7 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)7 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)7 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)6 SelectQuery (jakarta.nosql.query.SelectQuery)6