• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-anno/src/main/java/com/alicp/jetcache/anno/method/ExpressionUtil.java
1
/**
2
 * Created on  13-10-02 18:38
3
 */
4
package com.alicp.jetcache.anno.method;
5

6
import com.alicp.jetcache.anno.CacheConsts;
7
import com.alicp.jetcache.anno.support.CacheAnnoConfig;
8
import com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig;
9
import com.alicp.jetcache.anno.support.CachedAnnoConfig;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

13
/**
14
 * @author huangli
15
 */
16
class ExpressionUtil {
×
17

18
    private static final Logger logger = LoggerFactory.getLogger(ExpressionUtil.class);
×
19

20
    static Object EVAL_FAILED = new Object();
×
21

22
    public static boolean evalCondition(CacheInvokeContext context, CacheAnnoConfig cac) {
23
        String condition = cac.getCondition();
×
24
        try {
25
            if (cac.getConditionEvaluator() == null) {
×
26
                if (CacheConsts.isUndefined(condition)) {
×
27
                    cac.setConditionEvaluator(o -> true);
×
28
                } else {
29
                    ExpressionEvaluator e = new ExpressionEvaluator(condition, cac.getDefineMethod());
×
30
                    cac.setConditionEvaluator((o) -> (Boolean) e.apply(o));
×
31
                }
32
            }
33
            return cac.getConditionEvaluator().apply(context);
×
34
        } catch (Exception e) {
×
35
            logger.error("error occurs when eval condition \"" + condition + "\" in " + context.getMethod() + ":" + e.getMessage(), e);
×
36
            return false;
×
37
        }
38
    }
39

40
    public static boolean evalPostCondition(CacheInvokeContext context, CachedAnnoConfig cac) {
41
        String postCondition = cac.getPostCondition();
×
42
        try {
43
            if (cac.getPostConditionEvaluator() == null) {
×
44
                if (CacheConsts.isUndefined(postCondition)) {
×
45
                    cac.setPostConditionEvaluator(o -> true);
×
46
                } else {
47
                    ExpressionEvaluator e = new ExpressionEvaluator(postCondition, cac.getDefineMethod());
×
48
                    cac.setPostConditionEvaluator((o) -> (Boolean) e.apply(o));
×
49
                }
50
            }
51
            return cac.getPostConditionEvaluator().apply(context);
×
52
        } catch (Exception e) {
×
53
            logger.error("error occurs when eval postCondition \"" + postCondition + "\" in " + context.getMethod() + ":" + e.getMessage(), e);
×
54
            return false;
×
55
        }
56
    }
57

58
    public static Object evalKey(CacheInvokeContext context, CacheAnnoConfig cac) {
59
        String keyScript = cac.getKey();
×
60
        try {
61
            if (cac.getKeyEvaluator() == null) {
×
62
                if (CacheConsts.isUndefined(keyScript)) {
×
63
                    cac.setKeyEvaluator(o -> {
×
64
                        CacheInvokeContext c = (CacheInvokeContext) o;
×
65
                        return c.getArgs() == null || c.getArgs().length == 0 ? "_$JETCACHE_NULL_KEY$_" : c.getArgs();
×
66
                    });
67
                } else {
68
                    ExpressionEvaluator e = new ExpressionEvaluator(keyScript, cac.getDefineMethod());
×
69
                    cac.setKeyEvaluator((o) -> e.apply(o));
×
70
                }
71
            }
72
            return cac.getKeyEvaluator().apply(context);
×
73
        } catch (Exception e) {
×
74
            logger.error("error occurs when eval key \"" + keyScript + "\" in " + context.getMethod() + ":" + e.getMessage(), e);
×
75
            return null;
×
76
        }
77
    }
78

79
    public static Object evalValue(CacheInvokeContext context, CacheUpdateAnnoConfig cac) {
80
        String valueScript = cac.getValue();
×
81
        try {
82
            if (cac.getValueEvaluator() == null) {
×
83
                ExpressionEvaluator e = new ExpressionEvaluator(valueScript, cac.getDefineMethod());
×
84
                cac.setValueEvaluator((o) -> e.apply(o));
×
85
            }
86
            return cac.getValueEvaluator().apply(context);
×
87
        } catch (Exception e) {
×
88
            logger.error("error occurs when eval value \"" + valueScript + "\" in " + context.getMethod() + ":" + e.getMessage(), e);
×
89
            return EVAL_FAILED;
×
90
        }
91
    }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc