• 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

79.31
/src/main/java/jp/co/future/uroborosql/converter/EntityResultSetConverter.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.converter;
8

9
import java.lang.reflect.Constructor;
10
import java.lang.reflect.InvocationTargetException;
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import java.util.Arrays;
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.function.Function;
17
import java.util.stream.Collectors;
18

19
import jp.co.future.uroborosql.exception.UroborosqlRuntimeException;
20
import jp.co.future.uroborosql.mapping.MappingColumn;
21
import jp.co.future.uroborosql.mapping.MappingUtils;
22
import jp.co.future.uroborosql.mapping.mapper.PropertyMapperManager;
23
import jp.co.future.uroborosql.utils.CaseFormat;
24

25
/**
26
 * 検索結果の1行を任意型に変換する変換器
27
 *
28
 * @param <E> エンティティ型
29
 * @author ota
30
 *
31
 */
32
public class EntityResultSetConverter<E> implements ResultSetConverter<E> {
33
        private final PropertyMapperManager mapperManager;
34
        private final Constructor<? extends E> constructor;
35
        private final Map<String, MappingColumn> mappingColumnMap;
36
        private Map<MappingColumn, Integer> columnPositionMap;
37

38
        /**
39
         * コンストラクタ
40
         *
41
         * @param schema スキーマ
42
         * @param entityType エンティティタイプ
43
         * @param mapperManager PropertyMapperManager
44
         */
45
        public EntityResultSetConverter(final String schema, final Class<? extends E> entityType,
46
                        final PropertyMapperManager mapperManager) {
1✔
47
                this.mapperManager = mapperManager;
1✔
48
                try {
49
                        this.constructor = entityType.getConstructor();
1✔
NEW
50
                } catch (NoSuchMethodException ex) {
×
NEW
51
                        throw new UroborosqlRuntimeException("EntityType should have a default constructor.", ex);
×
52
                }
1✔
53

54
                this.mappingColumnMap = Arrays.stream(MappingUtils.getMappingColumns(schema, entityType))
1✔
55
                                .collect(Collectors.toMap(c -> CaseFormat.UPPER_SNAKE_CASE.convert(c.getName()), Function.identity()));
1✔
56
        }
1✔
57

58
        /**
59
         * {@inheritDoc}
60
         *
61
         * @see jp.co.future.uroborosql.converter.ResultSetConverter#createRecord(java.sql.ResultSet)
62
         */
63
        @Override
64
        public E createRecord(final ResultSet rs) throws SQLException {
65
                try {
66
                        if (columnPositionMap == null) {
1✔
67
                                var rsmd = rs.getMetaData();
1✔
68
                                var columnCount = rsmd.getColumnCount();
1✔
69

70
                                // resizeが発生しないよう、初期loadFactorで溢れないサイズを指定する。
71
                                // MapのloadFactorはデフォルト0.75(3/4)なので 4/3 を掛けている。そのうえで切り捨てが発生してもキャパシティを越えないよう +1 している。
72
                                columnPositionMap = new HashMap<>(columnCount * 4 / 3 + 1);
1✔
73
                                // columnLabelsは1始まりの配列で値を格納
74
                                for (var i = 1; i <= columnCount; i++) {
1✔
75
                                        var columnLabel = CaseFormat.UPPER_SNAKE_CASE.convert(rsmd.getColumnLabel(i));
1✔
76
                                        var col = mappingColumnMap.get(columnLabel);
1✔
77
                                        if (col != null) {
1✔
78
                                                columnPositionMap.put(col, i);
1✔
79
                                        }
80
                                }
81
                        }
82

83
                        var rec = constructor.newInstance();
1✔
84
                        for (var entry : columnPositionMap.entrySet()) {
1✔
85
                                var column = entry.getKey();
1✔
86
                                var position = entry.getValue();
1✔
87
                                column.setValue(rec, mapperManager.getValue(column.getJavaType(), rs, position));
1✔
88
                        }
1✔
89
                        return rec;
1✔
NEW
90
                } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
×
NEW
91
                        throw new UroborosqlRuntimeException(ex);
×
NEW
92
                } catch (SQLException | RuntimeException | Error ex) {
×
NEW
93
                        throw ex;
×
94
                }
95
        }
96
}
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

© 2026 Coveralls, Inc