Search in sources :

Example 6 with Column

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

the class ColumnEntityTest method shouldConvertSubColumnListToMap.

@Test
public void shouldConvertSubColumnListToMap() {
    ColumnEntity entity = ColumnEntity.of("entity");
    entity.add(Column.of("_id", "id"));
    List<Column> columns = asList(Column.of("name", "Ada"), Column.of("type", "type"), Column.of("information", "ada@lovelace.com"));
    entity.add(Column.of("contacts", columns));
    Map<String, Object> result = entity.toMap();
    assertEquals("id", result.get("_id"));
    List<Map<String, Object>> contacts = (List<Map<String, Object>>) result.get("contacts");
    assertEquals(3, contacts.size());
    assertThat(contacts, containsInAnyOrder(singletonMap("name", "Ada"), singletonMap("type", "type"), singletonMap("information", "ada@lovelace.com")));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.jupiter.api.Test)

Example 7 with Column

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

the class ColumnEntityTest method shouldFindTypeSupplier.

@Test
public void shouldFindTypeSupplier() {
    Column column = Column.of("name", "name");
    ColumnEntity entity = ColumnEntity.of("entity", singletonList(column));
    List<String> names = entity.find("name", new TypeReference<List<String>>() {
    }).orElse(Collections.emptyList());
    Assertions.assertNotNull(names);
    Assertions.assertFalse(names.isEmpty());
    MatcherAssert.assertThat(names, Matchers.contains("name"));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 8 with Column

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameLike.

@Test
public void shouldSelectWhereNameLike() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnQuery query = select().from(columnFamily).where("name").like(name).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.LIKE, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(name, column.get());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 9 with Column

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String columnFamily = "columnFamily";
    Number valueA = 10;
    Number valueB = 20;
    ColumnQuery query = select().from(columnFamily).where("name").between(valueA, valueB).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", column.getName());
    assertThat(column.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 10 with Column

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnQuery query = select().from(columnFamily).where("name").eq(name).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(name, column.get());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Aggregations

Column (jakarta.nosql.column.Column)113 Test (org.junit.jupiter.api.Test)72 ColumnCondition (jakarta.nosql.column.ColumnCondition)57 ColumnEntity (jakarta.nosql.column.ColumnEntity)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)35 List (java.util.List)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)24 ArrayList (java.util.ArrayList)13 Value (jakarta.nosql.Value)10 TypeReference (jakarta.nosql.TypeReference)9 Arrays.asList (java.util.Arrays.asList)9 Collections.singletonList (java.util.Collections.singletonList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 Optional (java.util.Optional)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)3