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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations