Interface QueryMapper.MapperQueryBuild
- All Known Subinterfaces:
-
QueryMapper.MapperFrom, QueryMapper.MapperLimit, QueryMapper.MapperNameOrder, QueryMapper.MapperSkip, QueryMapper.MapperWhere
- Enclosing interface:
-
QueryMapper
This interface defines terminal operations used to execute a query after all filtering, ordering, and pagination steps have been specified. It allows retrieving query results in different forms, such as a count, a list, a stream, or a single optional result.
@Inject
Template template;
List<Book> books = template.select(Book.class)
.where("author").eq("Ada")
.orderBy("title").asc()
.limit(10)
.result();
The returned instances are mutable and not thread-safe. Support
for execution operations depends on the capabilities of the
underlying NoSQL database.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionlongcount()Executes the query and returns the number of entities that match the current filter conditions.<T> List<T> result()Executes the query and returns the result as aList.<T> Optional<T> Executes the query and returns the result as a single element, wrapped in anOptional.<T> Stream<T> stream()Executes the query and returns the result as aStream.
-
Method Details
-
count
long count()Executes the query and returns the number of entities that match the current filter conditions.This is a terminal operation. Unlike
result()which returns the list of matching entities,count()returns the total number of matching records.long count = template.select(Person.class) .where("active").eq(true) .count();- Returns:
- the number of records that match the filter criteria
-
result
Executes the query and returns the result as aList.List<Book> books = template.select(Book.class) .where("author").eq("Ada") .result();- Type Parameters:
-
T- the entity type - Returns:
- the result of the query
- Throws:
-
UnsupportedOperationException- If a NoSQL database does not support a specific operation or if the database does not support certain query conditions, an exception will be raised. For example, a wide-column may not support the OR operator, or a document database may not support the BETWEEN operator. The level of NoSQL database support for various conditions may vary depending on the database provider.
-
stream
Executes the query and returns the result as aStream.Stream<Book> books = template.select(Book.class) .where("author") .eq("Ada") .stream(); books.forEach(System.out::println);- Type Parameters:
-
T- the entity type - Returns:
- the result of the query
- Throws:
-
UnsupportedOperationException- If a NoSQL database does not support a specific operation or if the database does not support certain query conditions, an exception will be raised. For example, a wide-column may not support the OR operator, or a document database may not support the BETWEEN operator. The level of NoSQL database support for various conditions may vary depending on the database provider.
-
singleResult
Executes the query and returns the result as a single element, wrapped in anOptional. If the query returns exactly one result, that result is returned in the Optional. If no result is found,Optional.empty()is returned. If more than one result is found, an exception specific to the Jakarta NoSQL provider may be thrown.Optional<Book> book = template.select(Book.class) .where("isbn").eq("978-1234567890") .singleResult();Use this method when expecting a single result from a query. It provides a safe way to handle the case where zero or one result is expected, while also allowing for exceptional cases where multiple results are returned.
- Type Parameters:
-
T- the type of the entity being queried - Returns:
- an Optional containing the single result of the query, if present, or empty if no result is found
- Throws:
-
UnsupportedOperationException- If a NoSQL database does not support a specific operation or if the database does not support certain query conditions, an exception will be raised. For example, a wide-column may not support the OR operator, or a document database may not support the BETWEEN operator. The level of NoSQL database support for various conditions may vary depending on the database provider.
-