Search in sources :

Example 1 with BindVariableValue

use of javax.jcr.query.qom.BindVariableValue in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testComparison.

/**
     * Test case for {@link QueryObjectModelFactory#comparison(DynamicOperand, String, StaticOperand)}
     */
public void testComparison() throws RepositoryException {
    PropertyValue op1 = qf.propertyValue(SELECTOR_NAME1, propertyName1);
    BindVariableValue op2 = qf.bindVariable(VARIABLE_NAME);
    for (Iterator<String> it = OPERATORS.iterator(); it.hasNext(); ) {
        String operator = it.next();
        Comparison comp = qf.comparison(op1, operator, op2);
        assertTrue("Not a PropertyValue operand", comp.getOperand1() instanceof PropertyValue);
        assertTrue("Not a BindVariableValue operand", comp.getOperand2() instanceof BindVariableValue);
        assertEquals("Wrong operator", operator, comp.getOperator());
    }
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Comparison(javax.jcr.query.qom.Comparison) PropertyValue(javax.jcr.query.qom.PropertyValue)

Example 2 with BindVariableValue

use of javax.jcr.query.qom.BindVariableValue in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testFullTextSearchWithBindVariableValue.

/**
     * Test case for {@link QueryObjectModelFactory#fullTextSearch(String, String, StaticOperand)}
     */
public void testFullTextSearchWithBindVariableValue() throws RepositoryException {
    FullTextSearch ftSearch = qf.fullTextSearch(SELECTOR_NAME1, propertyName1, qf.bindVariable(VARIABLE_NAME));
    assertEquals("Wrong selector name", SELECTOR_NAME1, ftSearch.getSelectorName());
    assertEquals("Wrong propertyName", propertyName1, ftSearch.getPropertyName());
    StaticOperand op = ftSearch.getFullTextSearchExpression();
    assertNotNull(op);
    assertTrue("not a BindVariableValue", op instanceof BindVariableValue);
    BindVariableValue value = (BindVariableValue) op;
    assertEquals(VARIABLE_NAME, value.getBindVariableName());
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) StaticOperand(javax.jcr.query.qom.StaticOperand) FullTextSearch(javax.jcr.query.qom.FullTextSearch)

Example 3 with BindVariableValue

use of javax.jcr.query.qom.BindVariableValue 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 BindVariableValue

use of javax.jcr.query.qom.BindVariableValue 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]);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Selector(javax.jcr.query.qom.Selector) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 5 with BindVariableValue

use of javax.jcr.query.qom.BindVariableValue in project jackrabbit by apache.

the class Parser method createQueryObjectModel.

/**
     * Parse a JCR-SQL2 query and return the query object model
     *
     * @param query the query string
     * @return the query object model
     * @throws RepositoryException if parsing failed
     */
public QueryObjectModel createQueryObjectModel(String query) throws RepositoryException {
    initialize(query);
    selectors = new ArrayList<Selector>();
    expected = new ArrayList<String>();
    bindVariables = new HashMap<String, BindVariableValue>();
    read();
    read("SELECT");
    int columnParseIndex = parseIndex;
    ArrayList<ColumnOrWildcard> list = parseColumns();
    read("FROM");
    Source source = parseSource();
    Column[] columnArray = resolveColumns(columnParseIndex, list);
    Constraint constraint = null;
    if (readIf("WHERE")) {
        constraint = parseConstraint();
    }
    Ordering[] orderings = null;
    if (readIf("ORDER")) {
        read("BY");
        orderings = parseOrder();
    }
    if (currentToken.length() > 0) {
        throw getSyntaxError("<end>");
    }
    return factory.createQuery(source, constraint, orderings, columnArray);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Constraint(javax.jcr.query.qom.Constraint) Source(javax.jcr.query.qom.Source) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) Selector(javax.jcr.query.qom.Selector)

Aggregations

BindVariableValue (javax.jcr.query.qom.BindVariableValue)7 PropertyValue (javax.jcr.query.qom.PropertyValue)3 Column (javax.jcr.query.qom.Column)2 Constraint (javax.jcr.query.qom.Constraint)2 Ordering (javax.jcr.query.qom.Ordering)2 Selector (javax.jcr.query.qom.Selector)2 StaticOperand (javax.jcr.query.qom.StaticOperand)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2 Test (org.junit.Test)2 Value (javax.jcr.Value)1 Comparison (javax.jcr.query.qom.Comparison)1 FullTextSearch (javax.jcr.query.qom.FullTextSearch)1 Literal (javax.jcr.query.qom.Literal)1 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)1 Source (javax.jcr.query.qom.Source)1