Search in sources :

Example 66 with DocumentCondition

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());
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 67 with DocumentCondition

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());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 68 with DocumentCondition

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));
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 69 with DocumentCondition

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))));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 70 with DocumentCondition

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());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (jakarta.nosql.document.DocumentCondition)132 Test (org.junit.jupiter.api.Test)68 DocumentQuery (jakarta.nosql.document.DocumentQuery)64 Document (jakarta.nosql.document.Document)60 List (java.util.List)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)4 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)4