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