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

future-architect / uroborosql / #770

12 Sep 2024 03:28PM UTC coverage: 90.35% (-0.9%) from 91.21%
#770

push

web-flow
 Enable per-SQL-ID log suppression (#322) (#332)

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

* Changed to use slf4j v2.0 API
Also added suppressLogging API

* Refactoring log-related class and method names.

384 of 587 new or added lines in 32 files covered. (65.42%)

9 existing lines in 7 files now uncovered.

8885 of 9834 relevant lines covered (90.35%)

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.log.support.ParserLoggingSupport;
17
import jp.co.future.uroborosql.parser.TransformContext;
18
import jp.co.future.uroborosql.utils.SqlFunction;
19
import ognl.ASTProperty;
20
import ognl.Node;
21
import ognl.Ognl;
22
import ognl.OgnlException;
23
import ognl.OgnlRuntime;
24

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

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

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

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

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

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

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

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

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