use of javax.jcr.query.qom.Selector in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryWithConstraint.
public void testCreateQueryWithConstraint() throws RepositoryException {
Selector 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.Selector in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintAndOrdering.
public void testCreateQueryFromSourceWithConstraintAndOrdering() 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);
QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, 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", 1, qom.getOrderings().length);
assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
use of javax.jcr.query.qom.Selector in project jackrabbit by apache.
the class Parser method resolveColumns.
private Column[] resolveColumns(int columnParseIndex, ArrayList<ColumnOrWildcard> list) throws RepositoryException {
int oldParseIndex = parseIndex;
// set the parse index to the column list, to get a more meaningful error message
// if something is wrong
this.parseIndex = columnParseIndex;
try {
ArrayList<Column> columns = new ArrayList<Column>();
for (ColumnOrWildcard c : list) {
if (c.propertyName == null) {
for (Selector selector : selectors) {
if (c.selectorName == null || c.selectorName.equals(selector.getSelectorName())) {
Column column = factory.column(selector.getSelectorName(), null, null);
columns.add(column);
}
}
} else {
Column column;
if (c.selectorName != null) {
column = factory.column(c.selectorName, c.propertyName, c.columnName);
} else if (c.columnName != null) {
column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.columnName);
} else {
column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.propertyName);
}
columns.add(column);
}
}
Column[] array = new Column[columns.size()];
columns.toArray(array);
return array;
} finally {
this.parseIndex = oldParseIndex;
}
}
use of javax.jcr.query.qom.Selector 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.Selector 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