Guest User

Untitled

a guest
Jul 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public Criterion convertExpression(LogicExpression expression, LogicContext context) {
  2.  
  3. Criterion criterion = null;
  4.  
  5. Operator operator = expression.getOperator();
  6. Operand rightOperand = expression.getRightOperand();
  7. Operand leftOperand = ((LogicExpressionBinary) expression).getLeftOperand();
  8. if (operator == null)
  9. criterion = createRootExpressionCriterion(expression);
  10. else {
  11. if (Operator.AND.equals(operator)) {
  12. Criterion rightCriterion = convertExpression((LogicExpression) rightOperand, context);
  13. Criterion leftCriterion = convertExpression((LogicExpression) leftOperand, context);
  14. criterion = Restrictions.and(rightCriterion, leftCriterion);
  15. } else if (Operator.OR.equals(operator)) {
  16. Criterion rightCriterion = convertExpression((LogicExpression) rightOperand, context);
  17. Criterion leftCriterion = convertExpression((LogicExpression) leftOperand, context);
  18. criterion = Restrictions.or(rightCriterion, leftCriterion);
  19. } else {
  20. if (leftOperand instanceof LogicComponent) {
  21. // if the left operand is component, then the right operand is an operand
  22. LogicComponent component = (LogicComponent) leftOperand;
  23. Operator componentOperator = expression.getOperator();
  24. Operand componentOperand = expression.getRightOperand();
  25. // insert the object to aliases
  26. if (StringUtils.isNotBlank(component.getObject())) {
  27. getAliases().add(component.getObject());
  28. }
  29. criterion = handleComponentExpression(component.getComponentProperty(), componentOperator, componentOperand, context.getIndexDate());
  30. } else {
  31. criterion = handleComparisonExpression(expression.getRootToken(), operator, rightOperand, context.getIndexDate());
  32. LogicExpression leftExpression = (LogicExpression) leftOperand;
  33. Operator leftOperator = leftExpression.getOperator();
  34. while(Operator.NOT.equals(leftOperator)) {
  35. criterion = Restrictions.not(criterion);
  36. leftOperand = ((LogicExpressionBinary) leftExpression).getLeftOperand();
  37. leftExpression = (LogicExpression) leftOperand;
  38. leftOperator = leftExpression.getOperator();
  39. }
  40. Criterion leftCriterion = convertExpression((LogicExpression) leftOperand, context);
  41. if (leftCriterion != null)
  42. criterion = Restrictions.and(criterion, leftCriterion);
  43. }
  44. }
  45. }
  46. return criterion;
  47. }
Add Comment
Please, Sign In to add comment