Search in sources :

Example 1 with NodeTypeInfoProvider

use of org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider in project jackrabbit-oak by apache.

the class NodeTypeIndexTest method createFilter.

private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 2 with NodeTypeInfoProvider

use of org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider in project jackrabbit-oak by apache.

the class IndexUpdateTest method find.

private Set<String> find(PropertyIndexLookup lookup, String name, String value) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(NT_BASE);
    SelectorImpl selector = new SelectorImpl(type, NT_BASE);
    Filter filter = new FilterImpl(selector, "SELECT * FROM [nt:base]", new QueryEngineSettings());
    return Sets.newHashSet(lookup.query(filter, name, PropertyValues.newString(value)));
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) Filter(org.apache.jackrabbit.oak.spi.query.Filter) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 3 with NodeTypeInfoProvider

use of org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider in project jackrabbit-oak by apache.

the class QueryEngineImpl method parseQuery.

/**
     * Parse the query.
     * 
     * @param statement the statement
     * @param language the language
     * @param context the context
     * @param mappings the mappings
     * @return the list of queries, where the first is the original, and all
     *         others are alternatives (for example, a "union" query)
     */
private static List<Query> parseQuery(String statement, String language, ExecutionContext context, Map<String, String> mappings) throws ParseException {
    boolean isInternal = SQL2Parser.isInternal(statement);
    if (isInternal) {
        LOG.trace("Parsing {} statement: {}", language, statement);
    } else {
        LOG.debug("Parsing {} statement: {}", language, statement);
    }
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(context.getRoot(), mappings));
    NodeTypeInfoProvider nodeTypes = context.getNodeTypeInfoProvider();
    QueryEngineSettings settings = context.getSettings();
    SQL2Parser parser = new SQL2Parser(mapper, nodeTypes, settings);
    if (language.endsWith(NO_LITERALS)) {
        language = language.substring(0, language.length() - NO_LITERALS.length());
        parser.setAllowNumberLiterals(false);
        parser.setAllowTextLiterals(false);
    }
    ArrayList<Query> queries = new ArrayList<Query>();
    Query q;
    if (SQL2.equals(language) || JQOM.equals(language)) {
        q = parser.parse(statement, false);
    } else if (SQL.equals(language)) {
        parser.setSupportSQL1(true);
        q = parser.parse(statement, false);
    } else if (XPATH.equals(language)) {
        XPathToSQL2Converter converter = new XPathToSQL2Converter();
        String sql2 = converter.convert(statement);
        LOG.debug("XPath > SQL2: {}", sql2);
        try {
            // OAK-874: No artificial XPath selector name in wildcards
            parser.setIncludeSelectorNameInWildcardColumns(false);
            q = parser.parse(sql2, false);
        } catch (ParseException e) {
            ParseException e2 = new ParseException(statement + " converted to SQL-2 " + e.getMessage(), 0);
            e2.initCause(e);
            throw e2;
        }
    } else {
        throw new ParseException("Unsupported language: " + language, 0);
    }
    queries.add(q);
    if (settings.isSql2Optimisation()) {
        if (q.isInternal()) {
            LOG.trace("Skipping optimisation as internal query.");
        } else {
            LOG.trace("Attempting optimisation");
            Query q2 = q.buildAlternativeQuery();
            if (q2 != q) {
                LOG.debug("Alternative query available: {}", q2);
                queries.add(q2);
            }
        }
    }
    // initialising all the queries.
    for (Query query : queries) {
        try {
            query.init();
        } catch (Exception e) {
            ParseException e2 = new ParseException(query.getStatement() + ": " + e.getMessage(), 0);
            e2.initCause(e);
            throw e2;
        }
    }
    return queries;
}
Also used : NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) ArrayList(java.util.ArrayList) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) ParseException(java.text.ParseException) XPathToSQL2Converter(org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter) ParseException(java.text.ParseException)

Example 4 with NodeTypeInfoProvider

use of org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider in project jackrabbit-oak by apache.

the class ReferenceIndexTest method createFilter.

@SuppressWarnings("Duplicates")
private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 5 with NodeTypeInfoProvider

use of org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider in project jackrabbit-oak by apache.

the class IndexPathServiceImpl method createFilter.

private FilterImpl createFilter(String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(nodeStore.getRoot());
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", settings);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Aggregations

NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)12 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)11 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)11 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)11 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)10 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)9 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 LocalNameMapper (org.apache.jackrabbit.oak.namepath.LocalNameMapper)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.NamePathMapperImpl)1 XPathToSQL2Converter (org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter)1 Filter (org.apache.jackrabbit.oak.spi.query.Filter)1