Search in sources :

Example 1 with BindVariableValueImpl

use of org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl in project jackrabbit by apache.

the class QueryObjectModelImpl method init.

/**
 * Initializes a query instance from a query object model.
 *
 * @param sessionContext component context of the current session
 * @param handler  the query handler of the search index.
 * @param qomTree  the query object model tree.
 * @param language the original query syntax from where the JQOM was
 *                 created.
 * @param node     a nt:query node where the query was read from or
 *                 <code>null</code> if it is not a stored query.
 * @throws InvalidQueryException if the qom tree cannot be serialized
 *                               according to the given language.
 * @throws RepositoryException   if another error occurs
 */
public void init(SessionContext sessionContext, QueryHandler handler, QueryObjectModelTree qomTree, String language, Node node) throws InvalidQueryException, RepositoryException {
    checkNotInitialized();
    this.sessionContext = sessionContext;
    this.language = language;
    this.handler = handler;
    this.qomTree = qomTree;
    this.node = node;
    this.statement = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language).toString(this);
    try {
        qomTree.accept(new DefaultTraversingQOMTreeVisitor() {

            @Override
            public Object visit(BindVariableValueImpl node, Object data) {
                variables.put(node.getBindVariableName(), null);
                return data;
            }
        }, null);
    } catch (Exception ignore) {
    }
    this.lqf = new LuceneQueryFactory(sessionContext.getSessionImpl(), (SearchIndex) handler, variables);
    setInitialized();
}
Also used : DefaultTraversingQOMTreeVisitor(org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor) BindVariableValueImpl(org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl) SearchIndex(org.apache.jackrabbit.core.query.lucene.SearchIndex) LuceneQueryFactory(org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory) RepositoryException(javax.jcr.RepositoryException) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 LuceneQueryFactory (org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory)1 SearchIndex (org.apache.jackrabbit.core.query.lucene.SearchIndex)1 BindVariableValueImpl (org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl)1 DefaultTraversingQOMTreeVisitor (org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor)1