• 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

62.86
/src/main/java/jp/co/future/uroborosql/parameter/mapper/DomainParameterMapper.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.parameter.mapper;
8

9
import java.lang.reflect.InvocationTargetException;
10
import java.lang.reflect.Modifier;
11
import java.sql.Connection;
12

13
import jp.co.future.uroborosql.exception.UroborosqlRuntimeException;
14
import jp.co.future.uroborosql.mapping.annotations.Domain;
15

16
/**
17
 * {@link Domain}配列用{@link BindParameterMapper}
18
 *
19
 * @author ota
20
 */
21
public class DomainParameterMapper implements BindParameterMapper<Object> {
1✔
22

23
        /**
24
         * {@inheritDoc}
25
         *
26
         * @see jp.co.future.uroborosql.parameter.mapper.BindParameterMapper#targetType()
27
         */
28
        @Override
29
        public Class<Object> targetType() {
30
                return Object.class;
×
31
        }
32

33
        @Override
34
        public boolean canAccept(final Object object) {
35
                return getDomainType(object) != null;
1✔
36
        }
37

38
        @Override
39
        public Object toJdbc(final Object original, final Connection connection,
40
                        final BindParameterMapperManager parameterMapperManager) {
41
                Class<?> type = getDomainType(original);
1✔
42
                var domain = type.getAnnotation(Domain.class);
1✔
43
                var value = getValue(type, domain, original);
1✔
44

45
                return parameterMapperManager.toJdbc(value, connection);
1✔
46
        }
47

48
        private Object getValue(final Class<?> type, final Domain domain, final Object original) {
49
                var methodName = domain.toJdbcMethod();
1✔
50
                try {
51
                        try {
52
                                var method = type.getMethod(methodName);
1✔
53
                                if (Modifier.isStatic(method.getModifiers())) {
1✔
54
                                        throw new IllegalStateException(
×
55
                                                        "not class method. [" + type.getSimpleName() + "#" + methodName + "]");
×
56
                                } else if (!domain.valueType().isAssignableFrom(method.getReturnType())) {
1✔
57
                                        throw new IllegalStateException(
×
58
                                                        "unmatch method result type. [" + type.getSimpleName() + "#" + methodName + "]");
×
59
                                }
60
                                return method.invoke(original);
1✔
61
                        } catch (NoSuchMethodException ex) {
1✔
62
                                try {
63
                                        // static?
64
                                        var method = type.getMethod(methodName, type);
1✔
65
                                        if (!Modifier.isStatic(method.getModifiers())) {
1✔
66
                                                throw new IllegalStateException(
×
67
                                                                "not static method. [" + type.getSimpleName() + "#" + methodName + "]");
×
68
                                        } else if (!domain.valueType().isAssignableFrom(method.getReturnType())) {
1✔
69
                                                throw new IllegalStateException(
×
70
                                                                "unmatch method result type. [" + type.getSimpleName() + "#" + methodName + "]");
×
71
                                        }
72
                                        return method.invoke(null, original);
1✔
NEW
73
                                } catch (NoSuchMethodException ex2) {
×
NEW
74
                                        throw new UroborosqlRuntimeException(ex);// 元のエラーでthrow
×
75
                                }
76
                        }
NEW
77
                } catch (IllegalAccessException | InvocationTargetException | SecurityException ex) {
×
NEW
78
                        throw new UroborosqlRuntimeException(ex);
×
79
                }
80
        }
81

82
        private Class<?> getDomainType(final Object object) {
83
                Class<?> type = object.getClass();
1✔
84
                while (!type.equals(Object.class)) {
1✔
85
                        if (type.getAnnotation(Domain.class) != null) {
1✔
86
                                return type;
1✔
87
                        }
88
                        type = type.getSuperclass();
1✔
89
                }
90
                return null;
1✔
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