use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByAgeBetween.
@Test
public void shouldFindByAgeBetween() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeBetween(10, 15);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(BETWEEN, condition.getCondition());
assertEquals(Document.of("age", Arrays.asList(10, 15)), condition.getDocument());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameLike.
@Test
public void shouldFindByNameLike() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByNameLike("Ada");
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(LIKE, condition.getCondition());
assertEquals(Document.of("name", "Ada"), condition.getDocument());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameAndAgeGreaterEqualThan.
@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(AND, condition.getCondition());
List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
assertThat(conditions, containsInAnyOrder(eq(Document.of("name", "Ada")), gte(Document.of("age", 33))));
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByAgeLessThanEqual.
@Test
public void shouldFindByAgeLessThanEqual() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeLessThanEqual(33);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(LESSER_EQUALS_THAN, condition.getCondition());
assertEquals(Document.of("age", 33), condition.getDocument());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverter method definesCondition.
private static void definesCondition(DocumentCondition condition, StringBuilder query, List<Object> params, int counter) {
Document document = condition.getDocument();
switch(condition.getCondition()) {
case IN:
appendCondition(query, params, document, IN);
return;
case EQUALS:
appendCondition(query, params, document, EQUALS);
return;
case GREATER_EQUALS_THAN:
appendCondition(query, params, document, GREATER_EQUALS_THAN);
return;
case GREATER_THAN:
appendCondition(query, params, document, GREATER_THAN);
return;
case LESSER_THAN:
appendCondition(query, params, document, LESSER_THAN);
return;
case LESSER_EQUALS_THAN:
appendCondition(query, params, document, LESSER_EQUALS_THAN);
return;
case LIKE:
appendCondition(query, params, document, LIKE);
return;
case AND:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(AND);
}
definesCondition(dc, query, params, ++counter);
}
return;
case OR:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(OR);
}
definesCondition(dc, query, params, ++counter);
}
return;
case NOT:
DocumentCondition documentCondition = document.get(DocumentCondition.class);
query.append("NOT (");
definesCondition(documentCondition, query, params, ++counter);
query.append(")");
return;
default:
throw new IllegalArgumentException("Orient DB has not support to the condition " + condition.getCondition());
}
}
Aggregations