Search in sources :

Example 1 with Source

use of javax.jcr.query.qom.Source in project jackrabbit-oak by apache.

the class QomTest method join.

@Test
public void join() throws RepositoryException {
    Source left = f.selector("nodeTypeName", "selectorName");
    Source right = f.selector("nodeTypeName2", "selectorName2");
    ChildNodeJoinCondition jc = f.childNodeJoinCondition("childSelectorName", "parentSelectorName");
    Join j = f.join(left, right, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, jc);
    assertEquals(left, j.getLeft());
    assertEquals(right, j.getRight());
    assertEquals(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, j.getJoinType());
    assertEquals(jc, j.getJoinCondition());
    assertEquals("ISCHILDNODE([childSelectorName], [parentSelectorName])", jc.toString());
}
Also used : ChildNodeJoinCondition(javax.jcr.query.qom.ChildNodeJoinCondition) Join(javax.jcr.query.qom.Join) Source(javax.jcr.query.qom.Source) Test(org.junit.Test)

Example 2 with Source

use of javax.jcr.query.qom.Source 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);
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) Source(javax.jcr.query.qom.Source)

Example 3 with Source

use of javax.jcr.query.qom.Source 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);
}
Also used : Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector)

Example 4 with Source

use of javax.jcr.query.qom.Source 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());
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Source(javax.jcr.query.qom.Source) Test(org.junit.Test)

Example 5 with Source

use of javax.jcr.query.qom.Source 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);
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) Source(javax.jcr.query.qom.Source)

Aggregations

Source (javax.jcr.query.qom.Source)10 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)7 Selector (javax.jcr.query.qom.Selector)6 Column (javax.jcr.query.qom.Column)5 Constraint (javax.jcr.query.qom.Constraint)4 Ordering (javax.jcr.query.qom.Ordering)3 PropertyExistence (javax.jcr.query.qom.PropertyExistence)3 PropertyValue (javax.jcr.query.qom.PropertyValue)2 QueryObjectModelFactory (javax.jcr.query.qom.QueryObjectModelFactory)2 Test (org.junit.Test)2 BindVariableValue (javax.jcr.query.qom.BindVariableValue)1 ChildNodeJoinCondition (javax.jcr.query.qom.ChildNodeJoinCondition)1 Join (javax.jcr.query.qom.Join)1 JoinCondition (javax.jcr.query.qom.JoinCondition)1 JoinType (org.apache.jackrabbit.commons.query.qom.JoinType)1