use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameGt.
@Test
public void shouldSelectWhereNameGt() {
String documentCollection = "documentCollection";
Number value = 10;
DocumentQuery query = select().from(documentCollection).where("name").gt(value).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.GREATER_THAN, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(value, document.get());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.
@Test
public void shouldSelectWhereNameEq() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentQuery query = select().from(documentCollection).where("name").eq(name).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(name, document.get());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana-driver by eclipse.
the class QueryAQLConverter method definesCondition.
private static void definesCondition(DocumentCondition condition, StringBuilder aql, Map<String, Object> params, char entity, int counter) {
Document document = condition.getDocument();
switch(condition.getCondition()) {
case IN:
appendCondition(aql, params, entity, document, IN);
return;
case EQUALS:
appendCondition(aql, params, entity, document, EQUALS);
return;
case GREATER_EQUALS_THAN:
appendCondition(aql, params, entity, document, GREATER_EQUALS_THAN);
return;
case GREATER_THAN:
appendCondition(aql, params, entity, document, GREATER_THAN);
return;
case LESSER_THAN:
appendCondition(aql, params, entity, document, LESSER_THAN);
return;
case LESSER_EQUALS_THAN:
appendCondition(aql, params, entity, document, LESSER_EQUALS_THAN);
return;
case LIKE:
appendCondition(aql, params, entity, document, LIKE);
return;
case AND:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(aql, counter)) {
aql.append(AND);
}
definesCondition(dc, aql, params, entity, ++counter);
}
return;
case OR:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(aql, counter)) {
aql.append(OR);
}
definesCondition(dc, aql, params, entity, ++counter);
}
return;
case NOT:
DocumentCondition documentCondition = document.get(DocumentCondition.class);
aql.append(NOT);
definesCondition(documentCondition, aql, params, entity, ++counter);
return;
default:
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.getCondition());
}
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana-driver by eclipse.
the class DocumentQueryConversor method convert.
public static Bson convert(DocumentCondition condition) {
Document document = condition.getDocument();
Object value = document.get();
switch(condition.getCondition()) {
case EQUALS:
return Filters.eq(document.getName(), value);
case GREATER_THAN:
return Filters.gt(document.getName(), value);
case GREATER_EQUALS_THAN:
return Filters.gte(document.getName(), value);
case LESSER_THAN:
return Filters.lt(document.getName(), value);
case LESSER_EQUALS_THAN:
return Filters.lte(document.getName(), value);
case IN:
List<Object> inList = document.get(new TypeReference<List<Object>>() {
});
return Filters.in(document.getName(), inList.toArray());
case LIKE:
return Filters.regex(document.getName(), value.toString());
case AND:
List<DocumentCondition> andList = condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
});
return Filters.and(andList.stream().map(DocumentQueryConversor::convert).collect(Collectors.toList()));
case OR:
List<DocumentCondition> orList = condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
});
return Filters.or(orList.stream().map(DocumentQueryConversor::convert).collect(Collectors.toList()));
default:
throw new UnsupportedOperationException("The condition " + condition.getCondition() + " is not supported from mongoDB diana driver");
}
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateTest method shouldReturnFind.
@Test
public void shouldReturnFind() {
subject.find(Person.class, "10");
ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(managerMock).select(queryCaptor.capture());
DocumentQuery query = queryCaptor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), condition);
}
Aggregations