use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class ResultRowImpl method getValue.
@Override
public PropertyValue getValue(String columnName) {
int index = query.getColumnIndex(columnName);
if (index >= 0) {
return values[index];
}
if (JcrConstants.JCR_PATH.equals(columnName)) {
return PropertyValues.newString(getPath());
}
// even though the query doesn't contain that column
if (columnName.startsWith(QueryImpl.REP_EXCERPT)) {
int columnIndex = query.getColumnIndex(QueryImpl.REP_EXCERPT);
PropertyValue indexExcerptValue = null;
if (columnIndex >= 0) {
indexExcerptValue = values[columnIndex];
if (indexExcerptValue != null) {
if (QueryImpl.REP_EXCERPT.equals(columnName) || SimpleExcerptProvider.REP_EXCERPT_FN.equals(columnName)) {
return SimpleExcerptProvider.getExcerpt(indexExcerptValue);
}
}
}
return getFallbackExcerpt(columnName, indexExcerptValue);
}
throw new IllegalArgumentException("Column not found: " + columnName);
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class ResultRowImpl method getComparator.
public static Comparator<ResultRowImpl> getComparator(final OrderingImpl[] orderings) {
if (orderings == null) {
return null;
}
return new Comparator<ResultRowImpl>() {
@Override
public int compare(ResultRowImpl o1, ResultRowImpl o2) {
PropertyValue[] orderValues = o1.getOrderValues();
PropertyValue[] orderValues2 = o2.getOrderValues();
int comp = 0;
for (int i = 0, size = orderings.length; i < size; i++) {
PropertyValue a = orderValues[i];
PropertyValue b = orderValues2[i];
if (a == null || b == null) {
if (a == b) {
comp = 0;
} else if (a == null) {
// TODO order by: nulls first (it looks like), or
// low?
comp = -1;
} else {
comp = 1;
}
} else {
comp = a.compareTo(b);
}
if (comp != 0) {
if (orderings[i].isDescending()) {
comp = -comp;
}
break;
}
}
return comp;
}
};
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class SQL2Parser method readString.
private PropertyValue readString() throws ParseException {
if (currentTokenType != VALUE) {
throw getSyntaxError("string value");
}
PropertyValue value = currentValue;
read();
return value;
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class ComparisonImpl method evaluate.
@Override
public boolean evaluate() {
// JCR 2.0 spec, 6.7.16 Comparison:
// "operand1 may evaluate to an array of values"
PropertyValue p1 = operand1.currentProperty();
if (p1 == null) {
return false;
}
PropertyValue p2 = operand2.currentValue();
if (p2 == null) {
// even for "null <> 'x'" (same as in SQL)
return false;
}
// "the value of operand2 is converted to the
// property type of the value of operand1" if possible
p2 = convertValueToType(p2, p1);
// if not possible, convert to the same type
if (p1.getType().tag() != p2.getType().tag()) {
// conversion failed: convert both to binary or string
int targetType = getCommonType(p1, p2);
p1 = convertToType(p1, targetType);
p2 = convertToType(p2, targetType);
}
if (p1.isArray()) {
// JCR 2.0 spec, 6.7.16 Comparison:
// "... constraint is satisfied as a whole if the comparison
// against any element of the array is satisfied."
Type<?> base = p1.getType().getBaseType();
for (int i = 0; i < p1.count(); i++) {
PropertyState value = PropertyStates.createProperty("value", p1.getValue(base, i), base);
if (operator.evaluate(PropertyValues.create(value), p2)) {
return true;
}
}
return false;
} else {
return operator.evaluate(p1, p2);
}
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class SimilarImpl method restrict.
@Override
public void restrict(FilterImpl f) {
if (f.getSelector().equals(selector)) {
PropertyValue p = pathExpression.currentValue();
String path = p.getValue(Type.STRING);
String query = MORE_LIKE_THIS_PREFIX + path;
PropertyValue v = PropertyValues.newString(query);
f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v);
}
}
Aggregations