Search in sources :

Example 1 with SimpleCachingExpressionFactory

use of com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory in project blaze-persistence by Blazebit.

the class SimpleCachingExpressionFactoryTest method testCreateSimpleExpressionCache.

@Test
public void testCreateSimpleExpressionCache() {
    ExpressionFactory ef = new SimpleCachingExpressionFactory(new ExpressionFactoryImpl(new HashMap<String, FunctionKind>(), true, true));
    String expressionString = "SIZE(Hello.world[:hahaha].criteria[1].api.lsls[a.b.c.d.e]) + SIZE(Hello.world[:hahaha].criteria[1].api.lsls[a.b.c.d.e])";
    Expression expr1 = ef.createSimpleExpression(expressionString, false, true, false, null, null);
    Expression expr2 = ef.createSimpleExpression(expressionString, false, true, false, null, null);
    Assert.assertFalse(expr1 == expr2);
    Assert.assertEquals(expr1, expr2);
}
Also used : ExpressionFactory(com.blazebit.persistence.parser.expression.ExpressionFactory) SimpleCachingExpressionFactory(com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory) HashMap(java.util.HashMap) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) Expression(com.blazebit.persistence.parser.expression.Expression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) SimpleCachingExpressionFactory(com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory) ExpressionFactoryImpl(com.blazebit.persistence.parser.expression.ExpressionFactoryImpl) Test(org.junit.Test)

Example 2 with SimpleCachingExpressionFactory

use of com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory in project blaze-persistence by Blazebit.

the class SimpleCachingExpressionFactoryTest method testCreateSimpleExpressionCacheWithMacros.

@Test
public void testCreateSimpleExpressionCacheWithMacros() {
    ExpressionFactory ef = new SimpleCachingExpressionFactory(new ExpressionFactoryImpl(new HashMap<String, FunctionKind>(), true, true));
    MacroConfiguration macroConfiguration = MacroConfiguration.of(Collections.singletonMap("my_macro", (MacroFunction) new MacroFunction() {

        @Override
        public Expression apply(List<Expression> expressions) {
            PathExpression p;
            if (expressions.get(0) instanceof PathExpression) {
                p = (PathExpression) expressions.get(0);
            } else {
                p = new PathExpression(new ArrayList<>(Arrays.asList((PathElementExpression) expressions.get(0))));
            }
            p.getExpressions().add(new ArrayExpression(new PropertyExpression("lsls"), new PathExpression(Arrays.<PathElementExpression>asList(new PropertyExpression("a"), new PropertyExpression("b"), new PropertyExpression("c"), new PropertyExpression("d"), new PropertyExpression("e")))));
            return p;
        }

        @Override
        public Object[] getState() {
            return new Object[0];
        }

        @Override
        public boolean supportsCaching() {
            return true;
        }

        @Override
        public int hashCode() {
            return getClass().hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return obj.getClass() == getClass();
        }
    }));
    String expressionString = "SIZE(my_macro(Hello.world[:hahaha].criteria[1].api)) + SIZE(my_macro(Hello.world[:hahaha].criteria[1].api))";
    Expression expr1 = ef.createSimpleExpression(expressionString, false, true, false, macroConfiguration, null);
    Expression expr2 = ef.createSimpleExpression(expressionString, false, true, false, macroConfiguration, null);
    Assert.assertFalse(expr1 == expr2);
    Assert.assertEquals(expr1, expr2);
}
Also used : ExpressionFactory(com.blazebit.persistence.parser.expression.ExpressionFactory) SimpleCachingExpressionFactory(com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory) HashMap(java.util.HashMap) SimpleCachingExpressionFactory(com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory) ExpressionFactoryImpl(com.blazebit.persistence.parser.expression.ExpressionFactoryImpl) MacroFunction(com.blazebit.persistence.parser.expression.MacroFunction) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) MacroConfiguration(com.blazebit.persistence.parser.expression.MacroConfiguration) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) Expression(com.blazebit.persistence.parser.expression.Expression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) Test(org.junit.Test)

Aggregations

ArrayExpression (com.blazebit.persistence.parser.expression.ArrayExpression)2 Expression (com.blazebit.persistence.parser.expression.Expression)2 ExpressionFactory (com.blazebit.persistence.parser.expression.ExpressionFactory)2 ExpressionFactoryImpl (com.blazebit.persistence.parser.expression.ExpressionFactoryImpl)2 PathElementExpression (com.blazebit.persistence.parser.expression.PathElementExpression)2 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)2 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)2 SimpleCachingExpressionFactory (com.blazebit.persistence.parser.expression.SimpleCachingExpressionFactory)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 MacroConfiguration (com.blazebit.persistence.parser.expression.MacroConfiguration)1 MacroFunction (com.blazebit.persistence.parser.expression.MacroFunction)1