Search in sources :

Example 1 with HyphenatedParser

use of org.apache.activemq.artemis.selector.hyphenated.HyphenatedParser 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();
            }
        }
    }
}
Also used : BooleanExpression(org.apache.activemq.artemis.selector.filter.BooleanExpression) HyphenatedParser(org.apache.activemq.artemis.selector.hyphenated.HyphenatedParser) StringReader(java.io.StringReader) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) StrictParser(org.apache.activemq.artemis.selector.strict.StrictParser)

Aggregations

StringReader (java.io.StringReader)1 BooleanExpression (org.apache.activemq.artemis.selector.filter.BooleanExpression)1 FilterException (org.apache.activemq.artemis.selector.filter.FilterException)1 HyphenatedParser (org.apache.activemq.artemis.selector.hyphenated.HyphenatedParser)1 StrictParser (org.apache.activemq.artemis.selector.strict.StrictParser)1