Search in sources :

Example 11 with Column

use of javax.jcr.query.qom.Column 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)

Example 12 with Column

use of javax.jcr.query.qom.Column in project jackrabbit by apache.

the class Parser method createQueryObjectModel.

/**
 * Parse a JCR-SQL2 query and return the query object model
 *
 * @param query the query string
 * @return the query object model
 * @throws RepositoryException if parsing failed
 */
public QueryObjectModel createQueryObjectModel(String query) throws RepositoryException {
    initialize(query);
    selectors = new ArrayList<Selector>();
    expected = new ArrayList<String>();
    bindVariables = new HashMap<String, BindVariableValue>();
    read();
    read("SELECT");
    int columnParseIndex = parseIndex;
    ArrayList<ColumnOrWildcard> list = parseColumns();
    read("FROM");
    Source source = parseSource();
    Column[] columnArray = resolveColumns(columnParseIndex, list);
    Constraint constraint = null;
    if (readIf("WHERE")) {
        constraint = parseConstraint();
    }
    Ordering[] orderings = null;
    if (readIf("ORDER")) {
        read("BY");
        orderings = parseOrder();
    }
    if (currentToken.length() > 0) {
        throw getSyntaxError("<end>");
    }
    return factory.createQuery(source, constraint, orderings, columnArray);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Constraint(javax.jcr.query.qom.Constraint) Source(javax.jcr.query.qom.Source) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) Selector(javax.jcr.query.qom.Selector)

Example 13 with Column

use of javax.jcr.query.qom.Column in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testColumnWithSelector.

/**
 * Test case for {@link QueryObjectModelFactory#column(String, String, String)}
 */
public void testColumnWithSelector() throws RepositoryException {
    Column col = qf.column(SELECTOR_NAME1, propertyName1, COLUMN_NAME);
    assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName());
    assertEquals("Wrong property name", propertyName1, col.getPropertyName());
    assertEquals("Wrong column name", COLUMN_NAME, col.getColumnName());
}
Also used : Column(javax.jcr.query.qom.Column)

Example 14 with Column

use of javax.jcr.query.qom.Column in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testCreateQueryWithConstraintOrderingAndColumn.

public void testCreateQueryWithConstraintOrderingAndColumn() throws RepositoryException {
    Selector 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);
}
Also used : Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Selector(javax.jcr.query.qom.Selector)

Example 15 with Column

use of javax.jcr.query.qom.Column in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintOrderingAndColumn.

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);
}
Also used : Column(javax.jcr.query.qom.Column) 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)

Aggregations

Column (javax.jcr.query.qom.Column)16 Constraint (javax.jcr.query.qom.Constraint)7 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)7 Ordering (javax.jcr.query.qom.Ordering)6 Selector (javax.jcr.query.qom.Selector)6 Source (javax.jcr.query.qom.Source)5 Test (org.junit.Test)4 PropertyValue (javax.jcr.query.qom.PropertyValue)3 QueryObjectModelFactory (javax.jcr.query.qom.QueryObjectModelFactory)3 BindVariableValue (javax.jcr.query.qom.BindVariableValue)2 PropertyExistence (javax.jcr.query.qom.PropertyExistence)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 Value (javax.jcr.Value)1 ValueFactory (javax.jcr.ValueFactory)1 Workspace (javax.jcr.Workspace)1 Query (javax.jcr.query.Query)1 QueryManager (javax.jcr.query.QueryManager)1