Hi Guys.
I need to create a dynamic query for search...
Kind of:
Code:
if (field != null){
query.append("AND field = "+field);
}
Of course, that is a lazy example...
But I want to make it DYNAMIC AND GENERIC.
For that I´m thinking in creating a helper, like:
Code:
public class WhatEver{
private String fieldName;
private Object fieldObject;
private Class<?> filterclass;
private String operation; //refector for a ENUM latter on, like "equals", ">", "<", "between"
private String matchMode; //if necessary
private boolean isList; //if I want to filter in a list, I have to create a JOIN here... but don´t know if I can do this
}
And create the query using criteria...
In a method, where I receive a list of "WhatEver", Sorting Field, Sorting ASC/DESC...
And the Root entityClass ...
If I can make this... I don´t need to create one query PER entity, that I´ll have in my CRUD with dynamic filters.
Anybody have this implemmented or can help me with it?