Replaces #825
Users will sometimes need to define queries dynamically instead of statically in response to what they see happen at run time. For example, a user specifies various customizable search options and in response, the application dynamically adds restrictions to a query to filter for the matching results.
An application ought to be able to define the same kind of query restrictions dynamically that it can already define statically (with patterns like Query by Method Name).
Query restrictions should make use of the Jakarta Data Static Metamodel and generally be agnostic to the database as much as possible, other than the same sort of limitations that Query By Method Name and the other static patterns have on which operations certain classes of NoSQL databases are incapable of.
The Jakarta Data Static Metamodel will be expanded to represent conditions that are possible per attribute type. These conditions can be supplied as an extra repository method parameter, similar to what is currently possible with Order.by/Sorts.
Example with one static and one dynamic restriction:
Page<Product> page1 = products.search(namePattern,
_Product.price.lessThan(100.0),
Order.by(_Product.price.desc(),
_Product.id.asc()));
For multiple dynamic restrictions,
One possible way suggested by Otavio in 825
List<Product> list = products.search(
namePattern,
_Product.price.greaterThan(min)
.and(_Product.price.lessThan(max))
.and(_Product.color.equal(BLUE)
.or(_Product.color.equal(GREEN))),
Order.by(_Product.name.asc(),
_Product.id.asc()));
Another possible way (slightly more wordy, possibly more readable)
List<Product> list = products.search(
namePattern,
Require.all(_Product.price.greaterThan(min),
_Product.price.lessThan(max),
Require.any(_Product.color.equal(BLUE),
_Product.color.equal(GREEN))),
Order.by(_Product.name.asc(),
_Product.id.asc()));
Or we could think of another way to cover and/or/not. That part can be figured out later. The basic idea here will be to add the restrictions to the static metamodel and decide how type safe to make them. For example, requiring Number for numeric attributes, or possibly more precise, or just Object for everything, ...
Replaces #825
Users will sometimes need to define queries dynamically instead of statically in response to what they see happen at run time. For example, a user specifies various customizable search options and in response, the application dynamically adds restrictions to a query to filter for the matching results.
An application ought to be able to define the same kind of query restrictions dynamically that it can already define statically (with patterns like Query by Method Name).
Query restrictions should make use of the Jakarta Data Static Metamodel and generally be agnostic to the database as much as possible, other than the same sort of limitations that Query By Method Name and the other static patterns have on which operations certain classes of NoSQL databases are incapable of.
The Jakarta Data Static Metamodel will be expanded to represent conditions that are possible per attribute type. These conditions can be supplied as an extra repository method parameter, similar to what is currently possible with Order.by/Sorts.
Example with one static and one dynamic restriction:
For multiple dynamic restrictions,
One possible way suggested by Otavio in 825
Another possible way (slightly more wordy, possibly more readable)
Or we could think of another way to cover and/or/not. That part can be figured out later. The basic idea here will be to add the restrictions to the static metamodel and decide how type safe to make them. For example, requiring
Numberfor numeric attributes, or possibly more precise, or just Object for everything, ...