use of javax.jcr.query.qom.Literal in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testLiteral.
/**
* Test case for {@link QueryObjectModelFactory#literal(Value)}
*/
public void testLiteral() throws RepositoryException {
Value v = superuser.getValueFactory().createValue("test");
Literal literal = qf.literal(v);
assertEquals("Wrong literal value", v.getString(), literal.getLiteralValue().getString());
}
use of javax.jcr.query.qom.Literal in project jackrabbit by apache.
the class EquiJoinMerger method getRightJoinConstraints.
@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
Map<String, Literal> literals = new HashMap<String, Literal>();
for (Row leftRow : leftRows) {
for (Value value : evaluator.getValues(leftProperty, leftRow)) {
literals.put(value.getString(), factory.literal(value));
}
}
List<Constraint> constraints = new ArrayList<Constraint>(literals.size());
for (Literal literal : literals.values()) {
constraints.add(factory.comparison(rightProperty, JCR_OPERATOR_EQUAL_TO, literal));
}
return constraints;
}
use of javax.jcr.query.qom.Literal in project jackrabbit by apache.
the class Parser method parseStaticOperand.
private StaticOperand parseStaticOperand() throws RepositoryException {
if (currentTokenType == PLUS) {
read();
} else if (currentTokenType == MINUS) {
read();
if (currentTokenType != VALUE) {
throw getSyntaxError("number");
}
int valueType = currentValue.getType();
switch(valueType) {
case PropertyType.LONG:
currentValue = valueFactory.createValue(-currentValue.getLong());
break;
case PropertyType.DOUBLE:
currentValue = valueFactory.createValue(-currentValue.getDouble());
break;
case PropertyType.BOOLEAN:
currentValue = valueFactory.createValue(!currentValue.getBoolean());
break;
case PropertyType.DECIMAL:
currentValue = valueFactory.createValue(currentValue.getDecimal().negate());
break;
default:
throw getSyntaxError("Illegal operation: -" + currentValue);
}
}
if (currentTokenType == VALUE) {
Literal literal = getUncastLiteral(currentValue);
read();
return literal;
} else if (currentTokenType == PARAMETER) {
read();
String name = readName();
if (readIf(":")) {
name = name + ":" + readName();
}
BindVariableValue var = bindVariables.get(name);
if (var == null) {
var = factory.bindVariable(name);
bindVariables.put(name, var);
}
return var;
} else if (readIf("TRUE")) {
Literal literal = getUncastLiteral(valueFactory.createValue(true));
return literal;
} else if (readIf("FALSE")) {
Literal literal = getUncastLiteral(valueFactory.createValue(false));
return literal;
} else if (readIf("CAST")) {
read("(");
StaticOperand op = parseStaticOperand();
if (!(op instanceof Literal)) {
throw getSyntaxError("literal");
}
Literal literal = (Literal) op;
Value value = literal.getLiteralValue();
read("AS");
value = parseCastAs(value);
read(")");
// CastLiteral
literal = factory.literal(value);
return literal;
} else {
throw getSyntaxError("static operand");
}
}
use of javax.jcr.query.qom.Literal in project jackrabbit-oak by apache.
the class QomTest method literal.
@Test
public void literal() throws RepositoryException {
Value v = vf.createValue(1);
Literal l = f.literal(v);
assertEquals(v, l.getLiteralValue());
assertEquals("1", l.toString());
assertEquals("'Joe''s'", f.literal(vf.createValue("Joe's")).toString());
assertEquals("' - \" - '", f.literal(vf.createValue(" - \" - ")).toString());
}
use of javax.jcr.query.qom.Literal in project jackrabbit-oak by apache.
the class QomTest method fullTextSearch.
@Test
public void fullTextSearch() throws RepositoryException {
Literal l = f.literal(vf.createValue(1));
FullTextSearch x = f.fullTextSearch("selectorName", "propertyName", l);
assertEquals("selectorName", x.getSelectorName());
assertEquals("propertyName", x.getPropertyName());
assertEquals(l, x.getFullTextSearchExpression());
assertEquals("CONTAINS([selectorName].[propertyName], 1)", x.toString());
assertEquals("CONTAINS([p], null)", f.fullTextSearch(null, "p", null).toString());
assertEquals("CONTAINS([s].[p], null)", f.fullTextSearch("s", "p", null).toString());
assertEquals("CONTAINS([s].*, null)", f.fullTextSearch("s", null, null).toString());
assertEquals("CONTAINS(*, null)", f.fullTextSearch(null, null, null).toString());
}
Aggregations