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

future-architect / uroborosql / #743

28 Jun 2024 04:17PM UTC coverage: 90.988% (+0.5%) from 90.484%
#743

push

web-flow
add paramIfNotEmpty method (#318)

* v0.x to master merge

* fix nanoseconds diff (java8 to java11)

* eclipse cleanup and  optimize import

* eclipse format

* optimize Imports

* remove unused annotation

* library version up

* migrate v0.x to master
- update java version 8 to 11
- update junit4 to junit5
- library version update

* fix test failed

* remove unused annotation

* fixed bug

* use var

* fix java8 coding style

* Refactoring TransactionContextManager

* Refactoring SqlAgent

* 途中コミット

* fix testcase

* fix review

* fix javadoc comments

* merge v0.x PR

* cleanup code

* cleanup test code

* change build status badge

* - agent.query, update, proc, batch にそれぞれSupplierを引数にとるメソッドを追加
- SqlQuery.paramとSqlEntityUpdate.setにFunctionを受け取るメソッドを追加

* testcaseの整形

* - SqlFluent と ExtractionCondition の分離
- Arrays.asList -> List.of への変更
- テストの整形

* - v0.x系の不具合対応の追いつき
- ログ出力の整理

* - SqlKindの整理(ENTITY_XXXの追加)
- REPL_LOGの追加
- Deprecatedメソッドの削除(SqlAgent)
- SqlAgent, ExecutionContextでsetterをfluent APIに変更

* DB接続URLの修正

* add and fix testcases.

* add event testcases.

* fix typo

* add paramIfNotEmpty method and StringUtils rename ObjectUtils

* fix review comments.

* remove unused import

1695 of 1958 new or added lines in 97 files covered. (86.57%)

26 existing lines in 10 files now uncovered.

8249 of 9066 relevant lines covered (90.99%)

0.91 hits per line

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

86.54
/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 org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15

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

27
/**
28
 * OGNLを使用した評価式パーサー
29
 *
30
 * @author H.Sugimoto
31
 */
32
public class OgnlExpressionParser extends AbstractExpressionParser {
33
        /** パーサーロガー */
34
        private static final Logger PARSER_LOG = LoggerFactory.getLogger("jp.co.future.uroborosql.sql.parser");
1✔
35

36
        /**
37
         * コンストラクタ
38
         */
39
        public OgnlExpressionParser() {
1✔
40
        }
1✔
41

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

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

68
        /**
69
         * OGNL評価式
70
         *
71
         * @author H.Sugimoto
72
         */
73
        private static class OgnlExpression implements Expression {
74
                private final Object expression;
75

76
                /**
77
                 * コンストラクタ
78
                 *
79
                 * @param expression 評価式
80
                 */
81
                public OgnlExpression(final Object expression) {
1✔
82
                        this.expression = expression;
1✔
83
                }
1✔
84

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

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

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

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