use of org.apache.activemq.artemis.selector.filter.BooleanExpression in project activemq-artemis by apache.
the class SelectorParserTest method testParseWithParensAround.
@Test
public void testParseWithParensAround() throws Exception {
String[] values = { "x = 1 and y = 2", "(x = 1) and (y = 2)", "((x = 1) and (y = 2))" };
for (int i = 0; i < values.length; i++) {
String value = values[i];
info("Parsing: " + value);
BooleanExpression andExpression = parse(value);
Assert.assertTrue("Created LogicExpression expression", andExpression instanceof LogicExpression);
LogicExpression logicExpression = (LogicExpression) andExpression;
Expression left = logicExpression.getLeft();
Expression right = logicExpression.getRight();
Assert.assertTrue("Left is a binary filter", left instanceof ComparisonExpression);
Assert.assertTrue("Right is a binary filter", right instanceof ComparisonExpression);
ComparisonExpression leftCompare = (ComparisonExpression) left;
ComparisonExpression rightCompare = (ComparisonExpression) right;
assertPropertyExpression("left", leftCompare.getLeft(), "x");
assertPropertyExpression("right", rightCompare.getLeft(), "y");
}
}
use of org.apache.activemq.artemis.selector.filter.BooleanExpression in project activemq-artemis by apache.
the class SelectorParserTest method testParseXPath.
@Test
public void testParseXPath() throws Exception {
BooleanExpression filter = parse("XPATH '//title[@lang=''eng'']'");
Assert.assertTrue("Created XPath expression", filter instanceof XPathExpression);
info("Expression: " + filter);
}
use of org.apache.activemq.artemis.selector.filter.BooleanExpression in project activemq-artemis by apache.
the class SelectorParser method parse.
public static BooleanExpression parse(String sql) throws FilterException {
Object result = cache.get(sql);
if (result instanceof FilterException) {
throw (FilterException) result;
} else if (result instanceof BooleanExpression) {
return (BooleanExpression) result;
} else {
String actual = sql;
boolean convertStringExpressions = false;
boolean hyphenatedProps = false;
while (true) {
if (actual.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
convertStringExpressions = true;
actual = actual.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
continue;
}
if (actual.startsWith(HYPHENATED_PROPS_PREFIX)) {
hyphenatedProps = true;
actual = actual.substring(HYPHENATED_PROPS_PREFIX.length());
continue;
}
if (actual.startsWith(NO_CONVERT_STRING_EXPRESSIONS_PREFIX)) {
convertStringExpressions = false;
actual = actual.substring(NO_CONVERT_STRING_EXPRESSIONS_PREFIX.length());
continue;
}
if (actual.startsWith(NO_HYPHENATED_PROPS_PREFIX)) {
hyphenatedProps = false;
actual = actual.substring(NO_HYPHENATED_PROPS_PREFIX.length());
continue;
}
break;
}
if (convertStringExpressions) {
ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
}
try {
BooleanExpression e = null;
if (hyphenatedProps) {
HyphenatedParser parser = new HyphenatedParser(new StringReader(actual));
e = parser.JmsSelector();
} else {
StrictParser parser = new StrictParser(new StringReader(actual));
e = parser.JmsSelector();
}
cache.put(sql, e);
return e;
} catch (Throwable e) {
FilterException fe = new FilterException(actual, e);
cache.put(sql, fe);
throw fe;
} finally {
if (convertStringExpressions) {
ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
}
}
}
}
use of org.apache.activemq.artemis.selector.filter.BooleanExpression in project activemq-artemis by apache.
the class SelectorTest method assertSelector.
protected void assertSelector(MockMessage message, String text, boolean expected) throws FilterException {
BooleanExpression selector = SelectorParser.parse(text);
Assert.assertTrue("Created a valid selector", selector != null);
boolean value = selector.matches(message);
Assert.assertEquals("Selector for: " + text, expected, value);
}
Aggregations