For example, if I do something like:
Criteria c = session.createCriteria(Book.class) .add(Expression.ge("release",reDate); .add(Expression.ge("price",price); .addOrder( Order.asc("date") ) .setFirstResult(0) .setMaxResults(10); c.list();
How can I use the same criteria instance, but delete (for example) the second criterion? I am trying to create a dynamic query in which I want the user to remove the filter without server support in order to restore the criteria from scratch.
thank
, (, ..) . API , , . , , add addOrder, , , .
add
addOrder
, , , .
, , , (, Collection), . , , , , , .
Collection
, , , , .
, () ? , , , , .
, () , .
:
public static void List<CriterionType> removeCriterions(Criteria criteria, Class<? extends Criterion> type) { Iterator<CriterionEntry> criterionIterator = ((CriteriaImpl) criteria).iterateExpressionEntries(); while (criterionIterator.hasNext()) { CriterionEntry criterionEntry = criterionIterator.next(); if (criterionEntry.getCriteria() == criteria) { Criterion criterion = criterionEntry.getCriterion(); if (null == type || criterion.getClass() == type) { criterionIterator.remove(); } } } }