Hql Builder 
Intro
This is a simple tool to create dynamic HQL queries in more fancy way, using groovy DSL. It looks like this:
def q = HqlQuery.build(Book) {
where {
or {
eq("id", 2)
'in'("status", [BookStatuses.PUBLISHED, BookStatuses.NEW])
}
}
}
q.queryString
produces:
from Book
where id = :p1 OR status in (:p2)
and q.paramValues
will give you a Map of params:
[p1: 2, p2: [PUBLISHED, NEW]]
Installation
repositories {
mavenCentral()
}
dependencies {
implementation 'com.relaximus:hql-builder:1.0'
}
Usage
Build can accept the string instead of the model class, this string will be the beginning of the constructed HQL query.
Main section also accepts: count()
, delete()
and limit()
methods which change the whole
behaviour of the query.
Predicates
All predicates are connected with the implicit AND
operation, OR
should be used explicitly instead.
eq
/neq
- Simple equality/not equality.in
- Value in the listlike
/iLike
- Text search (with case insensitive option)gt
/gte
/lt
/lte
- > / ≥ / < / ≤isNull