• 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

92.16
/src/main/java/jp/co/future/uroborosql/SqlQueryImpl.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;
8

9
import java.sql.ResultSet;
10
import java.sql.SQLException;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Optional;
14
import java.util.stream.Collectors;
15
import java.util.stream.Stream;
16

17
import jp.co.future.uroborosql.context.ExecutionContext;
18
import jp.co.future.uroborosql.converter.EntityResultSetConverter;
19
import jp.co.future.uroborosql.converter.MapResultSetConverter;
20
import jp.co.future.uroborosql.converter.ResultSetConverter;
21
import jp.co.future.uroborosql.converter.ScalarResultSetConverter;
22
import jp.co.future.uroborosql.exception.DataNonUniqueException;
23
import jp.co.future.uroborosql.exception.DataNotFoundException;
24
import jp.co.future.uroborosql.exception.UroborosqlSQLException;
25
import jp.co.future.uroborosql.fluent.SqlQuery;
26
import jp.co.future.uroborosql.mapping.mapper.PropertyMapperManager;
27
import jp.co.future.uroborosql.utils.CaseFormat;
28

29
/**
30
 * SqlQuery実装
31
 *
32
 * @author H.Sugimoto
33
 */
34
final class SqlQueryImpl extends AbstractSqlFluent<SqlQuery> implements SqlQuery {
35
        /**
36
         * コンストラクタ
37
         *
38
         * @param agent SqlAgent
39
         * @param context ExecutionContext
40
         */
41
        SqlQueryImpl(final SqlAgent agent, final ExecutionContext context) {
42
                super(agent, context);
1✔
43
        }
1✔
44

45
        /**
46
         * {@inheritDoc}
47
         *
48
         * @see jp.co.future.uroborosql.fluent.SqlQuery#first()
49
         */
50
        @Override
51
        public Map<String, Object> first() {
52
                return first(agent().getMapKeyCaseFormat());
1✔
53
        }
54

55
        /**
56
         * {@inheritDoc}
57
         *
58
         * @see jp.co.future.uroborosql.fluent.SqlQuery#first(jp.co.future.uroborosql.utils.CaseFormat)
59
         */
60
        @Override
61
        public Map<String, Object> first(final CaseFormat caseFormat) {
62
                return findFirst(caseFormat).orElseThrow(() -> new DataNotFoundException("query result is empty."));
1✔
63
        }
64

65
        /**
66
         * {@inheritDoc}
67
         *
68
         * @see jp.co.future.uroborosql.fluent.SqlQuery#first(Class)
69
         */
70
        @Override
71
        public <T> T first(final Class<T> type) {
72
                return findFirst(type).orElseThrow(() -> new DataNotFoundException("query result is empty."));
1✔
73
        }
74

75
        /**
76
         * {@inheritDoc}
77
         *
78
         * @see jp.co.future.uroborosql.fluent.SqlQuery#findFirst()
79
         */
80
        @Override
81
        public Optional<Map<String, Object>> findFirst() {
82
                return findFirst(agent().getMapKeyCaseFormat());
1✔
83
        }
84

85
        /**
86
         * {@inheritDoc}
87
         *
88
         * @see jp.co.future.uroborosql.fluent.SqlQuery#findFirst(jp.co.future.uroborosql.utils.CaseFormat)
89
         */
90
        @Override
91
        public Optional<Map<String, Object>> findFirst(final CaseFormat caseFormat) {
92
                try (var stream = stream(caseFormat)) {
1✔
93
                        return stream.findFirst();
1✔
94
                }
95
        }
96

97
        /**
98
         * {@inheritDoc}
99
         *
100
         * @see jp.co.future.uroborosql.fluent.SqlQuery#findFirst(java.lang.Class)
101
         */
102
        @Override
103
        public <T> Optional<T> findFirst(final Class<T> type) {
104
                try (var stream = stream(type)) {
1✔
105
                        return stream.findFirst();
1✔
106
                }
107
        }
108

109
        /**
110
         * {@inheritDoc}
111
         *
112
         * @see jp.co.future.uroborosql.fluent.SqlQuery#one()
113
         */
114
        @Override
115
        public Map<String, Object> one() {
116
                return one(agent().getMapKeyCaseFormat());
1✔
117
        }
118

119
        /**
120
         * {@inheritDoc}
121
         *
122
         * @see jp.co.future.uroborosql.fluent.SqlQuery#one(CaseFormat)
123
         */
124
        @Override
125
        public Map<String, Object> one(final CaseFormat caseFormat) {
126
                return findOne(caseFormat).orElseThrow(() -> new DataNotFoundException("query result is empty."));
1✔
127
        }
128

129
        /**
130
         * {@inheritDoc}
131
         *
132
         * @see jp.co.future.uroborosql.fluent.SqlQuery#one(Class)
133
         */
134
        @Override
135
        public <T> T one(final Class<T> type) {
136
                return findOne(type).orElseThrow(() -> new DataNotFoundException("query result is empty."));
1✔
137
        }
138

139
        /**
140
         * {@inheritDoc}
141
         *
142
         * @see jp.co.future.uroborosql.fluent.SqlQuery#findOne()
143
         */
144
        @Override
145
        public Optional<Map<String, Object>> findOne() {
146
                return findOne(agent().getMapKeyCaseFormat());
1✔
147
        }
148

149
        @Override
150
        public Optional<Map<String, Object>> findOne(final CaseFormat caseFormat) {
151
                try (var stream = stream(caseFormat)) {
1✔
152
                        var resultList = stream.limit(2).collect(Collectors.toList());
1✔
153
                        if (resultList.size() > 1) {
1✔
154
                                throw new DataNonUniqueException("two or more query results.");
1✔
155
                        }
156
                        return resultList.stream().findFirst();
1✔
157
                }
158
        }
159

160
        @Override
161
        public <T> Optional<T> findOne(final Class<T> type) {
162
                try (var stream = stream(type)) {
1✔
163
                        var resultList = stream.limit(2).collect(Collectors.toList());
1✔
164
                        if (resultList.size() > 1) {
1✔
165
                                throw new DataNonUniqueException("two or more query results.");
1✔
166
                        }
167
                        return resultList.stream().findFirst();
1✔
168
                }
169
        }
170

171
        /**
172
         * {@inheritDoc}
173
         *
174
         * @see jp.co.future.uroborosql.fluent.SqlQuery#resultSet()
175
         */
176
        @Override
177
        public ResultSet resultSet() {
178
                try {
179
                        return agent().query(context());
1✔
NEW
180
                } catch (SQLException ex) {
×
NEW
181
                        throw new UroborosqlSQLException(ex);
×
182
                }
183
        }
184

185
        /**
186
         * {@inheritDoc}
187
         *
188
         * @see jp.co.future.uroborosql.fluent.SqlQuery#collect()
189
         */
190
        @Override
191
        public List<Map<String, Object>> collect() {
192
                return collect(agent().getMapKeyCaseFormat());
1✔
193
        }
194

195
        /**
196
         * {@inheritDoc}
197
         *
198
         * @see jp.co.future.uroborosql.fluent.SqlQuery#collect(jp.co.future.uroborosql.utils.CaseFormat)
199
         */
200
        @Override
201
        public List<Map<String, Object>> collect(final CaseFormat caseFormat) {
202
                try {
203
                        return agent().query(context(), caseFormat);
1✔
204
                } catch (SQLException ex) {
1✔
205
                        throw new UroborosqlSQLException(ex);
1✔
206
                }
207
        }
208

209
        /**
210
         * {@inheritDoc}
211
         *
212
         * @see jp.co.future.uroborosql.fluent.SqlQuery#collect(java.lang.Class)
213
         */
214
        @Override
215
        public <T> List<T> collect(final Class<T> type) {
216
                try (var stream = stream(type)) {
1✔
217
                        return stream.collect(Collectors.toList());
1✔
218
                }
219
        }
220

221
        /**
222
         * {@inheritDoc}
223
         *
224
         * @see jp.co.future.uroborosql.fluent.SqlQuery#stream()
225
         */
226
        @Override
227
        public Stream<Map<String, Object>> stream() {
228
                return stream(agent().getMapKeyCaseFormat());
1✔
229
        }
230

231
        /**
232
         * {@inheritDoc}
233
         *
234
         * @see jp.co.future.uroborosql.fluent.SqlQuery#stream(jp.co.future.uroborosql.converter.ResultSetConverter)
235
         */
236
        @Override
237
        public <T> Stream<T> stream(final ResultSetConverter<T> converter) {
238
                try {
239
                        return agent().query(context(), converter);
1✔
NEW
240
                } catch (SQLException ex) {
×
NEW
241
                        throw new UroborosqlSQLException(ex);
×
242
                }
243
        }
244

245
        /**
246
         * {@inheritDoc}
247
         *
248
         * @see jp.co.future.uroborosql.fluent.SqlQuery#stream(jp.co.future.uroborosql.utils.CaseFormat)
249
         */
250
        @Override
251
        public Stream<Map<String, Object>> stream(final CaseFormat caseFormat) {
252
                return stream(new MapResultSetConverter(agent().getSqlConfig(), caseFormat));
1✔
253
        }
254

255
        /**
256
         * {@inheritDoc}
257
         *
258
         * @see jp.co.future.uroborosql.fluent.SqlQuery#stream(java.lang.Class)
259
         */
260
        @Override
261
        public <T> Stream<T> stream(final Class<T> type) {
262
                if (type == null) {
1✔
263
                        throw new IllegalArgumentException("Argument 'type' is required.");
1✔
264
                }
265
                var manager = new PropertyMapperManager(agent().getSqlConfig().getClock());
1✔
266
                if (ScalarResultSetConverter.accept(type)) {
1✔
267
                        return stream(new ScalarResultSetConverter<>(null, type, manager));
1✔
268
                } else {
269
                        return stream(new EntityResultSetConverter<>(context().getSchema(), type, manager));
1✔
270
                }
271
        }
272

273
        /**
274
         * {@inheritDoc}
275
         *
276
         * @see jp.co.future.uroborosql.fluent.SqlQuery#select(java.lang.Class)
277
         */
278
        @Override
279
        public <T> Stream<T> select(final Class<T> type) {
280
                return select(null, type);
1✔
281
        }
282

283
        /**
284
         * {@inheritDoc}
285
         *
286
         * @see jp.co.future.uroborosql.fluent.SqlQuery#select(java.lang.String, java.lang.Class)
287
         */
288
        @Override
289
        public <T> Stream<T> select(final String col, final Class<T> type) {
290
                if (type == null) {
1✔
291
                        throw new IllegalArgumentException("Argument 'type' is required.");
1✔
292
                }
293
                if (!ScalarResultSetConverter.accept(type)) {
1✔
294
                        throw new IllegalArgumentException(type.getName() + " is not supported.");
1✔
295
                }
296
                return stream(new ScalarResultSetConverter<>(col, type,
1✔
297
                                new PropertyMapperManager(agent().getSqlConfig().getClock())));
1✔
298
        }
299

300
}
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