Interface QueryBuilder<Value extends Storable>
- All Known Implementing Classes:
AbstractQueryBuilder
,IndexedMapQuery
,Query
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 Summary
Modifier and TypeMethodDescriptionAdds a new AND clause to the query.Matches documents with the attribute between and including minimum and maximum.equalTo(Comparable match)
Matches if the attribute is an exact match to the given text.void
execute(io.vertx.core.Handler<io.vertx.core.AsyncResult<Collection<Value>>> handler)
Executes the constructed query asynchronously.in(Comparable... list)
Matches if a specified attribute is contained within the given listMatches documents where the attribute containst the given textChecks if the given attribute matches the given regex.name()
Generates unique ids for the triggers that are used.The attribute to be queried.Adds a new OR clause to the query.Orders the result by the given direction using the last specified attribute handler unless orderBy is set.Orders the result by the given attribute using the default sort order unless the sort order has been explicitly set.page(int page)
set the page offset for paging support.pageSize(int pageSize)
set the size of each page for paging support.poll(Consumer<Collection<Value>> consumer, TimerSource timer)
Executes the query periodically.Sets a name for the query for identification.startsWith(String text)
Matches if the specified attribute starts with the given text
-
Method Details
-
and
Adds a new AND clause to the query.- Parameters:
attribute
- the name of the attribute to be queried.- Returns:
- fluent
-
or
Adds a new OR clause to the query.- Parameters:
attribute
- the name of the attribute to be queried.- Returns:
- fluent
-
on
The attribute to be queried.- Parameters:
attribute
- the name of the queried attribute.- Returns:
- fluent
-
page
set the page offset for paging support.- Parameters:
page
- the page to return results from.- Returns:
- fluent
-
pageSize
set the size of each page for paging support.- Parameters:
pageSize
- the number of hits returned on each page.- Returns:
- fluent
-
between
Matches documents with the attribute between and including minimum and maximum.- Parameters:
minimum
- the minimum value to matchmaximum
- the maximum value to match- Returns:
- fluent
-
like
Matches documents where the attribute containst the given text- Parameters:
text
- the text to check if contained.- Returns:
- fluent
-
startsWith
Matches if the specified attribute starts with the given text- Parameters:
text
- the text to check if starting with.- Returns:
- fluent
-
in
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
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
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
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
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
Executes the constructed query asynchronously.- Parameters:
handler
- the handler to be invoked when the result is completed.
-
poll
Executes the query periodically.- Parameters:
consumer
- a consumer that receives the resultstimer
- 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
Sets a name for the query for identification.- Parameters:
name
- the name to set- Returns:
- fluent
-