use of jakarta.nosql.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, List<ORecordId> ids) {
Document document = condition.getDocument();
switch(condition.getCondition()) {
case IN:
appendCondition(query, params, document, IN, ids);
return;
case EQUALS:
appendCondition(query, params, document, EQUALS, ids);
return;
case GREATER_EQUALS_THAN:
appendCondition(query, params, document, GREATER_EQUALS_THAN, ids);
return;
case GREATER_THAN:
appendCondition(query, params, document, GREATER_THAN, ids);
return;
case LESSER_THAN:
appendCondition(query, params, document, LESSER_THAN, ids);
return;
case LESSER_EQUALS_THAN:
appendCondition(query, params, document, LESSER_EQUALS_THAN, ids);
return;
case LIKE:
appendCondition(query, params, document, LIKE, ids);
return;
case AND:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(AND);
}
definesCondition(dc, query, params, ++counter, ids);
}
return;
case OR:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(OR);
}
definesCondition(dc, query, params, ++counter, ids);
}
return;
case NOT:
DocumentCondition documentCondition = document.get(DocumentCondition.class);
query.append("NOT (");
definesCondition(documentCondition, query, params, ++counter, ids);
query.append(")");
return;
default:
throw new IllegalArgumentException("Orient DB has not support to the condition " + condition.getCondition());
}
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLike.
@Test
public void shouldSelectWhereNameLike() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentDeleteQuery query = delete().from(documentCollection).where("name").like(name).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.LIKE, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(name, document.get());
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameBetween.
@Test
public void shouldSelectWhereNameBetween() {
String documentCollection = "documentCollection";
Number valueA = 10;
Number valueB = 20;
DocumentDeleteQuery query = delete().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.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameAnd.
@Test
public void shouldSelectWhereNameAnd() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentDeleteQuery query = delete().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 DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLte.
@Test
public void shouldSelectWhereNameLte() {
String documentCollection = "documentCollection";
Number value = 10;
DocumentDeleteQuery query = delete().from(documentCollection).where("name").lte(value).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.LESSER_EQUALS_THAN, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(value, document.get());
}
Aggregations