public static Constraint and( QueryObjectModelFactory factory, List<Constraint> constraints) throws RepositoryException { int n = constraints.size(); if (n == 0) { return null; } else if (n == 1) { return constraints.get(0); } else { int m = n / 2; return factory.and( and(factory, constraints.subList(0, m)), and(factory, constraints.subList(m, n))); } }
public static Constraint and( QueryObjectModelFactory factory, List<Constraint> constraints) throws RepositoryException { int n = constraints.size(); if (n == 0) { return null; } else if (n == 1) { return constraints.get(0); } else { int m = n / 2; return factory.and( and(factory, constraints.subList(0, m)), and(factory, constraints.subList(m, n))); } }
private Constraint parseAnd() throws RepositoryException { Constraint a = parseCondition(); while (readIf("AND")) { a = factory.and(a, parseCondition()); } return a; }
private Constraint parseAnd() throws RepositoryException { Constraint a = parseCondition(); while (readIf("AND")) { a = factory.and(a, parseCondition()); } return a; }
private Constraint parseAnd() throws RepositoryException { Constraint a = parseCondition(); while (readIf("AND")) { a = factory.and(a, parseCondition()); } return a; }
public void testNot() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); n1.setProperty(propertyName1, "foo"); Node n2 = testRootNode.addNode(nodeName2, testNodeType); n2.setProperty(propertyName2, "bar"); superuser.save(); QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.descendantNode("s", testRootNode.getPath()), qf.not( qf.propertyExistence("s", propertyName1) ) ), null, null ); checkQOM(qom, new Node[]{n2}); } }
public void testOr() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); n1.setProperty(propertyName1, "foo"); Node n2 = testRootNode.addNode(nodeName2, testNodeType); n2.setProperty(propertyName2, "bar"); superuser.save(); QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.descendantNode("s", testRootNode.getPath()), qf.or( qf.propertyExistence("s", propertyName1), qf.propertyExistence("s", propertyName2) ) ), null, null ); checkQOM(qom, new Node[]{n1, n2}); } }
public void testPropertyExistence() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); n1.setProperty(propertyName1, "abc"); Node n2 = testRootNode.addNode(nodeName2, testNodeType); n2.setProperty(propertyName2, "abc"); superuser.save(); QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.propertyExistence("s", propertyName1) ), null, null); checkQOM(qom, new Node[]{n1}); qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.propertyExistence("s", propertyName2) ), null, null); checkQOM(qom, new Node[]{n2}); } }
protected QueryObjectModel createQuery(String joinType, JoinCondition condition, Constraint left, Constraint right) throws RepositoryException { // only consider nodes under test root Constraint constraint; if (QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER.equals(joinType)) { constraint = qf.descendantNode(LEFT, testRoot); } else { constraint = qf.descendantNode(RIGHT, testRoot); } if (left != null) { constraint = qf.and(constraint, left); } if (right != null) { constraint = qf.and(constraint, right); } Join join = qf.join( qf.selector(testNodeType, LEFT), qf.selector(testNodeType, RIGHT), joinType, condition); return qf.createQuery(join, constraint, null, null); } }
/** * Test case for {@link QueryObjectModelFactory#and(Constraint, Constraint)} */ public void testAnd() throws RepositoryException { PropertyExistence c1 = qf.propertyExistence(SELECTOR_NAME1, propertyName1); PropertyExistence c2 = qf.propertyExistence(SELECTOR_NAME1, propertyName2); And and = qf.and(c1, c2); assertTrue("Not a PropertyExistence constraint", and.getConstraint1() instanceof PropertyExistence); assertTrue("Not a PropertyExistence constraint", and.getConstraint2() instanceof PropertyExistence); }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeLocalName("s"), operator, qf.literal(literal) ) ), null, null); } }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeName("s"), operator, qf.literal(literal) ) ), null, null); } }
private QueryObjectModel createQuery(DynamicOperand operand, boolean toUpper, String operator, Value literal) throws RepositoryException { if (toUpper) { operand = qf.upperCase(operand); } else { operand = qf.lowerCase(operand); } return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( operand, operator, qf.literal(literal) ) ), null, null); } }
public void testOrdering() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.descendantNode("s", testRootNode.getPath()) ), new Ordering[]{qf.ascending(qf.fullTextSearchScore("s"))}, null ); forQOMandSQL2(qom, new Callable() { public Object call(Query query) throws RepositoryException { RowIterator rows = query.execute().getRows(); double previousScore = Double.NaN; while (rows.hasNext()) { double score = rows.nextRow().getScore("s"); if (!Double.isNaN(previousScore)) { assertTrue("wrong order", previousScore <= score); } previousScore = score; } return null; } }); }
protected void setUp() throws Exception { super.setUp(); qomQuery = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.propertyValue("s", propertyName1), QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, qf.bindVariable("v") ) ), null, null); sqlQuery = qm.createQuery(qomQuery.getStatement(), Query.JCR_SQL2); }
@Test public void and() throws RepositoryException { Constraint c0 = f.propertyExistence("x", "c0"); Constraint c1 = f.propertyExistence("x", "c1"); And and = f.and(c0, c1); assertEquals(and.getConstraint1(), c0); assertEquals(and.getConstraint2(), c1); assertEquals("([x].[c0] IS NOT NULL) AND ([x].[c1] IS NOT NULL)", and.toString()); }
private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.length( qf.propertyValue( "s", propertyName)), operator, qf.literal(length)) ), null, null); QueryResult[] results = new QueryResult[2]; results[0] = qom.execute(); results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(); return results; } }
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)); } }
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)); } }
@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]); }