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

future-architect / uroborosql / #767

26 Aug 2024 05:08PM UTC coverage: 90.274% (-0.9%) from 91.21%
#767

push

HidekiSugimoto189
各Logger用のインタフェースを作成し必要なクラスがimplementsするように修正。そのうえでSLF4J 2.xのAPIを利用するように変更(性能改善)

360 of 568 new or added lines in 32 files covered. (63.38%)

9 existing lines in 7 files now uncovered.

8864 of 9819 relevant lines covered (90.27%)

0.9 hits per line

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

81.48
/src/main/java/jp/co/future/uroborosql/expr/ognl/OgnlExpressionParser.java
1
/**
2
 * Copyright (c) 2017-present, Future Corporation
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
package jp.co.future.uroborosql.expr.ognl;
8

9
import java.util.LinkedHashSet;
10
import java.util.Objects;
11
import java.util.Set;
12

13
import jp.co.future.uroborosql.exception.ExpressionRuntimeException;
14
import jp.co.future.uroborosql.expr.AbstractExpressionParser;
15
import jp.co.future.uroborosql.expr.Expression;
16
import jp.co.future.uroborosql.parser.TransformContext;
17
import jp.co.future.uroborosql.utils.SqlFunction;
18
import ognl.ASTProperty;
19
import ognl.Node;
20
import ognl.Ognl;
21
import ognl.OgnlException;
22
import ognl.OgnlRuntime;
23

24
/**
25
 * OGNLを使用した評価式パーサー
26
 *
27
 * @author H.Sugimoto
28
 */
29
public class OgnlExpressionParser extends AbstractExpressionParser {
30
        /**
31
         * コンストラクタ
32
         */
33
        public OgnlExpressionParser() {
1✔
34
        }
1✔
35

36
        /**
37
         * {@inheritDoc}
38
         *
39
         * @see jp.co.future.uroborosql.expr.ExpressionParser#initialize()
40
         */
41
        @Override
42
        public void initialize() {
43
                super.initialize();
1✔
44
                OgnlRuntime.setPropertyAccessor(TransformContext.class,
1✔
45
                                new TransformContextPropertyAccessor(getSqlConfig().getDialect().getSqlFunction()));
1✔
46
        }
1✔
47

48
        /**
49
         * {@inheritDoc}
50
         *
51
         * @see jp.co.future.uroborosql.expr.ExpressionParser#parse(java.lang.String)
52
         */
53
        @Override
54
        public Expression parse(final String expression) {
55
                try {
56
                        return new OgnlExpression(Ognl.parseExpression(expression));
1✔
57
                } catch (OgnlException ex) {
×
58
                        throw new ExpressionRuntimeException("Failed to parse the expression.[" + expression + "]", ex);
×
59
                }
60
        }
61

62
        /**
63
         * OGNL評価式
64
         *
65
         * @author H.Sugimoto
66
         */
67
        private static class OgnlExpression implements Expression {
68
                private final Object expression;
69

70
                /**
71
                 * コンストラクタ
72
                 *
73
                 * @param expression 評価式
74
                 */
75
                public OgnlExpression(final Object expression) {
1✔
76
                        this.expression = expression;
1✔
77
                }
1✔
78

79
                /**
80
                 * {@inheritDoc}
81
                 *
82
                 * @see jp.co.future.uroborosql.expr.Expression#getValue(java.lang.Object)
83
                 */
84
                @Override
85
                public Object getValue(final Object context) {
86
                        try {
87
                                return Ognl.getValue(expression, context);
1✔
88
                        } catch (OgnlException ex) {
×
89
                                throw new ExpressionRuntimeException("Acquire an object failed.[" + expression + "]", ex);
×
90
                        }
91
                }
92

93
                /**
94
                 * {@inheritDoc}
95
                 *
96
                 * @see jp.co.future.uroborosql.expr.Expression#dumpNode(java.lang.Object)
97
                 */
98
                @Override
99
                public StringBuilder dumpNode(final Object context) {
100
                        var builder = new StringBuilder();
1✔
101
                        if (expression != null) {
1✔
102
                                Set<ASTProperty> props = new LinkedHashSet<>();
1✔
103
                                traverseNode((Node) expression, props);
1✔
104
                                for (var prop : props) {
1✔
105
                                        var propName = prop.toString();
1✔
106
                                        if (!SqlFunction.SHORT_NAME.equals(propName)) {
1✔
107
                                                try {
108
                                                        var value = Ognl.getValue(prop, context, null);
1✔
109
                                                        builder.append(propName)
1✔
110
                                                                        .append(":[")
1✔
111
                                                                        .append(Objects.toString(value, null))
1✔
112
                                                                        .append("],");
1✔
113
                                                } catch (OgnlException ex) {
×
114
                                                        // ダンプ処理でシステムが止まっては困るのでログ出力して握りつぶす
NEW
115
                                                        PARSER_LOG.atWarn()
×
NEW
116
                                                                        .setMessage(ex.getMessage())
×
NEW
117
                                                                        .setCause(ex)
×
NEW
118
                                                                        .log();
×
119
                                                }
1✔
120
                                        }
121
                                }
1✔
122
                        }
123
                        return builder;
1✔
124
                }
125

126
                /**
127
                 * {@inheritDoc}
128
                 *
129
                 * @see jp.co.future.uroborosql.expr.Expression#collectParams(java.util.Set)
130
                 */
131
                @Override
132
                public void collectParams(final Set<String> params) {
133
                        Set<ASTProperty> props = new LinkedHashSet<>();
1✔
134
                        traverseNode((Node) expression, props);
1✔
135
                        for (var prop : props) {
1✔
136
                                var propName = prop.toString();
1✔
137
                                if (!SqlFunction.SHORT_NAME.equals(propName)) {
1✔
138
                                        params.add(propName);
1✔
139
                                }
140
                        }
1✔
141
                }
1✔
142

143
                /**
144
                 * 評価式の探索
145
                 *
146
                 * @param node ノード
147
                 * @param params プロパティが見つかった場合に格納するSetオブジェクト
148
                 */
149
                private void traverseNode(final Node node, final Set<ASTProperty> props) {
150
                        if (node == null) {
1✔
151
                                return;
×
152
                        }
153
                        if (node instanceof ASTProperty) {
1✔
154
                                var prop = (ASTProperty) node;
1✔
155
                                props.add(prop);
1✔
156
                        } else {
1✔
157
                                var childCount = node.jjtGetNumChildren();
1✔
158
                                for (var i = 0; i < childCount; i++) {
1✔
159
                                        var child = node.jjtGetChild(i);
1✔
160
                                        traverseNode(child, props);
1✔
161
                                }
162
                        }
163
                }
1✔
164
        }
165
}
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