/** * Adds an <code>Expression</code> to a <code>Criteria</code>. * * @param criteria * @param parameterName * @param parameterValue * @param comparatorID * @param matchMode */ private void addExpression( org.hibernate.Criteria criteria, String parameterName, Object parameterValue, int comparatorID, org.hibernate.criterion.MatchMode matchMode) { if (parameterValue != null) { switch (comparatorID) { case CriteriaSearchParameter.LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add( org.hibernate.criterion.Expression.like( parameterName, (String) parameterValue, matchMode)); } else { criteria.add(org.hibernate.criterion.Expression.like(parameterName, parameterValue)); } break; } case CriteriaSearchParameter.INSENSITIVE_LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValue instanceof String)) { criteria.add( org.hibernate.criterion.Expression.ilike( parameterName, (String) parameterValue, matchMode)); } else { criteria.add(org.hibernate.criterion.Expression.ilike(parameterName, parameterValue)); } break; } case CriteriaSearchParameter.EQUAL_COMPARATOR: { criteria.add(org.hibernate.criterion.Expression.eq(parameterName, parameterValue)); break; } case CriteriaSearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { criteria.add(org.hibernate.criterion.Expression.ge(parameterName, parameterValue)); break; } case CriteriaSearchParameter.GREATER_THAN_COMPARATOR: { criteria.add(org.hibernate.criterion.Expression.gt(parameterName, parameterValue)); break; } case CriteriaSearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { criteria.add(org.hibernate.criterion.Expression.le(parameterName, parameterValue)); break; } case CriteriaSearchParameter.LESS_THAN_COMPARATOR: { criteria.add(org.hibernate.criterion.Expression.lt(parameterName, parameterValue)); break; } } } else { criteria.add(org.hibernate.criterion.Expression.isNull(parameterName)); } }
public List getNextPrevEntries( WeblogEntryData current, String catName, String locale, int maxEntries, boolean next) throws RollerException { Junction conjunction = Expression.conjunction(); conjunction.add(Expression.eq("website", current.getWebsite())); conjunction.add(Expression.eq("status", WeblogEntryData.PUBLISHED)); if (next) { conjunction.add(Expression.gt("pubTime", current.getPubTime())); } else { conjunction.add(Expression.lt("pubTime", current.getPubTime())); } if (catName != null && !catName.trim().equals("/")) { WeblogCategoryData category = getWeblogCategoryByPath(current.getWebsite(), null, catName); if (category != null) { conjunction.add(Expression.eq("category", category)); } else { throw new RollerException("Cannot find category: " + catName); } } if (locale != null) { conjunction.add(Expression.ilike("locale", locale, MatchMode.START)); } try { Session session = ((HibernatePersistenceStrategy) this.strategy).getSession(); Criteria criteria = session.createCriteria(WeblogEntryData.class); criteria.addOrder(next ? Order.asc("pubTime") : Order.desc("pubTime")); criteria.add(conjunction); criteria.setMaxResults(maxEntries); List results = criteria.list(); return results; } catch (HibernateException e) { throw new RollerException(e); } }
/** * Adds an <code>Expression</code> to a <code>Criteria</code>. The given <code>parameterValues * </code> represents either an array of <code>String</code> or another object. The different * values in the array are added to a disjunction which is connected with logical and to the other * criteria of the search. * * @param criteria * @param parameterName * @param parameterValues * @param searchIfNull * @param comparatorID * @param matchMode */ private void addExpression( org.hibernate.Criteria criteria, String parameterName, Object[] parameterValues, int comparatorID, org.hibernate.criterion.MatchMode matchMode) { if (parameterValues != null) { org.hibernate.criterion.Disjunction disjunction = org.hibernate.criterion.Expression.disjunction(); switch (comparatorID) { case CriteriaSearchParameter.LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.like( parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.like( parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } } break; } case CriteriaSearchParameter.INSENSITIVE_LIKE_COMPARATOR: { if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.ilike( parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.ilike( parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } } break; } case CriteriaSearchParameter.EQUAL_COMPARATOR: { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.eq(parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } break; } case CriteriaSearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.ge(parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } break; } case CriteriaSearchParameter.GREATER_THAN_COMPARATOR: { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.gt(parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } break; } case CriteriaSearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.le(parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } break; } case CriteriaSearchParameter.LESS_THAN_COMPARATOR: { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add( org.hibernate.criterion.Expression.lt(parameterName, parameterValues[index])); } else { disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName)); } } break; } } criteria.add(disjunction); } else { criteria.add(org.hibernate.criterion.Expression.isNull(parameterName)); } }