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());
}
}
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());
}
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");
}
}
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]);
}
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);
}
Aggregations