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); } }
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; } }
QueryObjectModel qom = qf.createQuery( qf.join( qf.selector(testNodeType, SELECTOR_1), qf.selector(testNodeType, SELECTOR_2), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.equiJoinCondition(SELECTOR_1, propertyName1, SELECTOR_2, propertyName1) ), qf.descendantNode(SELECTOR_1, testRoot), null, new Column[]{ qf.column(SELECTOR_1, propertyName1, columnName1), qf.column(SELECTOR_2, propertyName1, columnName2)
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); } }
public void testLeftOuterJoin() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.join( qf.selector(testNodeType, LEFT), qf.selector(mixReferenceable, RIGHT), QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, qf.sameNodeJoinCondition(LEFT, RIGHT, ".")), qf.descendantNode(LEFT, testRoot), null, null); checkQOM(qom, new Node[][]{{n1, null}, {n2, n2}}); }
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); }
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 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]); }
@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()); }
public void testPathDoesNotExist() throws RepositoryException { QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); }
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}); } }
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); } }
public void testPathDoesNotExist() throws RepositoryException { QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); }
/** * 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); }
private Row getRow() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[]{qf.column(SELECTOR_NAME, propertyName1, propertyName1)}); RowIterator rows = qom.execute().getRows(); assertTrue("empty result", rows.hasNext()); Row r = rows.nextRow(); assertFalse("result must not contain more than one row", rows.hasNext()); return r; } }
public void testDuplicateNodeType() throws RepositoryException { try { Query q = qf.createQuery( qf.join( qf.selector(testNodeType, "nt"), qf.selector(testNodeType, "nt"), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.descendantNodeJoinCondition("nt", "nt")), null, null, null); q.execute(); fail("Selector with two identical selector names must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS nt, [" + testNodeType + "] AS nt nt INNER JOIN nt ON ISDESCENDANTNODE(nt, nt)"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("selectorName with syntactically invalid name must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } } }
public void testPathDoesNotExist() throws RepositoryException { QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.sameNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); }
/** * From the spec: * <p> * If propertyName is specified, columnName is required and used to name * the column in the tabular results. */ public void testColumnNames() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, SELECTOR_1), null, null, new Column[]{qf.column(SELECTOR_1, propertyName1, propertyName1)}); forQOMandSQL2(qom, new Callable() { public Object call(Query query) throws RepositoryException { QueryResult result = query.execute(); List<String> names = new ArrayList<String>(Arrays.asList(result.getColumnNames())); assertTrue("Missing column: " + propertyName1, names.remove(propertyName1)); for (Iterator<String> it = names.iterator(); it.hasNext(); ) { fail(it.next() + " was not declared as a column"); } return null; } }); }
@Test public void escapedName() throws RepositoryException { assertEquals("[[n]]]", f.selector("[n]", null).toString()); assertEquals("[[s]]].[[p]]]", f.propertyValue("[s]", "[p]").toString()); assertEquals("ISSAMENODE([[s1]]], [[s2]]], [[p]]])", f.sameNodeJoinCondition("[s1]", "[s2]", "[p]").toString()); assertEquals("ISSAMENODE([[s]]], [[p]]])", f.sameNode("[s]", "[p]").toString()); } }