Search in sources :

Example 6 with N1QLExpression

use of org.springframework.data.couchbase.core.query.N1QLExpression in project spring-data-couchbase by spring-projects.

the class OldN1qlQueryCreator method complete.

@Override
protected N1QLExpression complete(N1QLExpression criteria, Sort sort) {
    N1QLExpression whereCriteria = N1qlUtils.createWhereFilterForEntity(criteria, this.converter, this.queryMethod.getEntityInformation());
    N1QLExpression selectFromWhere = selectFrom.where(whereCriteria);
    // sort of the Pageable takes precedence over the sort in the query name
    if ((queryMethod.isPageQuery() || queryMethod.isSliceQuery()) && accessor.getPageable().isPaged()) {
        Pageable pageable = accessor.getPageable();
        sort = pageable.getSort();
    }
    if (sort.isSorted()) {
        N1QLExpression[] cbSorts = N1qlUtils.createSort(sort);
        return selectFromWhere.orderBy(cbSorts);
    }
    return selectFromWhere;
}
Also used : Pageable(org.springframework.data.domain.Pageable) N1QLExpression(org.springframework.data.couchbase.core.query.N1QLExpression)

Example 7 with N1QLExpression

use of org.springframework.data.couchbase.core.query.N1QLExpression in project spring-data-couchbase by spring-projects.

the class PartTreeN1qlBasedQuery method getCount.

@Override
protected N1QLExpression getCount(ParameterAccessor accessor, Object[] runtimeParameters) {
    N1QLExpression bucket = i(getCouchbaseOperations().getBucketName());
    N1QLExpression countFrom = select(count(x("*")).as(x(CountFragment.COUNT_ALIAS))).from(bucket);
    N1qlCountQueryCreator queryCountCreator = new N1qlCountQueryCreator(partTree, accessor, countFrom, getCouchbaseOperations().getConverter(), getQueryMethod());
    N1QLExpression statement = queryCountCreator.createQuery();
    this.placeHolderValues = queryCountCreator.getPlaceHolderValues();
    return statement;
}
Also used : N1QLExpression(org.springframework.data.couchbase.core.query.N1QLExpression)

Example 8 with N1QLExpression

use of org.springframework.data.couchbase.core.query.N1QLExpression in project spring-data-couchbase by spring-projects.

the class ReactiveAbstractN1qlBasedQuery method execute.

@Override
public Object execute(Object[] parameters) {
    ReactiveCouchbaseParameterAccessor accessor = new ReactiveCouchbaseParameterAccessor(queryMethod, parameters);
    ResultProcessor processor = this.queryMethod.getResultProcessor().withDynamicProjection(accessor);
    ReturnedType returnedType = processor.getReturnedType();
    Class<?> typeToRead = returnedType.getTypeToRead();
    typeToRead = typeToRead == null ? returnedType.getDomainType() : typeToRead;
    N1QLExpression expression = getExpression(accessor, parameters, returnedType);
    JsonValue queryPlaceholderValues = getPlaceholderValues(accessor);
    // prepare the final query
    N1QLQuery query = N1qlUtils.buildQuery(expression, queryPlaceholderValues, getScanConsistency());
    return ReactiveWrapperConverters.toWrapper(processor.processResult(executeDependingOnType(query, queryMethod, typeToRead)), Flux.class);
}
Also used : N1QLQuery(org.springframework.data.couchbase.core.query.N1QLQuery) JsonValue(com.couchbase.client.java.json.JsonValue) N1QLExpression(org.springframework.data.couchbase.core.query.N1QLExpression) ResultProcessor(org.springframework.data.repository.query.ResultProcessor) ReturnedType(org.springframework.data.repository.query.ReturnedType)

Example 9 with N1QLExpression

use of org.springframework.data.couchbase.core.query.N1QLExpression in project spring-data-couchbase by spring-projects.

the class StringBasedN1qlQueryParser method getExpression.

// copied from StringN1qlBasedQuery
private N1QLExpression getExpression(ParameterAccessor accessor, ReturnedType returnedType, SpelExpressionParser parser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
    boolean isCountQuery = queryMethod.isCountQuery();
    Object[] runtimeParameters = getParameters(accessor);
    EvaluationContext evaluationContext = evaluationContextProvider.getEvaluationContext(queryMethod.getParameters(), runtimeParameters);
    N1QLExpression parsedStatement = x(this.doParse(parser, evaluationContext, isCountQuery));
    return parsedStatement;
}
Also used : N1QLExpression(org.springframework.data.couchbase.core.query.N1QLExpression) JsonObject(com.couchbase.client.java.json.JsonObject) EvaluationContext(org.springframework.expression.EvaluationContext)

Example 10 with N1QLExpression

use of org.springframework.data.couchbase.core.query.N1QLExpression in project spring-data-couchbase by spring-projects.

the class N1qlQueryCreatorUtils method like.

protected static N1QLExpression like(Iterator<Object> parameterValues, boolean ignoreCase, boolean anyPrefix, boolean anySuffix) {
    Object next = parameterValues.next();
    if (next == null) {
        return N1QLExpression.NULL();
    }
    N1QLExpression converted;
    if (next instanceof String) {
        String pattern = (String) next;
        if (anyPrefix) {
            pattern = "%" + pattern;
        }
        if (anySuffix) {
            pattern = pattern + "%";
        }
        converted = s(pattern);
    } else {
        converted = x(String.valueOf(next));
    }
    if (ignoreCase) {
        return converted.lower();
    }
    return converted;
}
Also used : N1QLExpression(org.springframework.data.couchbase.core.query.N1QLExpression)

Aggregations

N1QLExpression (org.springframework.data.couchbase.core.query.N1QLExpression)13 ArrayList (java.util.ArrayList)3 JsonValue (com.couchbase.client.java.json.JsonValue)2 N1QLQuery (org.springframework.data.couchbase.core.query.N1QLQuery)2 Pageable (org.springframework.data.domain.Pageable)2 ResultProcessor (org.springframework.data.repository.query.ResultProcessor)2 ReturnedType (org.springframework.data.repository.query.ReturnedType)2 JsonObject (com.couchbase.client.java.json.JsonObject)1 Sort (org.springframework.data.domain.Sort)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1 EvaluationContext (org.springframework.expression.EvaluationContext)1