use of javax.jcr.query.qom.Column in project jackrabbit-oak by apache.
the class QueryObjectModelImpl method getStatement.
@Override
public String getStatement() {
StringBuilder buff = new StringBuilder();
buff.append("select ");
int i;
if (columns != null && columns.length > 0) {
i = 0;
for (Column c : columns) {
if (i++ > 0) {
buff.append(", ");
}
buff.append(c);
}
} else {
buff.append("*");
}
buff.append(" from ");
buff.append(source);
if (constraint != null) {
buff.append(" where ");
buff.append(constraint);
}
if (orderings != null && orderings.length > 0) {
buff.append(" order by ");
i = 0;
for (Ordering o : orderings) {
if (i++ > 0) {
buff.append(", ");
}
buff.append(o);
}
}
return buff.toString();
}
use of javax.jcr.query.qom.Column in project jackrabbit-oak by apache.
the class QomTest method column.
@Test
public void column() throws RepositoryException {
Column c = f.column("selectorName", "propertyName", "columnName");
assertEquals("selectorName", c.getSelectorName());
assertEquals("propertyName", c.getPropertyName());
assertEquals("columnName", c.getColumnName());
assertEquals("[selectorName].[propertyName] AS [columnName]", c.toString());
assertEquals("[p]", f.column(null, "p", null).toString());
assertEquals("[p] AS [c]", f.column(null, "p", "c").toString());
assertEquals("[s].[p]", f.column("s", "p", null).toString());
assertEquals("[s].[p] AS [c]", f.column("s", "p", "c").toString());
assertEquals("[s].* AS [c]", f.column("s", null, "c").toString());
assertEquals("* AS [c]", f.column(null, null, "c").toString());
assertEquals("*", f.column(null, null, null).toString());
assertEquals("[s].*", f.column("s", null, null).toString());
}
use of javax.jcr.query.qom.Column 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.Column 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.Column in project jackrabbit by apache.
the class SQL2PathEscapingTest method testGetChildrenApiDirect.
/**
* will build a query directly via the api using a spaced path
*
* @throws Exception
*/
public void testGetChildrenApiDirect() throws Exception {
QueryObjectModelFactory qomf = qm.getQOMFactory();
Source source1 = qomf.selector(NodeType.NT_BASE, "selector");
Column[] columns = new Column[] { qomf.column("selector", null, null) };
Constraint constraint2 = qomf.childNode("selector", n1.getPath());
QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns);
checkResult(qom.execute(), 2);
}
Aggregations