Search in sources :

Example 1 with Literal

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());
}
Also used : Literal(javax.jcr.query.qom.Literal) BindVariableValue(javax.jcr.query.qom.BindVariableValue) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue)

Example 2 with Literal

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;
}
Also used : HashMap(java.util.HashMap) Constraint(javax.jcr.query.qom.Constraint) Literal(javax.jcr.query.qom.Literal) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row)

Example 3 with Literal

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");
    }
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) StaticOperand(javax.jcr.query.qom.StaticOperand) Literal(javax.jcr.query.qom.Literal) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) BindVariableValue(javax.jcr.query.qom.BindVariableValue)

Example 4 with Literal

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());
}
Also used : Literal(javax.jcr.query.qom.Literal) BindVariableValue(javax.jcr.query.qom.BindVariableValue) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 5 with Literal

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());
}
Also used : Literal(javax.jcr.query.qom.Literal) FullTextSearch(javax.jcr.query.qom.FullTextSearch) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

Literal (javax.jcr.query.qom.Literal)7 PropertyValue (javax.jcr.query.qom.PropertyValue)5 Value (javax.jcr.Value)4 BindVariableValue (javax.jcr.query.qom.BindVariableValue)3 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)3 Test (org.junit.Test)3 FullTextSearch (javax.jcr.query.qom.FullTextSearch)2 StaticOperand (javax.jcr.query.qom.StaticOperand)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Row (javax.jcr.query.Row)1 Comparison (javax.jcr.query.qom.Comparison)1 Constraint (javax.jcr.query.qom.Constraint)1