Class QueryParser<O>

  • Direct Known Subclasses:
    CQNParser, SQLParser

    public abstract class QueryParser<O>
    extends Object
    A service provider interface for parsers which can convert string queries to CQEngine native queries.

    Subclasses can implement this to support string-based queries in various dialects, such as SQL or a string representation of a CQEngine native query.

    Author:
    Niall Gallagher
    • Field Detail

      • objectType

        protected final Class<O> objectType
      • SYNTAX_ERROR_LISTENER

        protected static final org.antlr.v4.runtime.BaseErrorListener SYNTAX_ERROR_LISTENER
    • Constructor Detail

      • QueryParser

        public QueryParser​(Class<O> objectType)
    • Method Detail

      • registerAttribute

        public <A> void registerAttribute​(Attribute<O,​A> attribute)
      • registerAttributes

        public void registerAttributes​(Map<String,​? extends Attribute<O,​?>> attributes)
      • registerAttributes

        public void registerAttributes​(Iterable<? extends Attribute<O,​?>> attributes)
      • registerValueParser

        public <A> void registerValueParser​(Class<A> valueType,
                                            ValueParser<A> valueParser)
      • registerFallbackValueParser

        public void registerFallbackValueParser​(ValueParser<Object> fallbackValueParser)
      • getObjectType

        public Class<O> getObjectType()
      • getAttribute

        public <A> Attribute<O,​A> getAttribute​(org.antlr.v4.runtime.tree.ParseTree attributeNameContext,
                                                     Class<A> expectedSuperType)
      • parseValue

        public <A> A parseValue​(Attribute<O,​A> attribute,
                                org.antlr.v4.runtime.tree.ParseTree parameterContext)
      • parseValue

        public <A> A parseValue​(Class<A> valueType,
                                org.antlr.v4.runtime.tree.ParseTree parameterContext)
      • parseValue

        public <A> A parseValue​(Class<A> valueType,
                                String text)
      • parse

        public abstract ParseResult<O> parse​(String query)
        Parses the given query and its query options, encapsulating both in the object returned.
        Parameters:
        query - The query to parse
        Returns:
        An object encapsulating the parsed query and its query options
      • retrieve

        public ResultSet<O> retrieve​(IndexedCollection<O> collection,
                                     String query)
        Shortcut for parsing the given query and its query options, and then retrieving objects matching the query from the given collection, using the parsed query options.
        Parameters:
        query - The query to parse
        Returns:
        The results of querying the collection with the parsed query and its query options
      • query

        public Query<O> query​(String query)
        Shortcut for calling parse(query).getQuery().
        Parameters:
        query - The query to parse
        Returns:
        The parsed query on its own, without any query options
      • queryOptions

        public QueryOptions queryOptions​(String query)
        Shortcut for calling parse(query).getQueryOptions().
        Parameters:
        query - The query to parse
        Returns:
        The query options, without the actual query