use of com.pogeyan.cmis.api.uri.expression.BinaryExpression in project copper-cms by PogeyanOSS.
the class MongoExpressionVisitor method visitBinary.
@Override
public Object visitBinary(BinaryExpression binaryExpression, BinaryOperator operator, Object leftSide, Object rightSide) {
if (leftSide instanceof BinaryExpression) {
// needs brackets to show the higher priority
if (BinaryOperator.AND.equals(((BinaryExpression) binaryExpression).getOperator()) || BinaryOperator.OR.equals(((BinaryExpression) binaryExpression).getOperator())) {
}
} else if (leftSide instanceof PropertyExpression) {
PropertyExpression leftOp = (PropertyExpression) leftSide;
String rightSideValue = null;
if (rightSide instanceof PropertyExpression) {
PropertyExpression rightOp = (PropertyExpression) rightSide;
rightSideValue = rightOp.getUriLiteral();
} else if (rightSide instanceof LiteralExpression) {
LiteralExpression rightOp = (LiteralExpression) rightSide;
rightSideValue = rightOp.getUriLiteral();
} else if (rightSide instanceof String) {
rightSideValue = rightSide.toString();
}
switch(operator) {
case EQ:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).equal(getStringObjectValue(rightSideValue));
case NE:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).notEqual(getStringObjectValue(rightSideValue));
case GE:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).greaterThanOrEq(getNumberObjectValue(rightSideValue));
case GT:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).greaterThan(getNumberObjectValue(rightSideValue));
case LE:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).lessThanOrEq(getNumberObjectValue(rightSideValue));
case LT:
return this.query.criteria(getQueryName(leftOp.getUriLiteral())).lessThan(getNumberObjectValue(rightSideValue));
default:
// Other operators are not supported for SQL Statements
throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
}
} else {
ArrayList<Criteria> operands = new ArrayList<>();
if (leftSide.getClass() == CriteriaContainerImpl.class) {
operands.add((Criteria) leftSide);
}
if (rightSide.getClass() == CriteriaContainerImpl.class) {
operands.add((Criteria) rightSide);
}
switch(operator) {
case OR:
this.query.or(operands.toArray(new Criteria[operands.size()]));
break;
case AND:
this.query.and(operands.toArray(new Criteria[operands.size()]));
break;
default:
// Other operators are not supported for SQL Statements
throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
}
}
// return the binary statement
return this.query;
}
use of com.pogeyan.cmis.api.uri.expression.BinaryExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readElements.
protected CommonExpression readElements(final CommonExpression leftExpression, final int priority) throws ExpressionParserException, ExpressionParserInternalError {
CommonExpression leftNode = leftExpression;
CommonExpression rightNode;
BinaryExpression binaryNode;
ActualBinaryOperator operator = readBinaryOperator();
ActualBinaryOperator nextOperator;
while ((operator != null) && (operator.getOP().getPriority() >= priority)) {
// eat the operator
tokenList.next();
// throws
rightNode = readElement(leftNode, operator);
// FilterParserInternalError
if (rightNode == null) {
// Tested with TestParserExceptions.testAdditionalStuff CASE 10
throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(operator.getToken().getPosition() + operator.getToken().getUriLiteral().length(), curExpression);
}
nextOperator = readBinaryOperator();
// a higher priority than "or"
while ((nextOperator != null) && (nextOperator.getOP().getPriority() > operator.getOP().getPriority())) {
// recurse until the a binary operator with a lower priority is
// detected
rightNode = readElements(rightNode, nextOperator.getOP().getPriority());
nextOperator = readBinaryOperator();
}
// some special handling in the filterTree
if (operator.getOP().getOperator() == BinaryOperator.PROPERTY_ACCESS) {
binaryNode = new MemberExpressionImpl(leftNode, rightNode);
} else {
binaryNode = new BinaryExpressionImpl(operator.getOP(), leftNode, rightNode, operator.getToken());
}
// try {
// validateBinaryOperatorTypes(binaryNode);
// } catch (ExpressionParserException expressionException) {
// // Extend the error information
// // Tested for original throw point
// expressionException.setFilterTree(binaryNode);
// throw expressionException;
// }
leftNode = binaryNode;
operator = readBinaryOperator();
}
// Add special handling for expressions like
// $filter=notsupportedfunction('a')
// If this special handling is not in place the error text would be
// -->Invalid token "(" detected after parsing at position 21 in
// "notsupportedfunction('a')".
// with this special handling we ensure that the error text would be
Token token = tokenList.lookToken();
if (token != null) {
if ((leftNode.getKind() == ExpressionKind.PROPERTY) && (tokenList.lookToken().getKind() == TokenKind.OPENPAREN)) {
// Tested with TestParserExceptions.testAdditionalStuff CASE 2
throw FilterParserExceptionImpl.createINVALID_METHOD_CALL(leftNode, tokenList.lookPrevToken(), curExpression);
}
}
return leftNode;
}
Aggregations