DATACOUCH-583 - Nested properties in queries not working. (#270)
The complete property path was being quoted instead of the individual components. ie. `address.street` instead of `address`.`street` Also fixed another issue - changed the maybeQuote() method for property names to correctly look for back-tics instead of double quotes and changed the name accordingly. Co-authored-by: mikereiche <michael.reiche@couchbase.com>
This commit is contained in:
@@ -343,7 +343,7 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
*/
|
||||
private StringBuilder exportSingle(StringBuilder sb, int[] paramIndexPtr, JsonValue parameters,
|
||||
CouchbaseConverter converter) {
|
||||
String fieldName = maybeQuote(key);
|
||||
String fieldName = maybeBackTic(key);
|
||||
int valueLen = value == null ? 0 : value.length;
|
||||
Object[] v = new Object[valueLen + 2];
|
||||
v[0] = fieldName;
|
||||
@@ -445,8 +445,8 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
posValues.add(ja);
|
||||
}
|
||||
|
||||
private String maybeQuote(String value) {
|
||||
if (value == null || (value.startsWith("\"") && value.endsWith("\""))) {
|
||||
private String maybeBackTic(String value) {
|
||||
if (value == null || (value.startsWith("`") && value.endsWith("`"))) {
|
||||
return value;
|
||||
} else {
|
||||
return "`" + value + "`";
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.springframework.data.couchbase.core.query.QueryCriteria.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
|
||||
import org.springframework.data.couchbase.core.query.Query;
|
||||
@@ -56,9 +57,13 @@ public class N1qlQueryCreator extends AbstractQueryCreator<Query, QueryCriteria>
|
||||
protected QueryCriteria create(final Part part, final Iterator<Object> iterator) {
|
||||
PersistentPropertyPath<CouchbasePersistentProperty> path = context.getPersistentPropertyPath(part.getProperty());
|
||||
CouchbasePersistentProperty property = path.getLeafProperty();
|
||||
return from(part, property, where(path.toDotPath()), iterator);
|
||||
return from(part, property, where(path.toDotPath(cvtr)), iterator);
|
||||
}
|
||||
|
||||
static Converter<? super CouchbasePersistentProperty, String> cvtr = (
|
||||
source) -> new StringBuilder(source.getName().length() + 2).append('`').append(source.getName()).append('`')
|
||||
.toString();
|
||||
|
||||
@Override
|
||||
protected QueryCriteria and(final Part part, final QueryCriteria base, final Iterator<Object> iterator) {
|
||||
if (base == null) {
|
||||
|
||||
Reference in New Issue
Block a user