2018-03-21 13:11:02 +01:00
|
|
|
package eu.eudat.data.query.definition;
|
|
|
|
|
|
|
|
import eu.eudat.data.dao.criteria.Criteria;
|
|
|
|
import eu.eudat.queryable.QueryableList;
|
|
|
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
|
|
|
|
2018-03-21 14:15:06 +01:00
|
|
|
public abstract class Query<C extends Criteria<T>, T extends DataEntity> implements CriteriaQuery<C, T> {
|
2018-03-21 13:11:02 +01:00
|
|
|
private C criteria;
|
|
|
|
private QueryableList<T> query;
|
|
|
|
|
2018-03-21 14:15:06 +01:00
|
|
|
public static class QueryBuilder<C extends Criteria<T>, T extends DataEntity, Q extends Query<C, T>> {
|
|
|
|
private C criteria;
|
|
|
|
private QueryableList<T> query;
|
|
|
|
|
|
|
|
public QueryBuilder<C, T, Q> criteria(C criteria) {
|
|
|
|
this.criteria = criteria;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public QueryBuilder<C, T, Q> query(QueryableList<T> query) {
|
|
|
|
this.query = query;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Q build(Class<Q> qClass) throws IllegalAccessException, InstantiationException {
|
|
|
|
Q q = qClass.newInstance();
|
|
|
|
q.setCriteria(criteria);
|
|
|
|
q.setQuery(query);
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 13:11:02 +01:00
|
|
|
public QueryableList<T> getQuery() {
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setQuery(QueryableList<T> query) {
|
|
|
|
this.query = query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public C getCriteria() {
|
|
|
|
return criteria;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCriteria(C criteria) {
|
|
|
|
this.criteria = criteria;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-21 14:15:06 +01:00
|
|
|
public QueryableList<T> collect() throws Exception {
|
|
|
|
return this.applyCriteria();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<T> collect(QueryableList<T> repo) throws Exception {
|
|
|
|
this.query = repo;
|
2018-03-21 13:11:02 +01:00
|
|
|
return this.applyCriteria();
|
|
|
|
}
|
|
|
|
}
|