Search in sources :

Example 21 with TypeReference

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

the class DefaultColumnConditionTest method shouldOr.

@Test
public void shouldOr() {
    ColumnCondition eq = ColumnCondition.eq(Column.of("name", "otavio"));
    ColumnCondition gt = ColumnCondition.gt(Column.of("age", 10));
    ColumnCondition lte = ColumnCondition.lte(Column.of("salary", 10_000.00));
    ColumnCondition or = eq.or(gt);
    List<ColumnCondition> conditions = or.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.OR, or.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    ColumnCondition result = or.or(lte);
    assertEquals(Condition.OR, result.getCondition());
    assertThat(result.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    }), Matchers.containsInAnyOrder(eq, gt, lte));
}
Also used : List(java.util.List) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 22 with TypeReference

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

the class Relations method load.

private static void load(ColumnCondition columnCondition, List<Relation> relations) {
    Column column = columnCondition.getColumn();
    Condition condition = columnCondition.getCondition();
    switch(condition) {
        case EQUALS:
            relations.add(Relation.column(QueryUtils.getName(column)).isEqualTo(getTerm(column)));
            return;
        case GREATER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThan(getTerm(column)));
            return;
        case GREATER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThanOrEqualTo(getTerm(column)));
            return;
        case LESSER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThan(getTerm(column)));
            return;
        case LESSER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThanOrEqualTo(getTerm(column)));
            return;
        case IN:
            relations.add(Relation.column(QueryUtils.getName(column)).in(getIinValue(column.getValue())));
            return;
        case LIKE:
            relations.add(Relation.column(QueryUtils.getName(column)).like(getTerm(column)));
            return;
        case AND:
            column.get(new TypeReference<List<ColumnCondition>>() {
            }).forEach(cc -> load(cc, relations));
            return;
        case OR:
        default:
            throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
    }
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) Condition(jakarta.nosql.Condition) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 23 with TypeReference

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

the class DefaultKeyValueEntityTest method shouldGetKeyValueSupplier.

@Test
public void shouldGetKeyValueSupplier() {
    String value = "10";
    KeyValueEntity entity = KeyValueEntity.of(value, value);
    assertEquals(value, entity.getValue());
    assertEquals(Integer.valueOf(10), entity.getKey(Integer.class));
    assertThat(singletonList(10), Matchers.contains(entity.getValue(new TypeReference<List<Integer>>() {
    }).get(0)));
}
Also used : TypeReference(jakarta.nosql.TypeReference) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 24 with TypeReference

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String documentCollection = "documentCollection";
    Number valueA = 10;
    Number valueB = 20;
    DocumentQuery query = select().from(documentCollection).where("name").between(valueA, valueB).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", document.getName());
    assertThat(document.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 25 with TypeReference

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

the class DocumentEntityTest method shouldNotFindTypeSupplier.

@Test
public void shouldNotFindTypeSupplier() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    List<String> names = entity.find("not_find", new TypeReference<List<String>>() {
    }).orElse(Collections.emptyList());
    Assertions.assertNotNull(names);
    Assertions.assertTrue(names.isEmpty());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

TypeReference (jakarta.nosql.TypeReference)30 Test (org.junit.jupiter.api.Test)28 Value (jakarta.nosql.Value)10 Document (jakarta.nosql.document.Document)10 Column (jakarta.nosql.column.Column)9 List (java.util.List)9 DocumentCondition (jakarta.nosql.document.DocumentCondition)7 ColumnCondition (jakarta.nosql.column.ColumnCondition)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)4 KeyValueEntity (jakarta.nosql.keyvalue.KeyValueEntity)3 Actor (jakarta.nosql.tck.entities.Actor)3 Address (jakarta.nosql.tck.entities.Address)3 AppointmentBook (jakarta.nosql.tck.entities.AppointmentBook)3 Contact (jakarta.nosql.tck.entities.Contact)3 ContactType (jakarta.nosql.tck.entities.ContactType)3 Director (jakarta.nosql.tck.entities.Director)3 Download (jakarta.nosql.tck.entities.Download)3 Job (jakarta.nosql.tck.entities.Job)3 Money (jakarta.nosql.tck.entities.Money)3 Movie (jakarta.nosql.tck.entities.Movie)3