use of javax.jcr.query.qom.PropertyValue in project jackrabbit-oak by apache.
the class QomTest method createQuery.
@Test
public void createQuery() throws RepositoryException {
Selector s = f.selector("nt:file", "x");
BindVariableValue b = f.bindVariable("var");
Constraint c = f.propertyExistence("x", "c");
PropertyValue p = f.propertyValue("x", "propertyName");
c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
Ordering o = f.ascending(p);
Column col = f.column("x", "propertyName", "columnName");
Ordering[] ords = new Ordering[] { o };
Column[] cols = new Column[] { col };
QueryObjectModel q = f.createQuery(s, c, ords, cols);
assertEquals(Query.JCR_JQOM, q.getLanguage());
String[] bv = q.getBindVariableNames();
assertEquals(1, bv.length);
assertEquals("var", bv[0]);
assertEquals(s, q.getSource());
assertEquals(c, q.getConstraint());
assertEquals(o, q.getOrderings()[0]);
assertEquals(col, q.getColumns()[0]);
}
use of javax.jcr.query.qom.PropertyValue in project jackrabbit-oak by apache.
the class QomTest method length.
@Test
public void length() throws RepositoryException {
PropertyValue p = f.propertyValue("selectorName", "propertyName");
Length l = f.length(p);
assertEquals(p, l.getPropertyValue());
assertEquals("LENGTH([selectorName].[propertyName])", l.toString());
}
use of javax.jcr.query.qom.PropertyValue in project jackrabbit by apache.
the class OperandEvaluator method getLengthValues.
/**
* Returns the values of the given value length operand for the given node.
*
* @see #getProperty(PropertyValue, Node)
* @param operand value length operand
* @param node node
* @return values of the operand for the given node
* @throws RepositoryException if the operand can't be evaluated
*/
private Value[] getLengthValues(Length operand, Node n) throws RepositoryException {
Property property = getProperty(operand.getPropertyValue(), n);
if (property == null) {
return new Value[0];
}
if (property.isMultiple()) {
long[] lengths = property.getLengths();
Value[] values = new Value[lengths.length];
for (int i = 0; i < lengths.length; i++) {
values[i] = factory.createValue(lengths[i]);
}
return values;
}
long length = property.getLength();
return new Value[] { factory.createValue(length) };
}
use of javax.jcr.query.qom.PropertyValue in project jackrabbit by apache.
the class LuceneQueryFactory method getComparisonQuery.
protected Query getComparisonQuery(DynamicOperand left, int transform, String operator, StaticOperand rigth, Map<String, NodeType> selectorMap) throws RepositoryException {
if (left instanceof PropertyValue) {
PropertyValue pv = (PropertyValue) left;
String field = npResolver.getJCRName(session.getQName(pv.getPropertyName()));
int type = PropertyType.UNDEFINED;
NodeType nt = selectorMap.get(pv.getSelectorName());
if (nt != null) {
for (PropertyDefinition pd : nt.getPropertyDefinitions()) {
if (pd.getName().equals(pv.getPropertyName())) {
type = pd.getRequiredType();
break;
}
}
}
return getPropertyValueQuery(field, operator, evaluator.getValue(rigth), type, transform);
} else if (left instanceof NodeName) {
return getNodeNameQuery(transform, operator, rigth);
} else if (left instanceof NodeLocalName) {
return getNodeLocalNameQuery(transform, operator, rigth);
} else {
throw new UnsupportedRepositoryOperationException(// FIXME
"Unknown operand type: " + left);
}
}
use of javax.jcr.query.qom.PropertyValue in project jackrabbit by apache.
the class OperandEvaluator method getValues.
/**
* Evaluates the given operand in the context of the given row.
*
* @param operand operand to be evaluated
* @param row query result row
* @return values of the operand at the given row
* @throws RepositoryException if the operand can't be evaluated
*/
public Value[] getValues(Operand operand, Row row) throws RepositoryException {
if (operand instanceof StaticOperand) {
StaticOperand so = (StaticOperand) operand;
return new Value[] { getValue(so) };
} else if (operand instanceof FullTextSearchScore) {
FullTextSearchScore ftss = (FullTextSearchScore) operand;
double score = row.getScore(ftss.getSelectorName());
return new Value[] { factory.createValue(score) };
} else if (operand instanceof NodeName) {
NodeName nn = (NodeName) operand;
String name = row.getNode(nn.getSelectorName()).getName();
// root node
if ("".equals(name)) {
return new Value[] { factory.createValue(name, PropertyType.STRING) };
}
return new Value[] { factory.createValue(name, PropertyType.NAME) };
} else if (operand instanceof Length) {
return getLengthValues((Length) operand, row);
} else if (operand instanceof LowerCase) {
return getLowerCaseValues((LowerCase) operand, row);
} else if (operand instanceof UpperCase) {
return getUpperCaseValues((UpperCase) operand, row);
} else if (operand instanceof NodeLocalName) {
return getNodeLocalNameValues((NodeLocalName) operand, row);
} else if (operand instanceof PropertyValue) {
return getPropertyValues((PropertyValue) operand, row);
} else {
throw new UnsupportedRepositoryOperationException("Unknown operand type: " + operand);
}
}
Aggregations