Search in sources :

Example 51 with InvalidQueryException

use of javax.jcr.query.InvalidQueryException 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);
}
Also used : RepositoryException(javax.jcr.RepositoryException) InvalidQueryException(javax.jcr.query.InvalidQueryException) Constraint(javax.jcr.query.qom.Constraint)

Aggregations

InvalidQueryException (javax.jcr.query.InvalidQueryException)51 Value (javax.jcr.Value)15 Query (javax.jcr.query.Query)14 NamespaceException (javax.jcr.NamespaceException)9 Name (org.apache.jackrabbit.spi.Name)7 RepositoryException (javax.jcr.RepositoryException)6 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)6 Constraint (javax.jcr.query.qom.Constraint)5 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)5 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)5 PropertyFunctionQueryNode (org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode)5 RelationQueryNode (org.apache.jackrabbit.spi.commons.query.RelationQueryNode)5 Path (org.apache.jackrabbit.spi.Path)4 DerefQueryNode (org.apache.jackrabbit.spi.commons.query.DerefQueryNode)4 TextsearchQueryNode (org.apache.jackrabbit.spi.commons.query.TextsearchQueryNode)4 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 QueryManager (javax.jcr.query.QueryManager)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3