use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameAnd.
@Test
public void shouldSelectWhereNameAnd() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentQuery query = select().from(documentCollection).where("name").eq(name).and("age").gt(10).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
});
assertEquals(Condition.AND, condition.getCondition());
assertThat(conditions, Matchers.containsInAnyOrder(eq(Document.of("name", name)), DocumentCondition.gt(Document.of("age", 10))));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class SelectQueryParser method getDocumentQuery.
private DocumentQuery getDocumentQuery(String query, DocumentObserverParser observer) {
SelectQuery selectQuery = selectQueryProvider.apply(query);
String collection = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
DocumentCondition condition = null;
Params params = Params.newParams();
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class SelectQueryParser method getDocumentQuery.
private DocumentQuery getDocumentQuery(Params params, SelectQuery selectQuery, DocumentObserverParser observer) {
String collection = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
DocumentCondition condition = null;
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
return new DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameNot.
@Test
public void shouldSelectWhereNameNot() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentDeleteQuery query = delete().from(documentCollection).where("name").not().eq(name).build();
DocumentCondition condition = query.getCondition().get();
Document column = condition.getDocument();
DocumentCondition negate = column.get(DocumentCondition.class);
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.NOT, condition.getCondition());
assertEquals(Condition.EQUALS, negate.getCondition());
assertEquals("name", negate.getDocument().getName());
assertEquals(name, negate.getDocument().get());
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameGte.
@Test
public void shouldSelectWhereNameGte() {
String documentCollection = "documentCollection";
Number value = 10;
DocumentDeleteQuery query = delete().from(documentCollection).where("name").gte(value).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.GREATER_EQUALS_THAN, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(value, document.get());
}
Aggregations