use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.
the class ConstraintSplitter method splitNot.
private void splitNot(ConstraintSplitInfo constraintSplitInfo, Not not) throws RepositoryException {
Constraint constraint = not.getConstraint();
if (constraint instanceof Not) {
split(constraintSplitInfo, ((Not) constraint).getConstraint());
} else if (constraint instanceof And) {
And and = (And) constraint;
split(constraintSplitInfo, factory.or(factory.not(and.getConstraint1()), factory.not(and.getConstraint2())));
} else if (constraint instanceof Or) {
Or or = (Or) constraint;
split(constraintSplitInfo, factory.and(factory.not(or.getConstraint1()), factory.not(or.getConstraint2())));
} else {
splitBySelectors(constraintSplitInfo, not, getSelectorNames(constraint));
}
}
use of javax.jcr.query.qom.Constraint in project jackrabbit-oak by apache.
the class QomTest method jcrNameConversion.
@Test
public void jcrNameConversion() throws RepositoryException {
assertEquals("[nt:base]", f.column(null, NodeType.NT_BASE, null).toString());
assertEquals("[s1].[nt:base] = [s2].[nt:base]", f.equiJoinCondition("s1", NodeType.NT_BASE, "s2", NodeType.NT_BASE).toString());
assertEquals("CONTAINS([nt:base], null)", f.fullTextSearch(null, NodeType.NT_BASE, null).toString());
assertEquals("CAST('nt:base' AS NAME)", f.literal(vf.createValue(NodeType.NT_BASE, PropertyType.NAME)).toString());
assertEquals("[nt:base] IS NOT NULL", f.propertyExistence(null, NodeType.NT_BASE).toString());
assertEquals("[nt:base]", f.propertyValue(null, NodeType.NT_BASE).toString());
assertEquals("[nt:base]", f.selector(NodeType.NT_BASE, null).toString());
Source source1 = f.selector(NodeType.NT_BASE, "selector");
Column[] columns = new Column[] { f.column("selector", null, null) };
Constraint constraint2 = f.childNode("selector", "/");
QueryObjectModel qom = f.createQuery(source1, constraint2, null, columns);
assertEquals("select [selector].* from " + "[nt:base] AS [selector] " + "where ISCHILDNODE([selector], [/])", qom.toString());
}
use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.
the class SQL2PathEscapingTest method testGetChildrenApiStatement.
/**
* the statement behind the api should be consistent, and return a similar
* query. in our case it should escape the paths that have spaces in them by
* enclosing them in single quotes
*
* @throws Exception
*/
public void testGetChildrenApiStatement() 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(executeSQL2Query(qom.getStatement()), 2);
}
use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.
the class Parser method parseCondition.
private Constraint parseCondition(DynamicOperand left) throws RepositoryException {
Constraint c;
if (readIf("=")) {
c = Operator.EQ.comparison(factory, left, parseStaticOperand());
} else if (readIf("<>")) {
c = Operator.NE.comparison(factory, left, parseStaticOperand());
} else if (readIf("<")) {
c = Operator.LT.comparison(factory, left, parseStaticOperand());
} else if (readIf(">")) {
c = Operator.GT.comparison(factory, left, parseStaticOperand());
} else if (readIf("<=")) {
c = Operator.LE.comparison(factory, left, parseStaticOperand());
} else if (readIf(">=")) {
c = Operator.GE.comparison(factory, left, parseStaticOperand());
} else if (readIf("LIKE")) {
c = Operator.LIKE.comparison(factory, left, parseStaticOperand());
} else if (readIf("IS")) {
boolean not = readIf("NOT");
read("NULL");
if (!(left instanceof PropertyValue)) {
throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
}
PropertyValue p = (PropertyValue) left;
c = getPropertyExistence(p);
if (!not) {
c = factory.not(c);
}
} else if (readIf("NOT")) {
if (readIf("IS")) {
read("NULL");
if (!(left instanceof PropertyValue)) {
throw new RepositoryException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName());
}
PropertyValue pv = (PropertyValue) left;
c = getPropertyExistence(pv);
} else {
read("LIKE");
c = factory.not(Operator.LIKE.comparison(factory, left, parseStaticOperand()));
}
} else {
throw getSyntaxError();
}
return c;
}
use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.
the class QueryObjectModelFactoryImpl method createQuery.
/**
* Creates a query with one or more selectors.
* <p>
* If <code>source</code> is a selector, that selector is the <i>default
* selector</i> of the query. Otherwise the query does not have a default
* selector.
*
* @param source the node-tuple source; non-null
* @param constraint the constraint, or null if none
* @param orderings zero or more orderings; null is equivalent to a
* zero-length array
* @param columns the columns; null is equivalent to a zero-length array
* @return the query; non-null
* @throws javax.jcr.query.InvalidQueryException
* if the query is invalid
* @throws javax.jcr.RepositoryException if the operation otherwise fails
*/
public QueryObjectModel createQuery(Source source, Constraint constraint, Ordering[] orderings, Column[] columns) throws InvalidQueryException, RepositoryException {
if (source == null) {
throw new InvalidQueryException("source must not be null");
}
if (!(source instanceof SourceImpl)) {
throw new RepositoryException("Unknown Source implementation");
}
if (constraint != null && !(constraint instanceof ConstraintImpl)) {
throw new RepositoryException("Unknown Constraint implementation");
}
OrderingImpl[] ords;
if (orderings != null) {
ords = new OrderingImpl[orderings.length];
for (int i = 0; i < orderings.length; i++) {
if (!(orderings[i] instanceof OrderingImpl)) {
throw new RepositoryException("Unknown Ordering implementation");
}
ords[i] = (OrderingImpl) orderings[i];
}
} else {
ords = OrderingImpl.EMPTY_ARRAY;
}
ColumnImpl[] cols;
if (columns != null) {
cols = new ColumnImpl[columns.length];
for (int i = 0; i < columns.length; i++) {
if (!(columns[i] instanceof ColumnImpl)) {
throw new RepositoryException("Unknown Column implementation");
}
cols[i] = (ColumnImpl) columns[i];
}
} else {
cols = ColumnImpl.EMPTY_ARRAY;
}
QueryObjectModelTree qomTree = new QueryObjectModelTree(resolver, (SourceImpl) source, (ConstraintImpl) constraint, ords, cols);
return createQuery(qomTree);
}
Aggregations