use of org.apache.activemq.artemis.selector.strict.StrictParser 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();
}
}
}
}
Aggregations