use of com.couchbase.client.java.json.JsonValue in project spring-data-couchbase by spring-projects.
the class StringQuery method toN1qlSelectString.
@Override
public String toN1qlSelectString(ReactiveCouchbaseTemplate template, String collection, Class domainClass, Class resultClass, boolean isCount, String[] distinctFields, String[] fields) {
final StringBuilder statement = new StringBuilder();
boolean makeCount = isCount && inlineN1qlQuery != null && !inlineN1qlQuery.toLowerCase(Locale.ROOT).contains("count(");
if (makeCount) {
statement.append("SELECT COUNT(*) AS " + TemplateUtils.SELECT_COUNT + " FROM (");
}
// apply the string statement
appendInlineN1qlStatement(statement);
// To use generated parameters for literals
// we need to figure out if we must use positional or named parameters
// If we are using positional parameters, we need to start where
// the inlineN1ql left off.
int[] paramIndexPtr = null;
JsonValue params = this.getParameters();
if (params instanceof JsonArray) {
// positional parameters
paramIndexPtr = new int[] { ((JsonArray) params).size() };
} else {
// named parameters or no parameters, no index required
paramIndexPtr = new int[] { -1 };
}
// criteria on this Query - should be empty for
appendWhere(statement, paramIndexPtr, template.getConverter());
if (!isCount) {
appendSort(statement);
appendSkipAndLimit(statement);
}
if (makeCount) {
statement.append(") predicate_query");
}
return statement.toString();
}
use of com.couchbase.client.java.json.JsonValue in project spring-data-couchbase by spring-projects.
the class AbstractN1qlBasedQuery method execute.
@Override
public Object execute(Object[] parameters) {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(queryMethod.getParameters(), parameters);
ResultProcessor processor = this.queryMethod.getResultProcessor().withDynamicProjection(accessor);
ReturnedType returnedType = processor.getReturnedType();
// TODO: review this - I just hacked it to work, basically...
// This was what was here in sdk2, but seem to end up being always Object. Forcing
// it to be the same as the object type for the repo.
// Class<?> typeToRead = returnedType.getTypeToRead();
// typeToRead = typeToRead == null ? returnedType.getDomainType() : typeToRead;
Class<?> typeToRead = queryMethod.getEntityInformation().getJavaType();
N1QLExpression statement = getExpression(accessor, parameters, returnedType);
JsonValue queryPlaceholderValues = getPlaceholderValues(accessor);
// prepare the final query
N1QLQuery query = buildQuery(statement, queryPlaceholderValues, getScanConsistency());
// prepare a count query
N1QLExpression countStatement = getCount(accessor, parameters);
// the place holder values are the same for the count query as well
N1QLQuery countQuery = buildQuery(countStatement, queryPlaceholderValues, getScanConsistency());
return processor.processResult(executeDependingOnType(query, countQuery, queryMethod, accessor.getPageable(), typeToRead));
}
use of com.couchbase.client.java.json.JsonValue 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 com.couchbase.client.java.json.JsonValue in project spring-data-couchbase by spring-projects.
the class StringN1qlQueryCreator method complete.
@Override
protected Query complete(QueryCriteria criteria, Sort sort) {
Query q = new StringQuery(parsedExpression.toString()).with(sort);
JsonValue params = queryParser.getPlaceholderValues(accessor);
if (params instanceof JsonArray) {
q.setPositionalParameters((JsonArray) params);
} else {
q.setNamedParameters((JsonObject) params);
}
return q;
}
Aggregations