use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class FilterTest method propertyRestriction.
@Test
public void propertyRestriction() {
PropertyValue one = PropertyValues.newString("1");
PropertyValue two = PropertyValues.newString("2");
FilterImpl f = FilterImpl.newTestInstance();
assertTrue(null == f.getPropertyRestriction("x"));
f.restrictProperty("x", Operator.LESS_OR_EQUAL, two);
assertEquals("Filter(, path=*, property=[x=[..2]]])", f.toString());
f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
// no change, as the same restrictions already were added
f.restrictProperty("x", Operator.LESS_OR_EQUAL, two);
assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
f.restrictProperty("x", Operator.GREATER_THAN, one);
assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1..]])", f.toString());
f.restrictProperty("x", Operator.LESS_THAN, two);
assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1.., ..2)]])", f.toString());
// TODO could replace / remove the old range conditions,
// if there is an overlap
f.restrictProperty("x", Operator.EQUAL, two);
assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1.., ..2), 2]])", f.toString());
f = FilterImpl.newTestInstance();
f.restrictProperty("x", Operator.EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
f.restrictProperty("x", Operator.EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
// TODO could replace / remove the old range conditions,
// if there is an overlap
f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[1, [1..]])", f.toString());
f.restrictProperty("x", Operator.LESS_OR_EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[1, [1.., ..1]]])", f.toString());
// TODO could replace / remove the old range conditions,
// if there is an overlap
f.restrictProperty("x", Operator.GREATER_THAN, one);
assertEquals("Filter(, path=*, property=[x=[1, [1.., ..1], (1..]])", f.toString());
f = FilterImpl.newTestInstance();
f.restrictProperty("x", Operator.EQUAL, one);
assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
// TODO could replace / remove the old range conditions,
// if there is an overlap
f.restrictProperty("x", Operator.LESS_THAN, one);
assertEquals("Filter(, path=*, property=[x=[1, ..1)]])", f.toString());
f = FilterImpl.newTestInstance();
f.restrictProperty("x", Operator.NOT_EQUAL, null);
assertEquals("Filter(, path=*, property=[x=[is not null]])", f.toString());
f.restrictProperty("x", Operator.LESS_THAN, one);
assertEquals("Filter(, path=*, property=[x=[is not null, ..1)]])", f.toString());
// this should replace the range with an equality
// (which is faster, and correct even when using multi-valued properties)
f.restrictProperty("x", Operator.EQUAL, two);
assertEquals("Filter(, path=*, property=[x=[is not null, ..1), 2]])", f.toString());
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class AbstractQueryTest method readRow.
protected static String readRow(ResultRow row, boolean pathOnly) {
if (pathOnly) {
return row.getValue(QueryImpl.JCR_PATH).getValue(Type.STRING);
}
StringBuilder buff = new StringBuilder();
PropertyValue[] values = row.getValues();
for (int i = 0; i < values.length; i++) {
if (i > 0) {
buff.append(", ");
}
PropertyValue v = values[i];
if (v == null) {
buff.append("null");
} else if (v.isArray()) {
buff.append('[');
for (int j = 0; j < v.count(); j++) {
buff.append(v.getValue(Type.STRING, j));
if (j > 0) {
buff.append(", ");
}
}
buff.append(']');
} else {
buff.append(v.getValue(Type.STRING));
}
}
return buff.toString();
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class IdentifierManager method resolveUUID.
private String resolveUUID(PropertyValue uuid) {
try {
Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid);
Result result = root.getQueryEngine().executeQuery("SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS);
String path = null;
for (ResultRow rr : result.getRows()) {
if (path != null) {
log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath());
return null;
} else {
path = rr.getPath();
}
}
return path;
} catch (ParseException ex) {
log.error("query failed", ex);
return null;
}
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class NodeCounterIndexTest method executeXPathQuery.
protected String executeXPathQuery(String statement) throws ParseException {
Result result = qe.executeQuery(statement, "xpath", null, NO_MAPPINGS);
StringBuilder buff = new StringBuilder();
for (ResultRow row : result.getRows()) {
for (PropertyValue v : row.getValues()) {
buff.append(v);
}
}
return buff.toString();
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class QueryImpl method currentRow.
ResultRowImpl currentRow() {
int selectorCount = selectors.size();
Tree[] trees = new Tree[selectorCount];
for (int i = 0; i < selectorCount; i++) {
SelectorImpl s = selectors.get(i);
trees[i] = s.currentTree();
}
int columnCount = columns.length;
PropertyValue[] values = new PropertyValue[columnCount];
for (int i = 0; i < columnCount; i++) {
ColumnImpl c = columns[i];
values[i] = c.currentProperty();
}
PropertyValue[] orderValues;
if (orderings == null) {
orderValues = null;
} else {
int size = orderings.length;
orderValues = new PropertyValue[size];
for (int i = 0; i < size; i++) {
orderValues[i] = orderings[i].getOperand().currentProperty();
}
}
return new ResultRowImpl(this, trees, values, distinctColumns, orderValues);
}
Aggregations