Search in sources :

Example 26 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.

the class DocumentQueryDeleteParser method parse.

public DocumentDeleteQuery parse(String methodName, Object[] args, ClassRepresentation representation, Converters converters) {
    String[] tokens = methodName.replace(PREFIX, DocumentQueryParserUtil.EMPTY).split(TOKENIZER);
    DocumentCondition condition = null;
    int index = 0;
    for (String token : tokens) {
        if (token.startsWith(DocumentQueryParserUtil.AND)) {
            ConditionResult result = and(args, index, token, methodName, representation, condition, converters);
            condition = result.getCondition();
            index = result.getIndex();
        } else if (token.startsWith(DocumentQueryParserUtil.OR)) {
            ConditionResult result = or(args, index, token, methodName, representation, condition, converters);
            condition = result.getCondition();
            index = result.getIndex();
        } else {
            condition = toCondition(token, index, args, methodName, representation, converters);
            index++;
        }
    }
    return new ArtemisDocumentDeleteQuery(representation.getName(), condition);
}
Also used : ConditionResult(org.jnosql.artemis.document.query.DocumentQueryParserUtil.ConditionResult) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 27 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.

the class DocumentQueryParser method parse.

public DocumentQuery parse(String methodName, Object[] args, ClassRepresentation representation, Converters converters) {
    String[] tokens = methodName.replace(PREFIX, EMPTY).split(TOKENIZER);
    String className = representation.getClassInstance().getName();
    DocumentCondition condition = null;
    List<Sort> sorts = new ArrayList<>();
    long limit = 0;
    long start = 0;
    int index = 0;
    for (String token : tokens) {
        if (token.startsWith(AND)) {
            DocumentQueryParserUtil.ConditionResult result = and(args, index, token, methodName, representation, condition, converters);
            condition = result.getCondition();
            index = result.getIndex();
        } else {
            if (token.startsWith(ORDER_BY)) {
                sort(sorts, token, representation);
            } else if (token.startsWith(DocumentQueryParserUtil.OR)) {
                DocumentQueryParserUtil.ConditionResult result = or(args, index, token, methodName, representation, condition, converters);
                condition = result.getCondition();
                index = result.getIndex();
            } else {
                condition = toCondition(token, index, args, methodName, representation, converters);
                index++;
            }
        }
    }
    while (index < args.length) {
        Object value = args[index];
        if (Sort.class.isInstance(value)) {
            sorts.add(Sort.class.cast(value));
        } else if (Pagination.class.isInstance(value)) {
            Pagination pagination = Pagination.class.cast(value);
            limit = pagination.getMaxResults();
            start = pagination.getFirstResult();
        } else {
            LOGGER.info(String.format("Ignoring parameter %s on  methodName %s class name %s arg-number: %d", String.valueOf(value), methodName, className, index));
        }
        index++;
    }
    return new ArtemisDocumentQuery(sorts, limit, start, condition, representation.getName());
}
Also used : ArrayList(java.util.ArrayList) Pagination(org.jnosql.artemis.Pagination) Sort(org.jnosql.diana.api.Sort) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 28 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.

the class DocumentQueryParserUtil method and.

static ConditionResult and(Object[] args, int index, String token, String methodName, ClassRepresentation representation, DocumentCondition queryCondition, Converters converters) {
    String field = token.replace(DocumentQueryParserUtil.AND, DocumentQueryParserUtil.EMPTY);
    DocumentCondition conditionResult = toCondition(field, index, args, methodName, representation, converters);
    DocumentCondition condition = null;
    if (queryCondition == null) {
        condition = conditionResult;
    } else {
        condition = queryCondition.and(conditionResult);
    }
    if (Condition.BETWEEN.equals(condition.getCondition())) {
        return new ConditionResult(index + 2, condition);
    } else {
        return new ConditionResult(++index, condition);
    }
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 29 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.

the class DocumentQueryParserUtil method or.

static ConditionResult or(Object[] args, int index, String token, String methodName, ClassRepresentation representation, DocumentCondition queryCondition, Converters converters) {
    String field = token.replace(DocumentQueryParserUtil.OR, DocumentQueryParserUtil.EMPTY);
    DocumentCondition conditionResult = toCondition(field, index, args, methodName, representation, converters);
    DocumentCondition condition = null;
    if (queryCondition == null) {
        condition = conditionResult;
    } else {
        condition = queryCondition.or(conditionResult);
    }
    if (Condition.BETWEEN.equals(condition.getCondition())) {
        return new ConditionResult(index + 2, condition);
    } else {
        return new ConditionResult(++index, condition);
    }
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 30 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.

the class AbstractMapperQuery method gtImpl.

protected void gtImpl(Number value) {
    requireNonNull(value, "value is required");
    DocumentCondition newCondition = DocumentCondition.gt(Document.of(representation.getColumnField(name), getValue(value)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Aggregations

DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)69 Test (org.junit.jupiter.api.Test)46 Document (org.jnosql.diana.api.document.Document)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)29 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)23 List (java.util.List)22 Person (org.jnosql.artemis.model.Person)13 Collections.singletonList (java.util.Collections.singletonList)7 Pagination (org.jnosql.artemis.Pagination)7 Sort (org.jnosql.diana.api.Sort)7 Proxy (java.lang.reflect.Proxy)6 Duration (java.time.Duration)6 Optional (java.util.Optional)6 Consumer (java.util.function.Consumer)6 Inject (javax.inject.Inject)6 CDIExtension (org.jnosql.artemis.CDIExtension)6 Converters (org.jnosql.artemis.Converters)6 DynamicQueryException (org.jnosql.artemis.DynamicQueryException)6 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)6 DocumentTemplateAsync (org.jnosql.artemis.document.DocumentTemplateAsync)6