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

mybatis / mybatis-3 / #3393

25 Dec 2023 01:42AM UTC coverage: 86.665% (+0.05%) from 86.619%
#3393

Pull #2971

github

web-flow
Merge 9b99f44b6 into 01225f508
Pull Request #2971: docs: add dynamic sql example to @Select

3498 of 4275 branches covered (0.0%)

9294 of 10724 relevant lines covered (86.67%)

0.87 hits per line

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

83.33
/src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java
1
/*
2
 *    Copyright 2009-2023 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.scripting.xmltags;
17

18
import java.util.Map;
19
import java.util.concurrent.ConcurrentHashMap;
20

21
import ognl.Ognl;
22
import ognl.OgnlContext;
23
import ognl.OgnlException;
24

25
import org.apache.ibatis.builder.BuilderException;
26

27
/**
28
 * Caches OGNL parsed expressions.
29
 *
30
 * @author Eduardo Macarron
31
 *
32
 * @see <a href='https://github.com/mybatis/old-google-code-issues/issues/342'>Issue 342</a>
33
 */
34
public final class OgnlCache {
35

36
  private static final OgnlMemberAccess MEMBER_ACCESS = new OgnlMemberAccess();
1✔
37
  private static final OgnlClassResolver CLASS_RESOLVER = new OgnlClassResolver();
1✔
38
  private static final Map<String, Object> expressionCache = new ConcurrentHashMap<>();
1✔
39

40
  private OgnlCache() {
41
    // Prevent Instantiation of Static Class
42
  }
43

44
  public static Object getValue(String expression, Object root) {
45
    try {
46
      OgnlContext context = Ognl.createDefaultContext(root, MEMBER_ACCESS, CLASS_RESOLVER, null);
1✔
47
      return Ognl.getValue(parseExpression(expression), context, root);
1✔
48
    } catch (OgnlException e) {
×
49
      throw new BuilderException("Error evaluating expression '" + expression + "'. Cause: " + e, e);
×
50
    }
51
  }
52

53
  private static Object parseExpression(String expression) throws OgnlException {
54
    Object node = expressionCache.get(expression);
1✔
55
    if (node == null) {
1✔
56
      node = Ognl.parseExpression(expression);
1✔
57
      expressionCache.put(expression, node);
1✔
58
    }
59
    return node;
1✔
60
  }
61

62
}
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