use of javax.jcr.query.qom.Source in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSource.
public void testCreateQueryFromSource() throws RepositoryException {
Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
QueryObjectModel qom = qf.createQuery(selector, null, null, null);
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
assertNull("Constraint must be null", qom.getConstraint());
assertEquals("Wrong size of orderings", 0, qom.getOrderings().length);
assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
use of javax.jcr.query.qom.Source in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraint.
public void testCreateQueryFromSourceWithConstraint() throws RepositoryException {
Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
QueryObjectModel qom = qf.createQuery(selector, propExist, null, null);
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
assertEquals("Wrong size of orderings", 0, qom.getOrderings().length);
assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
use of javax.jcr.query.qom.Source in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintOrderingAndColumn.
public void testCreateQueryFromSourceWithConstraintOrderingAndColumn() throws RepositoryException {
Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering ordering = qf.ascending(propValue);
Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, new Column[] { column });
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
assertEquals("Wrong size of orderings", 1, qom.getOrderings().length);
assertEquals("Wrong size of columns", 1, qom.getColumns().length);
}
use of javax.jcr.query.qom.Source 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);
}
use of javax.jcr.query.qom.Source in project jackrabbit by apache.
the class Parser method parseSource.
private Source parseSource() throws RepositoryException {
Selector selector = parseSelector();
selectors.add(selector);
Source source = selector;
while (true) {
JoinType type;
if (readIf("RIGHT")) {
read("OUTER");
type = JoinType.RIGHT;
} else if (readIf("LEFT")) {
read("OUTER");
type = JoinType.LEFT;
} else if (readIf("INNER")) {
type = JoinType.INNER;
} else {
break;
}
read("JOIN");
selector = parseSelector();
selectors.add(selector);
read("ON");
JoinCondition on = parseJoinCondition();
source = type.join(factory, source, selector, on);
}
return source;
}
Aggregations