use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.
the class AbstractVoEnabledDao method formRestrictionClause.
/**
* Creates a CNF restriction clause from the given Filters list.
*
* @param filters A list of filtering properties arrays.
* Elements in each array will be in a disjunction (OR) with each other.
* Arrays will then be in a conjunction (AND) with each other.
* I.e. The filter will be in a conjunctive normal form.
* <code>[0 OR 1 OR 2] AND [0 OR 1] AND [0 OR 1 OR 3]</code>
* @param addAcl whether the acl restriction clause should also be added.
* @return a string containing the clause, without the leading "WHERE" keyword.
*/
protected static String formRestrictionClause(ArrayList<ObjectFilter[]> filters, boolean addAcl) {
String queryString = addAcl ? AbstractVoEnabledDao.formAclRestrictionClause() : " ";
if (filters == null || filters.isEmpty())
return queryString;
StringBuilder conjunction = new StringBuilder();
for (ObjectFilter[] filterArray : filters) {
if (filterArray.length == 0)
continue;
StringBuilder disjunction = new StringBuilder();
boolean first = true;
for (ObjectFilter filter : filterArray) {
if (filter == null)
continue;
if (!first)
disjunction.append("or ");
if (filter.getObjectAlias() != null) {
disjunction.append(filter.getObjectAlias()).append(".");
disjunction.append(filter.getPropertyName()).append(" ").append(filter.getOperator());
if (filter.getOperator().equals(ObjectFilter.in)) {
disjunction.append("( :").append(AbstractVoEnabledDao.formParamName(filter)).append(" ) ");
} else {
disjunction.append(":").append(AbstractVoEnabledDao.formParamName(filter)).append(" ");
}
}
first = false;
}
String disjunctionString = disjunction.toString();
if (!disjunctionString.isEmpty()) {
conjunction.append("and ( ").append(disjunctionString).append(" ) ");
}
}
return queryString + conjunction.toString();
}
Aggregations