- bug fixes
-
added
NotEqual
andNotEqualIgnoreCase
specs -
resolving annotations from parent interfaces, for example, consider the following interfaces:
@Spec(path = "deleted", constVal = "false", spec = Equal.class) public interface NotDeletedSpec extends Specification<Customer> {} @Spec(path = "firstName", spec = Equal.class) public interface FirstNameSpec extends NotDeletedSpec {}
FirstNameSpec
extendsNotDeletedSpec
, so their specifications will be combined withand
, i.e. a controller method like this:@RequestMapping("/customers") @ResponseBody public Object findNotDeletedCustomersByFirstName(FirstNameSpec spec) { return repository.findAll(spec); }
will accept HTTP requests such as
GET /customers?firstName=Homer
and execute JPA queries such aswhere firstName = 'Homer' and deleted = false
.
-
join support! It is now possible to filter by attributes of joined entities. For example:
@RequestMapping("/customers") @ResponseBody public Object findByOrders( @Join(path = "orders", alias = "o") @Spec(paths = "o.itemName", params = "orderItem", spec=Like.class) Specification<Customer> spec) { return repository.findAll(spec); }
Of course you can use
@Join
on annotated custom specification interfaces:@Join(path = "orders", alias = "o") @Spec(paths = "o.itemName", params = "orderItem", spec=Like.class) public interface CustomerByOrdersSpec implements Specification<Customer> { } // ... @RequestMapping("/customers") @ResponseBody public Object findByOrders( CustomerByOrdersSpec spec) { return repository.findAll(spec); }
-
@Joins
annotation has been changed to take instances of@Join
asvalue
parameter (was@JoinFetch
).@JoinFetch
might be passed tojoin
param of@Joins
- introduced
NotNull
specification
- bumped dependencies to the latest Spring Boot version and JPA 2.1 API
- added
EqualIgnoreCase
specification - introduced
Null
specification which accepts a boolean HTTP param to dynamically addis null
oris not null
part to the query - introduced
onTypeMismatch
property of@Spec
to define whether an exception should be thrown or empty result returned when an invalid value is passed (e.g. a non numeric value while field type isInteger
). Default behaviour is to return an empty result, which is a breaking change (an exception was thrown in previous versions). UseonTypeMismatch=EXCEPTION
to match old behaviour.
- fixed stack overflow issue with annotated interfaces!
- added
GreaterThan
,GreaterThanOrEqual
,LessThan
,LessThanOrEqual
specs DateAfter
,DateBefore
and their invlusive versions are now deprecated (use the above specs)
- added
@JoinFetch
and@Joins
(see README.md for the details)
- added date inclusive specs
-
it is now allowed to annotate a custom interface that extends
Specification
, eg.:@Or({ @Spec(path="firstName", params="name", spec=Like.class), @Spec(path="lastName", params="name", spec=Like.class) }) public interface FullNameSpec extends Specification<Customer> { }
it can be then used as controller parameter without further annotations, i.e.:
@RequestMapping("/customers") @ResponseBody public Object findByFullName(FullNameSpec spec) { return repository.findAll(spec); }
-
added optional
constVal
attribute in@Spec
. It allows to define a constant part of the query that does not use any HTTP parameters, e.g.:@And({ @Spec(path="deleted", spec=Equal.class, constVal="false"), @Spec(path="firstName", spec=Like.class) })
for handling requests such as
GET /customers?firstName=Homer
and executing queries such as:select c from Customer c where c.firstName like %Homer% and c.deleted = false
-
it is possible to combine parameter and interface annotations. They are combined with 'and' operator. For example you can create a basic interface like:
@Spec(path="deleted", spec=Equal.class, constVal="false") public interface NotDeletedEntitySpec<T> extends Specification<T> {}
And use it for your queries in the controller:
@RequestMapping("/customers") @ResponseBody public Object findNotDeletedCustomerByLastName( @Spec(path="lastName", spec=Equal.class) NotDeletedEntitySpec<Customer> spec) { return repository.findAll(spec); }
-
Equal
andIn
now support boolean values correctly -
introduced
IsNull
specification -
introduced
@Conjunction
and@Disjunction
for nesting ands and ors within each other
- introduced
DateAfter
specification - introduced
Equal
that supports exact match for numbers, strings, dates and enums - introduced
In
that supports in operator for numbers, strings, dates and enums - deprecated
EqualEnum
(useEqual
andIn
)