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");
}
}
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());
}
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));
}
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));
}
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));
}
Aggregations