private static Logger log = LoggerFactory.getLogger(AbstractCriteriaDecorator.class);
@SuppressWarnings("rawtypes")
@Override
public void render(final CriteriaContext context) {
final Criterion field = context.getCriterion();
Criteria criteria = context.getOrderingCriteria();
final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT));
final Iterator<String> iter = propertyNamePath.iterator();
String key = null;
String associationPath = null;
if (propertyNamePath.size() == 1) {
associationPath = iter.next();
} else while (iter.hasNext()) {
key = iter.next();
if (associationPath == null) {
associationPath = new String(key);
} else {
associationPath += "." + key;
}
if (iter.hasNext()) {
criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.INNER_JOIN);
associationPath = new String(key);
}
}
final T value = getObjectValue(field);
ComparatorType comparator = field.getComparator();
if (value != null) {
if (value.toString().contains("%")) {
comparator = ComparatorType.LIKE;
}
}
if (field.getValue() != null || field.getComparator() == ComparatorType.IS_NULL || field.getComparator() == ComparatorType.IS_NOT_NULL) {
switch (comparator) {
case EQ:
criteria.add(Restrictions.eq(associationPath, value));
break;
case GE:
criteria.add(Restrictions.ge(associationPath, value));
break;
case GT:
criteria.add(Restrictions.gt(associationPath, value));
break;
case LE:
criteria.add(Restrictions.le(associationPath, value));
break;
case LT:
criteria.add(Restrictions.lt(associationPath, value));
break;
case NE:
criteria.add(Restrictions.ne(associationPath, value));
break;
case LIKE:
criteria.add(Restrictions.ilike(associationPath, value));
break;
case IS_NULL:
criteria.add(Restrictions.isNull(associationPath));
break;
case IS_NOT_NULL:
criteria.add(Restrictions.isNotNull(associationPath));
break;
case IN:
if (value instanceof Collection) {
criteria.add(Restrictions.in(associationPath, (Collection) value));
} else if (value instanceof Object[]) {
criteria.add(Restrictions.in(associationPath, (Object[]) value));
} else {
log.warn("Type not allowed for IN clause: " + value.getClass() + ", value: " + value);
}
break;
default:
log.warn("Restriction not supported: " + comparator);
break;
}
}
switch (field.getSortingType()) {
case ASCENDING:
criteria.addOrder(Order.asc(associationPath));
break;
case DESCENDING:
criteria.addOrder(Order.desc(associationPath));