Interface QueryBuilder<Value extends Storable>

All Known Implementing Classes:
AbstractQueryBuilder, IndexedMapQuery, Query

public interface QueryBuilder<Value extends Storable>
Interface for the query builder.

All queries must start with a single attribute name, this is usually passed onto the query-builder constructor. To add constraints to the attribute use [between, like, equal, in.. etc], the attribute constraints are applied using the AND operator.

To match documents that matches at least one constraint for a single attribute, use the OR operation with the same attribute name and then apply the constraint.

To create more complex queries that spans over multiple attributes, use the AND/OR operation to combine/group constraints for attributes. Following are some examples of usage:

Matches all documents where..

attribute name starts with "veg" or contains "table' - attribute "name" startsWith "veg" or attribute "name" like "table"

attribute name starts with "veg" AND contains "table'. - attribute "name" startsWith "veg" like "table"

attribute name equals "vegetable" or "red". - attribute "name" equals "vegetable" or attribute "name" equals "red"

attribute name contains "veg" or "fruit". - attribute "name" like "veg" or attribute "name" like "fruit"

attribute vegetable.color, json example: {vegetable: {color: ""}} is red, green or blue. - attribute "vegetable.color" in [red, green, blue]

attribute vegetable.color is "red", all matches are ordered by vegetable.price - attribute "vegetable.color" equals "red' orderBy "vegetable.price" descending

attribute vegetable.vitamins is [A,B,C], match if vegetable contains vitamin C or K - attribute "vegetable.vitamins[]" in [C,K]

  • Method Details

    • and

      QueryBuilder<Value> and(String attribute)
      Adds a new AND clause to the query.
      Parameters:
      attribute - the name of the attribute to be queried.
      Returns:
      fluent
    • or

      QueryBuilder<Value> or(String attribute)
      Adds a new OR clause to the query.
      Parameters:
      attribute - the name of the attribute to be queried.
      Returns:
      fluent
    • on

      QueryBuilder<Value> on(String attribute)
      The attribute to be queried.
      Parameters:
      attribute - the name of the queried attribute.
      Returns:
      fluent
    • page

      QueryBuilder<Value> page(int page)
      set the page offset for paging support.
      Parameters:
      page - the page to return results from.
      Returns:
      fluent
    • pageSize

      QueryBuilder<Value> pageSize(int pageSize)
      set the size of each page for paging support.
      Parameters:
      pageSize - the number of hits returned on each page.
      Returns:
      fluent
    • between

      QueryBuilder<Value> between(Long minimum, Long maximum)
      Matches documents with the attribute between and including minimum and maximum.
      Parameters:
      minimum - the minimum value to match
      maximum - the maximum value to match
      Returns:
      fluent
    • like

      QueryBuilder<Value> like(String text)
      Matches documents where the attribute containst the given text
      Parameters:
      text - the text to check if contained.
      Returns:
      fluent
    • startsWith

      QueryBuilder<Value> startsWith(String text)
      Matches if the specified attribute starts with the given text
      Parameters:
      text - the text to check if starting with.
      Returns:
      fluent
    • in

      QueryBuilder<Value> in(Comparable... list)
      Matches if a specified attribute is contained within the given list
      Parameters:
      list - the list that the attribute value must be contained in to match.
      Returns:
      fluent
    • equalTo

      QueryBuilder<Value> equalTo(Comparable match)
      Matches if the attribute is an exact match to the given text.
      Parameters:
      match - the text that should be equal to the specified attribute.
      Returns:
      fluent
    • matches

      QueryBuilder<Value> matches(String regex)
      Checks if the given attribute matches the given regex. Be careful when passing user input to this method. No complexity restrictions are applied. To pass user input use equals instead. If a query can use any non-regex constraint, it is recommended to use that instead.
      Parameters:
      regex - the regular expression in which the attribute is to match
      Returns:
      fluent
    • orderBy

      QueryBuilder<Value> orderBy(String orderByAttribute)
      Orders the result by the given attribute using the default sort order unless the sort order has been explicitly set.
      Parameters:
      orderByAttribute - the handler of the attribute to sort by using dot notation.
      Returns:
      fluent
    • order

      QueryBuilder<Value> order(SortOrder order)
      Orders the result by the given direction using the last specified attribute handler unless orderBy is set.
      Parameters:
      order - descending or ascending.
      Returns:
      fluent
    • execute

      void execute(io.vertx.core.Handler<io.vertx.core.AsyncResult<Collection<Value>>> handler)
      Executes the constructed query asynchronously.
      Parameters:
      handler - the handler to be invoked when the result is completed.
    • poll

      EntryWatcher<Value> poll(Consumer<Collection<Value>> consumer, TimerSource timer)
      Executes the query periodically.
      Parameters:
      consumer - a consumer that receives the results
      timer - the source of the interval.
      Returns:
      fluent.
    • name

      String name()
      Generates unique ids for the triggers that are used. Should be overridden so that logging messages are a bit meaningful.
      Returns:
      a name that identifies this query.
    • setName

      QueryBuilder<Value> setName(String name)
      Sets a name for the query for identification.
      Parameters:
      name - the name to set
      Returns:
      fluent