Search in sources :

Example 16 with TypeReference

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

the class DocumentQueryConversor method feedQuery.

private static void feedQuery(IDocumentQuery<HashMap> ravenQuery, DocumentCondition condition, List<String> ids) {
    Document document = condition.getDocument();
    Object value = document.get();
    String name = document.getName();
    if (EntityConverter.ID_FIELD.equals(name)) {
        if (value instanceof Iterable) {
            final Iterable iterable = Iterable.class.cast(value);
            iterable.forEach(i -> ids.add(i.toString()));
        } else {
            ids.add(value.toString());
        }
        return;
    }
    switch(condition.getCondition()) {
        case EQUALS:
            ravenQuery.whereEquals(name, value);
            return;
        case GREATER_THAN:
            ravenQuery.whereGreaterThan(name, value);
            return;
        case GREATER_EQUALS_THAN:
            ravenQuery.whereGreaterThanOrEqual(name, value);
            return;
        case LESSER_THAN:
            ravenQuery.whereLessThan(name, value);
            return;
        case LESSER_EQUALS_THAN:
            ravenQuery.whereLessThanOrEqual(name, value);
            return;
        case IN:
            ravenQuery.whereIn(name, ValueUtil.convertToList(document.getValue()));
            return;
        case NOT:
            ravenQuery.negateNext();
            feedQuery(ravenQuery, document.get(DocumentCondition.class), ids);
            return;
        case LIKE:
            throw new UnsupportedOperationException("Raven does not support LIKE Operator");
        case AND:
            condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
            }).forEach(c -> feedQuery(ravenQuery.andAlso(), c, ids));
            return;
        case OR:
            condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
            }).forEach(c -> feedQuery(ravenQuery.orElse(), c, ids));
            return;
        default:
            throw new UnsupportedOperationException("The condition " + condition.getCondition() + " is not supported from ravendb diana driver");
    }
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 17 with TypeReference

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

the class ColumnEntityTest method shouldNotFindTypeSupplier.

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

Example 18 with TypeReference

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

the class DefaultColumnConditionTest method shouldAnd.

@Test
public void shouldAnd() {
    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 and = eq.and(gt);
    List<ColumnCondition> conditions = and.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.AND, and.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    ColumnCondition result = and.and(lte);
    assertEquals(Condition.AND, 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 19 with TypeReference

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

the class DefaultColumnConditionTest method shouldCreateAndCondition.

@Test
public void shouldCreateAndCondition() {
    Column age = Column.of("age", 26);
    Column name = Column.of("name", "Otavio");
    ColumnCondition condition1 = DefaultColumnCondition.of(name, Condition.EQUALS);
    ColumnCondition condition2 = DefaultColumnCondition.of(age, Condition.GREATER_THAN);
    ColumnCondition and = condition1.and(condition2);
    Column andColumn = and.getColumn();
    assertEquals(Condition.AND, and.getCondition());
    assertEquals(Condition.AND.getNameField(), andColumn.getName());
    assertThat(andColumn.getValue().get(new TypeReference<List<ColumnCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 20 with TypeReference

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

the class DefaultColumnConditionTest method shouldCreateOrCondition.

@Test
public void shouldCreateOrCondition() {
    Column age = Column.of("age", 26);
    Column name = Column.of("name", "Otavio");
    ColumnCondition condition1 = DefaultColumnCondition.of(name, Condition.EQUALS);
    ColumnCondition condition2 = DefaultColumnCondition.of(age, Condition.GREATER_THAN);
    ColumnCondition and = condition1.or(condition2);
    Column andColumn = and.getColumn();
    assertEquals(Condition.OR, and.getCondition());
    assertEquals(Condition.OR.getNameField(), andColumn.getName());
    assertThat(andColumn.getValue().get(new TypeReference<List<ColumnCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) 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