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

future-architect / uroborosql / #839

05 May 2025 05:28AM UTC coverage: 90.172% (-0.02%) from 90.196%
#839

push

web-flow
backport #350 add updateChained method. (#351)

* backport #350 add updateChained method.

* update github-action settings

* fix review

17 of 19 new or added lines in 3 files covered. (89.47%)

2 existing lines in 1 file now uncovered.

7936 of 8801 relevant lines covered (90.17%)

0.9 hits per line

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

86.62
/src/main/java/jp/co/future/uroborosql/AbstractAgent.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.CallableStatement;
10
import java.sql.Connection;
11
import java.sql.PreparedStatement;
12
import java.sql.SQLException;
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.Collections;
16
import java.util.Iterator;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Spliterator;
20
import java.util.Spliterators;
21
import java.util.concurrent.atomic.AtomicReference;
22
import java.util.stream.Collectors;
23
import java.util.stream.Stream;
24
import java.util.stream.StreamSupport;
25

26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

29
import jp.co.future.uroborosql.config.SqlConfig;
30
import jp.co.future.uroborosql.connection.ConnectionContext;
31
import jp.co.future.uroborosql.context.SqlContext;
32
import jp.co.future.uroborosql.coverage.CoverageData;
33
import jp.co.future.uroborosql.coverage.CoverageHandler;
34
import jp.co.future.uroborosql.dialect.Dialect;
35
import jp.co.future.uroborosql.enums.InsertsType;
36
import jp.co.future.uroborosql.enums.SqlKind;
37
import jp.co.future.uroborosql.exception.EntitySqlRuntimeException;
38
import jp.co.future.uroborosql.exception.UroborosqlRuntimeException;
39
import jp.co.future.uroborosql.filter.SqlFilterManager;
40
import jp.co.future.uroborosql.fluent.Procedure;
41
import jp.co.future.uroborosql.fluent.SqlBatch;
42
import jp.co.future.uroborosql.fluent.SqlEntityQuery;
43
import jp.co.future.uroborosql.fluent.SqlQuery;
44
import jp.co.future.uroborosql.fluent.SqlUpdate;
45
import jp.co.future.uroborosql.mapping.EntityHandler;
46
import jp.co.future.uroborosql.mapping.TableMetadata;
47
import jp.co.future.uroborosql.parser.ContextTransformer;
48
import jp.co.future.uroborosql.parser.SqlParser;
49
import jp.co.future.uroborosql.parser.SqlParserImpl;
50
import jp.co.future.uroborosql.store.SqlManager;
51
import jp.co.future.uroborosql.tx.LocalTransactionManager;
52
import jp.co.future.uroborosql.tx.SQLRunnable;
53
import jp.co.future.uroborosql.tx.SQLSupplier;
54
import jp.co.future.uroborosql.tx.TransactionManager;
55
import jp.co.future.uroborosql.utils.CaseFormat;
56
import jp.co.future.uroborosql.utils.StringUtils;
57

58
/**
59
 * SqlAgentの抽象親クラス
60
 *
61
 * @author H.Sugimoto
62
 */
63
public abstract class AbstractAgent implements SqlAgent {
64
        /** ロガー */
65
        private static final Logger LOG = LoggerFactory.getLogger(AbstractAgent.class);
1✔
66

67
        /** SQLカバレッジ用ロガー */
68
        protected static final Logger COVERAGE_LOG = LoggerFactory.getLogger(SqlAgent.class.getPackage().getName()
1✔
69
                        + "sql.coverage");
70

71
        /** ログ出力を抑止するためのMDCキー */
72
        protected static final String SUPPRESS_PARAMETER_LOG_OUTPUT = "SuppressParameterLogOutput";
73

74
        /** SqlContext属性キー:リトライカウント */
75
        protected static final String CTX_ATTR_KEY_RETRY_COUNT = "__retryCount";
76

77
        /** SqlContext属性キー:バインドパラメータコメントの出力有無 */
78
        protected static final String CTX_ATTR_KEY_OUTPUT_BIND_COMMENT = "__outputBindComment";
79

80
        /** 例外発生にロールバックが必要なDBでリトライを実現するために設定するSavepointの名前 */
81
        protected static final String RETRY_SAVEPOINT_NAME = "__retry_savepoint";
82

83
        /** BATCH-INSERT用のバッチフレームの判定条件 */
84
        protected static final InsertsCondition<Object> DEFAULT_BATCH_INSERTS_WHEN_CONDITION = (context, count,
1✔
85
                        row) -> count == 1000;
1✔
86

87
        /** BULK-INSERT用のバッチフレームの判定条件 */
88
        protected static final InsertsCondition<Object> DEFAULT_BULK_INSERTS_WHEN_CONDITION = (context, count,
1✔
89
                        row) -> count == 10;
1✔
90

91
        /** 一括UPDATE用のバッチフレームの判定条件 */
92
        protected static final UpdatesCondition<Object> DEFAULT_UPDATES_WHEN_CONDITION = (context, count,
1✔
93
                        row) -> count == 1000;
1✔
94

95
        /** カバレッジハンドラ */
96
        protected static AtomicReference<CoverageHandler> coverageHandlerRef = new AtomicReference<>();
1✔
97

98
        /** SQL設定管理クラス */
99
        protected SqlConfig sqlConfig;
100

101
        /** トランザクション管理機能 */
102
        protected TransactionManager transactionManager;
103

104
        /** クエリータイムアウト制限値 */
105
        protected int queryTimeout = -1;
1✔
106

107
        /** フェッチサイズ */
108
        protected int fetchSize = -1;
1✔
109

110
        /** SQL実行エラー時にリトライするエラーコードのリスト */
111
        protected List<String> sqlRetryCodes = Collections.emptyList();
1✔
112

113
        /** SQL実行エラー時の最大リトライ回数 */
114
        protected int maxRetryCount = 0;
1✔
115

116
        /** SQL実行リトライ時の待機時間(ms) */
117
        protected int retryWaitTime = 0;
1✔
118

119
        /** SQLを特定するための一意なIDに置換するためのキー */
120
        protected String keySqlId = "_SQL_ID_";
1✔
121

122
        /** Queryの結果を格納するMapのキーを生成する際に使用するCaseFormat */
123
        protected CaseFormat defaultMapKeyCaseFormat = CaseFormat.UPPER_SNAKE_CASE;
1✔
124

125
        /** デフォルトの{@link InsertsType} */
126
        protected InsertsType defaultInsertsType = InsertsType.BATCH;
1✔
127

128
        static {
129
                // SQLカバレッジ取得用のクラス名を設定する。指定がない場合、またはfalseが指定された場合はカバレッジを収集しない。
130
                // クラス名が指定されている場合はそのクラス名を指定
131
                String sqlCoverageClassName = System.getProperty(KEY_SQL_COVERAGE);
1✔
132
                if (sqlCoverageClassName == null || Boolean.FALSE.toString().equalsIgnoreCase(sqlCoverageClassName)) {
1✔
133
                        sqlCoverageClassName = null;
×
134
                } else if (Boolean.TRUE.toString().equalsIgnoreCase(sqlCoverageClassName)) {
1✔
135
                        // trueの場合は、デフォルト値を設定
136
                        sqlCoverageClassName = AbstractAgent.class.getPackage().getName() + ".coverage.CoberturaCoverageHandler";
1✔
137
                }
138

139
                CoverageHandler handler = null;
1✔
140
                if (sqlCoverageClassName != null) {
1✔
141
                        try {
142
                                handler = (CoverageHandler) Class.forName(sqlCoverageClassName, true,
1✔
143
                                                Thread.currentThread().getContextClassLoader()).newInstance();
1✔
144
                        } catch (Exception ex) {
×
145
                                LOG.warn("Failed to generate CoverageHandler class. Class:{}, Cause:{}", sqlCoverageClassName,
×
146
                                                ex.getMessage());
×
147
                        }
1✔
148
                }
149

150
                if (handler != null) {
1✔
151
                        coverageHandlerRef.set(handler);
1✔
152
                }
153
        }
1✔
154

155
        /**
156
         * コンストラクタ。
157
         *
158
         * @param sqlConfig SQL設定管理クラス
159
         * @param settings 設定情報
160
         * @param connectionContext DB接続情報
161
         */
162
        protected AbstractAgent(final SqlConfig sqlConfig, final Map<String, String> settings,
163
                        final ConnectionContext connectionContext) {
1✔
164
                this.sqlConfig = sqlConfig;
1✔
165
                this.transactionManager = new LocalTransactionManager(sqlConfig, connectionContext);
1✔
166

167
                // デフォルトプロパティ設定
168
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_FETCH_SIZE)) {
1✔
169
                        this.fetchSize = Integer.parseInt(settings.get(SqlAgentFactory.PROPS_KEY_FETCH_SIZE));
1✔
170
                }
171
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_QUERY_TIMEOUT)) {
1✔
172
                        this.queryTimeout = Integer.parseInt(settings.get(SqlAgentFactory.PROPS_KEY_QUERY_TIMEOUT));
1✔
173
                }
174
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_SQL_RETRY_CODES)) {
1✔
175
                        this.sqlRetryCodes = Collections.unmodifiableList(Arrays.asList(settings.get(
1✔
176
                                        SqlAgentFactory.PROPS_KEY_SQL_RETRY_CODES).split(",")));
1✔
177
                }
178
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_DEFAULT_MAX_RETRY_COUNT)) {
1✔
179
                        this.maxRetryCount = Integer.parseInt(settings.get(SqlAgentFactory.PROPS_KEY_DEFAULT_MAX_RETRY_COUNT));
×
180
                }
181
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_DEFAULT_SQL_RETRY_WAIT_TIME)) {
1✔
182
                        this.retryWaitTime = Integer.parseInt(settings
×
183
                                        .get(SqlAgentFactory.PROPS_KEY_DEFAULT_SQL_RETRY_WAIT_TIME));
×
184
                }
185
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_SQL_ID_KEY_NAME)) {
1✔
186
                        this.keySqlId = settings.get(SqlAgentFactory.PROPS_KEY_SQL_ID_KEY_NAME);
1✔
187
                }
188
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_DEFAULT_MAP_KEY_CASE_FORMAT)) {
1✔
189
                        this.defaultMapKeyCaseFormat = CaseFormat.valueOf(settings
1✔
190
                                        .get(SqlAgentFactory.PROPS_KEY_DEFAULT_MAP_KEY_CASE_FORMAT));
1✔
191
                }
192
                if (settings.containsKey(SqlAgentFactory.PROPS_KEY_DEFAULT_INSERTS_TYPE)) {
1✔
193
                        this.defaultInsertsType = InsertsType.valueOf(settings
×
194
                                        .get(SqlAgentFactory.PROPS_KEY_DEFAULT_INSERTS_TYPE));
×
195
                }
196
        }
1✔
197

198
        /**
199
         * {@inheritDoc}
200
         *
201
         * @see jp.co.future.uroborosql.connection.ConnectionManager#getConnection()
202
         */
203
        @Override
204
        public Connection getConnection() {
205
                return transactionManager.getConnection();
1✔
206
        }
207

208
        /**
209
         * SQLマネージャを取得します。
210
         *
211
         * @return SQLマネージャ
212
         */
213
        protected SqlManager getSqlManager() {
214
                return sqlConfig.getSqlManager();
1✔
215
        }
216

217
        /**
218
         * SqlFilter管理クラスを取得します。
219
         *
220
         * @return SqlFilter管理クラス
221
         */
222
        public SqlFilterManager getSqlFilterManager() {
223
                return sqlConfig.getSqlFilterManager();
1✔
224
        }
225

226
        /**
227
         * ORM処理クラス を取得します。
228
         *
229
         * @return ORM処理クラス
230
         */
231
        protected EntityHandler<?> getEntityHandler() {
232
                return sqlConfig.getEntityHandler();
1✔
233
        }
234

235
        /**
236
         * SqlContextの設定内容を元にSQLを構築する
237
         *
238
         * @param sqlContext SQLコンテキスト
239
         * @param isQuery queryかどうか。queryの場合<code>true</code>
240
         */
241
        protected void transformContext(final SqlContext sqlContext, final boolean isQuery) {
242
                String originalSql = sqlContext.getSql();
1✔
243
                if (StringUtils.isEmpty(originalSql) && getSqlManager() != null) {
1✔
244
                        originalSql = getSqlManager().getSql(sqlContext.getSqlName());
1✔
245
                        if (StringUtils.isEmpty(originalSql)) {
1✔
246
                                throw new UroborosqlRuntimeException("sql file:[" + sqlContext.getSqlName() + "] is not found.");
1✔
247
                        }
248
                }
249
                originalSql = getSqlFilterManager().doTransformSql(sqlContext, originalSql);
1✔
250
                sqlContext.setSql(originalSql);
1✔
251

252
                // SQL-IDの付与
253
                if (originalSql.contains(keySqlId)) {
1✔
254
                        String sqlId = sqlContext.getSqlId();
1✔
255
                        if (StringUtils.isEmpty(sqlId)) {
1✔
256
                                sqlId = sqlContext.getSqlName();
1✔
257
                        }
258
                        if (StringUtils.isEmpty(sqlId)) {
1✔
259
                                sqlId = String.valueOf(originalSql.hashCode());
×
260
                        }
261

262
                        originalSql = originalSql.replace(keySqlId, sqlId);
1✔
263
                }
264

265
                // Dialectに合わせたエスケープキャラクタの設定
266
                sqlContext.param(Dialect.PARAM_KEY_ESCAPE_CHAR, getSqlConfig().getDialect().getEscapeChar());
1✔
267

268
                // 自動パラメータバインド関数の呼出
269
                if (sqlContext.batchCount() == 0) {
1✔
270
                        if (isQuery) {
1✔
271
                                sqlContext.acceptQueryAutoParameterBinder();
1✔
272
                        } else {
273
                                sqlContext.acceptUpdateAutoParameterBinder();
1✔
274
                        }
275
                }
276

277
                if (StringUtils.isEmpty(sqlContext.getExecutableSql())) {
1✔
278
                        boolean outputBindComment = (boolean) sqlContext.contextAttrs().getOrDefault(
1✔
279
                                        CTX_ATTR_KEY_OUTPUT_BIND_COMMENT, true);
1✔
280
                        SqlParser sqlParser = new SqlParserImpl(originalSql, sqlConfig.getExpressionParser(),
1✔
281
                                        sqlConfig.getDialect().isRemoveTerminator(), outputBindComment);
1✔
282
                        ContextTransformer contextTransformer = sqlParser.parse();
1✔
283
                        contextTransformer.transform(sqlContext);
1✔
284

285
                        if (coverageHandlerRef.get() != null) {
1✔
286
                                // SQLカバレッジ用のログを出力する
287
                                CoverageData coverageData = new CoverageData(sqlContext.getSqlName(), originalSql,
1✔
288
                                                contextTransformer.getPassedRoute());
1✔
289
                                COVERAGE_LOG.trace("{}", coverageData);
1✔
290

291
                                coverageHandlerRef.get().accept(coverageData);
1✔
292
                        }
293
                }
294

295
                if (LOG.isTraceEnabled()) {
1✔
296
                        LOG.trace("Template SQL[{}{}{}]", System.lineSeparator(), originalSql, System.lineSeparator());
×
297
                }
298
                if (LOG.isDebugEnabled()) {
1✔
299
                        LOG.debug("Executed SQL[{}{}{}]", System.lineSeparator(), sqlContext.getExecutableSql(),
×
300
                                        System.lineSeparator());
×
301
                }
302
        }
1✔
303

304
        /**
305
         * フェッチサイズとクエリタイムアウトをPreparedStatementに設定する
306
         *
307
         * @param preparedStatement PreparedStatement
308
         * @throws SQLException SQL例外
309
         */
310
        protected void applyProperties(final PreparedStatement preparedStatement) throws SQLException {
311
                // フェッチサイズ指定
312
                if (getFetchSize() >= 0 && !(preparedStatement instanceof CallableStatement)) {
1✔
313
                        preparedStatement.setFetchSize(getFetchSize());
1✔
314
                }
315

316
                // クエリタイムアウト指定
317
                if (getQueryTimeout() >= 0) {
1✔
318
                        preparedStatement.setQueryTimeout(getQueryTimeout());
1✔
319
                }
320
        }
1✔
321

322
        /**
323
         * 例外発生時ハンドラー
324
         *
325
         * @param sqlContext SQLコンテキスト
326
         * @param ex SQL例外
327
         * @throws SQLException SQL例外
328
         */
329
        protected abstract void handleException(SqlContext sqlContext, SQLException ex) throws SQLException;
330

331
        /**
332
         * {@inheritDoc}
333
         *
334
         * @see jp.co.future.uroborosql.SqlAgent#close()
335
         */
336
        @Override
337
        public void close() {
338
                transactionManager.close();
1✔
339
                if (coverageHandlerRef.get() != null) {
1✔
340
                        coverageHandlerRef.get().onSqlAgentClose();
1✔
341
                }
342
        }
1✔
343

344
        /**
345
         * {@inheritDoc}
346
         *
347
         * @see jp.co.future.uroborosql.tx.TransactionManager#required(jp.co.future.uroborosql.tx.SQLRunnable)
348
         */
349
        @Override
350
        public void required(final SQLRunnable runnable) {
351
                transactionManager.required(runnable);
1✔
352
        }
1✔
353

354
        /**
355
         * {@inheritDoc}
356
         *
357
         * @see jp.co.future.uroborosql.tx.TransactionManager#required(jp.co.future.uroborosql.tx.SQLSupplier)
358
         */
359
        @Override
360
        public <R> R required(final SQLSupplier<R> supplier) {
361
                return transactionManager.required(supplier);
1✔
362
        }
363

364
        /**
365
         * {@inheritDoc}
366
         *
367
         * @see jp.co.future.uroborosql.tx.TransactionManager#requiresNew(jp.co.future.uroborosql.tx.SQLRunnable)
368
         */
369
        @Override
370
        public void requiresNew(final SQLRunnable runnable) {
371
                transactionManager.requiresNew(runnable);
1✔
372
        }
1✔
373

374
        /**
375
         * {@inheritDoc}
376
         *
377
         * @see jp.co.future.uroborosql.tx.TransactionManager#requiresNew(jp.co.future.uroborosql.tx.SQLSupplier)
378
         */
379
        @Override
380
        public <R> R requiresNew(final SQLSupplier<R> supplier) {
381
                return transactionManager.requiresNew(supplier);
1✔
382
        }
383

384
        /**
385
         * {@inheritDoc}
386
         *
387
         * @see jp.co.future.uroborosql.tx.TransactionManager#notSupported(jp.co.future.uroborosql.tx.SQLRunnable)
388
         */
389
        @Override
390
        public void notSupported(final SQLRunnable runnable) {
391
                transactionManager.notSupported(runnable);
1✔
392
        }
1✔
393

394
        /**
395
         * {@inheritDoc}
396
         *
397
         * @see jp.co.future.uroborosql.tx.TransactionManager#notSupported(jp.co.future.uroborosql.tx.SQLSupplier)
398
         */
399
        @Override
400
        public <R> R notSupported(final SQLSupplier<R> supplier) {
401
                return transactionManager.notSupported(supplier);
1✔
402
        }
403

404
        /**
405
         * {@inheritDoc}
406
         *
407
         * @see jp.co.future.uroborosql.tx.TransactionManager#setRollbackOnly()
408
         */
409
        @Override
410
        public void setRollbackOnly() {
411
                transactionManager.setRollbackOnly();
1✔
412
        }
1✔
413

414
        /**
415
         * {@inheritDoc}
416
         *
417
         * @see jp.co.future.uroborosql.tx.TransactionManager#setSavepoint(java.lang.String)
418
         */
419
        @Override
420
        public void setSavepoint(final String savepointName) {
421
                transactionManager.setSavepoint(savepointName);
1✔
422
        }
1✔
423

424
        /**
425
         * {@inheritDoc}
426
         *
427
         * @see jp.co.future.uroborosql.tx.TransactionManager#releaseSavepoint(java.lang.String)
428
         */
429
        @Override
430
        public void releaseSavepoint(final String savepointName) {
431
                transactionManager.releaseSavepoint(savepointName);
1✔
432
        }
1✔
433

434
        /**
435
         * {@inheritDoc}
436
         *
437
         * @see jp.co.future.uroborosql.tx.TransactionManager#rollback(java.lang.String)
438
         */
439
        @Override
440
        public void rollback(final String savepointName) {
441
                transactionManager.rollback(savepointName);
1✔
442
        }
1✔
443

444
        /**
445
         * {@inheritDoc}
446
         *
447
         * @see jp.co.future.uroborosql.tx.TransactionManager#savepointScope(jp.co.future.uroborosql.tx.SQLSupplier)
448
         */
449
        @Override
450
        public <R> R savepointScope(final SQLSupplier<R> supplier) {
451
                return transactionManager.savepointScope(supplier);
1✔
452
        }
453

454
        /**
455
         * {@inheritDoc}
456
         *
457
         * @see jp.co.future.uroborosql.tx.TransactionManager#savepointScope(jp.co.future.uroborosql.tx.SQLRunnable)
458
         */
459
        @Override
460
        public void savepointScope(final SQLRunnable runnable) {
461
                transactionManager.savepointScope(runnable);
1✔
462
        }
1✔
463

464
        /**
465
         * {@inheritDoc}
466
         *
467
         * @see jp.co.future.uroborosql.tx.TransactionManager#autoCommitScope(jp.co.future.uroborosql.tx.SQLSupplier)
468
         */
469
        @Override
470
        public <R> R autoCommitScope(final SQLSupplier<R> supplier) {
471
                return transactionManager.autoCommitScope(supplier);
1✔
472
        }
473

474
        /**
475
         * {@inheritDoc}
476
         *
477
         * @see jp.co.future.uroborosql.tx.TransactionManager#autoCommitScope(jp.co.future.uroborosql.tx.SQLRunnable)
478
         */
479
        @Override
480
        public void autoCommitScope(final SQLRunnable runnable) {
481
                transactionManager.autoCommitScope(runnable);
1✔
482
        }
1✔
483

484
        /**
485
         * {@inheritDoc}
486
         *
487
         * @see jp.co.future.uroborosql.SqlAgent#rollback()
488
         */
489
        @Override
490
        public void rollback() {
491
                transactionManager.rollback();
1✔
492
        }
1✔
493

494
        /**
495
         * {@inheritDoc}
496
         *
497
         * @see jp.co.future.uroborosql.SqlAgent#commit()
498
         */
499
        @Override
500
        public void commit() {
501
                transactionManager.commit();
1✔
502
        }
1✔
503

504
        /**
505
         * {@inheritDoc}
506
         *
507
         * @see jp.co.future.uroborosql.config.SqlConfigAware#getSqlConfig()
508
         */
509
        @Override
510
        public SqlConfig getSqlConfig() {
511
                return this.sqlConfig;
1✔
512
        }
513

514
        /**
515
         * {@inheritDoc}
516
         *
517
         * @see jp.co.future.uroborosql.config.SqlConfigAware#setSqlConfig(jp.co.future.uroborosql.config.SqlConfig)
518
         */
519
        @Override
520
        public void setSqlConfig(final SqlConfig config) {
521
                this.sqlConfig = config;
×
522
        }
×
523

524
        /**
525
         * {@inheritDoc}
526
         *
527
         * @see jp.co.future.uroborosql.SqlAgent#context()
528
         */
529
        @Override
530
        public SqlContext context() {
531
                return sqlConfig.context();
1✔
532
        }
533

534
        /**
535
         * {@inheritDoc}
536
         *
537
         * @see jp.co.future.uroborosql.SqlAgent#context()
538
         */
539
        @Override
540
        public SqlContext contextFrom(final String sqlName) {
541
                return sqlConfig.context().setSqlName(sqlName);
1✔
542
        }
543

544
        /**
545
         * {@inheritDoc}
546
         *
547
         * @see jp.co.future.uroborosql.SqlAgent#context()
548
         */
549
        @Override
550
        public SqlContext contextWith(final String sql) {
551
                return sqlConfig.context().setSql(sql);
1✔
552
        }
553

554
        /**
555
         * {@inheritDoc}
556
         *
557
         * @see jp.co.future.uroborosql.SqlAgent#query(java.lang.String)
558
         */
559
        @Override
560
        public SqlQuery query(final String sqlName) {
561
                return new SqlQueryImpl(this, contextFrom(sqlName));
1✔
562
        }
563

564
        /**
565
         * {@inheritDoc}
566
         *
567
         * @see jp.co.future.uroborosql.SqlAgent#queryWith(java.lang.String)
568
         */
569
        @Override
570
        public SqlQuery queryWith(final String sql) {
571
                return new SqlQueryImpl(this, contextWith(sql));
1✔
572
        }
573

574
        /**
575
         * {@inheritDoc}
576
         *
577
         * @see jp.co.future.uroborosql.SqlAgent#update(java.lang.String)
578
         */
579
        @Override
580
        public SqlUpdate update(final String sqlName) {
581
                return new SqlUpdateImpl(this, contextFrom(sqlName));
1✔
582
        }
583

584
        /**
585
         * {@inheritDoc}
586
         *
587
         * @see jp.co.future.uroborosql.SqlAgent#updateWith(java.lang.String)
588
         */
589
        @Override
590
        public SqlUpdate updateWith(final String sql) {
591
                return new SqlUpdateImpl(this, contextWith(sql));
1✔
592
        }
593

594
        /**
595
         * {@inheritDoc}
596
         *
597
         * @see jp.co.future.uroborosql.SqlAgent#updateChained(java.lang.String[])
598
         */
599
        @Override
600
        public SqlUpdate updateChained(final String... sqlNames) {
601
                if (sqlNames == null || sqlNames.length == 0) {
1✔
602
                        throw new IllegalArgumentException("sqlNames is required.");
1✔
603
                }
604
                if (sqlNames.length == 1) {
1✔
605
                        LOG.warn("If sqlNames is single, use update method instead of updateChained.");
1✔
606
                        return update(sqlNames[0]);
1✔
607
                }
608
                if (!getSqlConfig().getDialect().supportsUpdateChained()) {
1✔
NEW
609
                        throw new UroborosqlRuntimeException(
×
NEW
610
                                        getSqlConfig().getDialect().getDatabaseName() + " does not support updateChained.");
×
611
                }
612
                String sqls = Arrays.stream(sqlNames)
1✔
613
                                .map(sqlName -> {
1✔
614
                                        String sql = getSqlManager().getSql(sqlName);
1✔
615
                                        if (StringUtils.isEmpty(sql)) {
1✔
616
                                                throw new UroborosqlRuntimeException("sql file:[" + sqlName + "] is not found.");
1✔
617
                                        }
618
                                        return sql;
1✔
619
                                })
620
                                .collect(Collectors.joining(";" + System.lineSeparator()));
1✔
621

622
                String sqlName = String.join(",", sqlNames);
1✔
623

624
                return new SqlUpdateImpl(this, context().setSqlName(sqlName).setSql(sqls));
1✔
625
        }
626

627
        /**
628
         * {@inheritDoc}
629
         *
630
         * @see jp.co.future.uroborosql.SqlAgent#batch(java.lang.String)
631
         */
632
        @Override
633
        public SqlBatch batch(final String sqlName) {
634
                return new SqlBatchImpl(this, contextFrom(sqlName));
1✔
635
        }
636

637
        /**
638
         * {@inheritDoc}
639
         *
640
         * @see jp.co.future.uroborosql.SqlAgent#batchWith(java.lang.String)
641
         */
642
        @Override
643
        public SqlBatch batchWith(final String sql) {
644
                return new SqlBatchImpl(this, contextWith(sql));
1✔
645
        }
646

647
        /**
648
         * {@inheritDoc}
649
         *
650
         * @see jp.co.future.uroborosql.SqlAgent#proc(java.lang.String)
651
         */
652
        @Override
653
        public Procedure proc(final String sqlName) {
654
                return new ProcedureImpl(this, contextFrom(sqlName));
1✔
655
        }
656

657
        /**
658
         * {@inheritDoc}
659
         *
660
         * @see jp.co.future.uroborosql.SqlAgent#procWith(java.lang.String)
661
         */
662
        @Override
663
        public Procedure procWith(final String sql) {
664
                return new ProcedureImpl(this, contextWith(sql));
1✔
665
        }
666

667
        /**
668
         * {@inheritDoc}
669
         *
670
         * @see jp.co.future.uroborosql.SqlAgent#query(java.lang.Class)
671
         */
672
        @SuppressWarnings("unchecked")
673
        @Override
674
        public <E> SqlEntityQuery<E> query(final Class<? extends E> entityType) {
675
                @SuppressWarnings("rawtypes")
676
                EntityHandler handler = this.getEntityHandler();
1✔
677
                if (!handler.getEntityType().isAssignableFrom(entityType)) {
1✔
678
                        throw new IllegalArgumentException("Entity type not supported");
×
679
                }
680

681
                try {
682
                        TableMetadata metadata = handler.getMetadata(this.transactionManager, entityType);
1✔
683

684
                        SqlContext context = handler.createSelectContext(this, metadata, entityType, false);
1✔
685

686
                        return new SqlEntityQueryImpl<>(this, handler, metadata, context, entityType);
1✔
687
                } catch (SQLException e) {
×
688
                        throw new EntitySqlRuntimeException(SqlKind.SELECT, e);
×
689
                }
690
        }
691

692
        /**
693
         * {@inheritDoc}
694
         *
695
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition, jp.co.future.uroborosql.enums.InsertsType)
696
         */
697
        @Override
698
        public <E> int inserts(final Class<E> entityType, final Stream<E> entities,
699
                        final InsertsCondition<? super E> condition,
700
                        final InsertsType insertsType) {
701
                if (insertsType == InsertsType.BULK && sqlConfig.getDialect().supportsBulkInsert()) {
1✔
702
                        return bulkInsert(entityType, entities, condition, null);
1✔
703
                } else {
704
                        return batchInsert(entityType, entities, condition, null);
1✔
705
                }
706
        }
707

708
        /**
709
         * {@inheritDoc}
710
         *
711
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition)
712
         */
713
        @Override
714
        public <E> int inserts(final Class<E> entityType, final Stream<E> entities,
715
                        final InsertsCondition<? super E> condition) {
716
                return inserts(entityType, entities, condition, defaultInsertsType);
1✔
717
        }
718

719
        /**
720
         * {@inheritDoc}
721
         *
722
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.lang.Class, java.util.stream.Stream)
723
         */
724
        @Override
725
        public <E> int inserts(final Class<E> entityType, final Stream<E> entities) {
726
                return inserts(entityType, entities,
1✔
727
                                InsertsType.BATCH.equals(defaultInsertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
728
                                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION);
729
        }
730

731
        /**
732
         * {@inheritDoc}
733
         *
734
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.enums.InsertsType)
735
         */
736
        @Override
737
        public <E> int inserts(final Class<E> entityType, final Stream<E> entities, final InsertsType insertsType) {
738
                return inserts(entityType, entities,
1✔
739
                                InsertsType.BATCH.equals(insertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
740
                                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION,
741
                                insertsType);
742
        }
743

744
        /**
745
         * {@inheritDoc}
746
         *
747
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition, jp.co.future.uroborosql.enums.InsertsType)
748
         */
749
        @Override
750
        public <E> int inserts(final Stream<E> entities, final InsertsCondition<? super E> condition,
751
                        final InsertsType insertsType) {
752
                Iterator<E> iterator = entities.iterator();
1✔
753
                if (!iterator.hasNext()) {
1✔
754
                        return 0;
1✔
755
                }
756

757
                E firstEntity = iterator.next();
1✔
758

759
                Spliterator<E> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);
1✔
760
                Stream<E> otherStream = StreamSupport.stream(spliterator, false);
1✔
761
                Stream<E> stream = Stream.concat(Stream.of(firstEntity), otherStream);
1✔
762

763
                @SuppressWarnings("unchecked")
764
                Class<E> type = (Class<E>) firstEntity.getClass();
1✔
765

766
                return inserts(type, stream, condition, insertsType);
1✔
767
        }
768

769
        /**
770
         * {@inheritDoc}
771
         *
772
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition)
773
         */
774
        @Override
775
        public <E> int inserts(final Stream<E> entities, final InsertsCondition<? super E> condition) {
776
                return inserts(entities, condition, defaultInsertsType);
1✔
777
        }
778

779
        /**
780
         * {@inheritDoc}
781
         *
782
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.util.stream.Stream)
783
         */
784
        @Override
785
        public <E> int inserts(final Stream<E> entities) {
786
                return inserts(entities, InsertsType.BATCH.equals(defaultInsertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
787
                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION);
788
        }
789

790
        /**
791
         * {@inheritDoc}
792
         *
793
         * @see jp.co.future.uroborosql.SqlAgent#inserts(java.util.stream.Stream, jp.co.future.uroborosql.enums.InsertsType)
794
         */
795
        @Override
796
        public <E> int inserts(final Stream<E> entities, final InsertsType insertsType) {
797
                return inserts(entities, InsertsType.BATCH.equals(insertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
798
                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION, insertsType);
799
        }
800

801
        /**
802
         * {@inheritDoc}
803
         *
804
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition, jp.co.future.uroborosql.enums.InsertsType)
805
         */
806
        @Override
807
        public <E> Stream<E> insertsAndReturn(final Class<E> entityType, final Stream<E> entities,
808
                        final InsertsCondition<? super E> condition,
809
                        final InsertsType insertsType) {
810
                List<E> insertedEntities = new ArrayList<>();
1✔
811
                if (insertsType == InsertsType.BULK && sqlConfig.getDialect().supportsBulkInsert()) {
1✔
812
                        bulkInsert(entityType, entities, condition, insertedEntities);
1✔
813
                } else {
814
                        batchInsert(entityType, entities, condition, insertedEntities);
1✔
815
                }
816
                return insertedEntities.stream();
1✔
817
        }
818

819
        /**
820
         * {@inheritDoc}
821
         *
822
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition)
823
         */
824
        @Override
825
        public <E> Stream<E> insertsAndReturn(final Class<E> entityType, final Stream<E> entities,
826
                        final InsertsCondition<? super E> condition) {
827
                return insertsAndReturn(entityType, entities, condition, defaultInsertsType);
1✔
828
        }
829

830
        /**
831
         * {@inheritDoc}
832
         *
833
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.lang.Class, java.util.stream.Stream)
834
         */
835
        @Override
836
        public <E> Stream<E> insertsAndReturn(final Class<E> entityType, final Stream<E> entities) {
837
                return insertsAndReturn(entityType, entities,
1✔
838
                                InsertsType.BATCH.equals(defaultInsertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
839
                                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION);
840
        }
841

842
        /**
843
         * {@inheritDoc}
844
         *
845
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.enums.InsertsType)
846
         */
847
        @Override
848
        public <E> Stream<E> insertsAndReturn(final Class<E> entityType, final Stream<E> entities,
849
                        final InsertsType insertsType) {
850
                return insertsAndReturn(entityType, entities,
1✔
851
                                InsertsType.BATCH.equals(insertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
852
                                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION,
853
                                insertsType);
854
        }
855

856
        /**
857
         * {@inheritDoc}
858
         *
859
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition, jp.co.future.uroborosql.enums.InsertsType)
860
         */
861
        @Override
862
        public <E> Stream<E> insertsAndReturn(final Stream<E> entities, final InsertsCondition<? super E> condition,
863
                        final InsertsType insertsType) {
864
                Iterator<E> iterator = entities.iterator();
1✔
865
                if (!iterator.hasNext()) {
1✔
866
                        return new ArrayList<E>().stream();
1✔
867
                }
868

869
                E firstEntity = iterator.next();
1✔
870

871
                Spliterator<E> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);
1✔
872
                Stream<E> otherStream = StreamSupport.stream(spliterator, false);
1✔
873
                Stream<E> stream = Stream.concat(Stream.of(firstEntity), otherStream);
1✔
874

875
                @SuppressWarnings("unchecked")
876
                Class<E> type = (Class<E>) firstEntity.getClass();
1✔
877

878
                return insertsAndReturn(type, stream, condition, insertsType);
1✔
879
        }
880

881
        /**
882
         * {@inheritDoc}
883
         *
884
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.InsertsCondition)
885
         */
886
        @Override
887
        public <E> Stream<E> insertsAndReturn(final Stream<E> entities, final InsertsCondition<? super E> condition) {
888
                return insertsAndReturn(entities, condition, defaultInsertsType);
1✔
889
        }
890

891
        /**
892
         * {@inheritDoc}
893
         *
894
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.util.stream.Stream)
895
         */
896
        @Override
897
        public <E> Stream<E> insertsAndReturn(final Stream<E> entities) {
898
                return insertsAndReturn(entities,
1✔
899
                                InsertsType.BATCH.equals(defaultInsertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
900
                                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION);
901
        }
902

903
        /**
904
         * {@inheritDoc}
905
         *
906
         * @see jp.co.future.uroborosql.SqlAgent#insertsAndReturn(java.util.stream.Stream, jp.co.future.uroborosql.enums.InsertsType)
907
         */
908
        @Override
909
        public <E> Stream<E> insertsAndReturn(final Stream<E> entities, final InsertsType insertsType) {
910
                return insertsAndReturn(entities, InsertsType.BATCH.equals(insertsType) ? DEFAULT_BATCH_INSERTS_WHEN_CONDITION
1✔
911
                                : DEFAULT_BULK_INSERTS_WHEN_CONDITION, insertsType);
912
        }
913

914
        /**
915
         * {@inheritDoc}
916
         *
917
         * @see jp.co.future.uroborosql.SqlAgent#updates(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.UpdatesCondition)
918
         */
919
        @Override
920
        public <E> int updates(final Class<E> entityType, final Stream<E> entities,
921
                        final UpdatesCondition<? super E> condition) {
922
                return batchUpdate(entityType, entities, condition, null);
1✔
923
        }
924

925
        /**
926
         * {@inheritDoc}
927
         *
928
         * @see jp.co.future.uroborosql.SqlAgent#updatesAndReturn(java.lang.Class, java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.UpdatesCondition)
929
         */
930
        @Override
931
        public <E> Stream<E> updatesAndReturn(final Class<E> entityType, final Stream<E> entities,
932
                        final UpdatesCondition<? super E> condition) {
933
                List<E> updatedEntities = new ArrayList<>();
1✔
934
                batchUpdate(entityType, entities, condition, updatedEntities);
1✔
935
                return updatedEntities.stream();
1✔
936
        }
937

938
        /**
939
         * {@inheritDoc}
940
         *
941
         * @see jp.co.future.uroborosql.SqlAgent#updates(java.lang.Class, java.util.stream.Stream)
942
         */
943
        @Override
944
        public <E> int updates(final Class<E> entityType, final Stream<E> entities) {
945
                return updates(entityType, entities, DEFAULT_UPDATES_WHEN_CONDITION);
1✔
946
        }
947

948
        /**
949
         * {@inheritDoc}
950
         *
951
         * @see jp.co.future.uroborosql.SqlAgent#updatesAndReturn(java.lang.Class, java.util.stream.Stream)
952
         */
953
        @Override
954
        public <E> Stream<E> updatesAndReturn(final Class<E> entityType, final Stream<E> entities) {
955
                return updatesAndReturn(entityType, entities, DEFAULT_UPDATES_WHEN_CONDITION);
×
956
        }
957

958
        /**
959
         * {@inheritDoc}
960
         *
961
         * @see jp.co.future.uroborosql.SqlAgent#updates(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.UpdatesCondition)
962
         */
963
        @Override
964
        public <E> int updates(final Stream<E> entities, final UpdatesCondition<? super E> condition) {
965
                Iterator<E> iterator = entities.iterator();
1✔
966
                if (!iterator.hasNext()) {
1✔
967
                        return 0;
×
968
                }
969

970
                E firstEntity = iterator.next();
1✔
971

972
                Spliterator<E> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);
1✔
973
                Stream<E> otherStream = StreamSupport.stream(spliterator, false);
1✔
974
                Stream<E> stream = Stream.concat(Stream.of(firstEntity), otherStream);
1✔
975

976
                @SuppressWarnings("unchecked")
977
                Class<E> type = (Class<E>) firstEntity.getClass();
1✔
978

979
                return updates(type, stream, condition);
1✔
980
        }
981

982
        /**
983
         * {@inheritDoc}
984
         *
985
         * @see jp.co.future.uroborosql.SqlAgent#updatesAndReturn(java.util.stream.Stream, jp.co.future.uroborosql.SqlAgent.UpdatesCondition)
986
         */
987
        @Override
988
        public <E> Stream<E> updatesAndReturn(final Stream<E> entities, final UpdatesCondition<? super E> condition) {
989
                Iterator<E> iterator = entities.iterator();
1✔
990
                if (!iterator.hasNext()) {
1✔
991
                        return new ArrayList<E>().stream();
×
992
                }
993

994
                E firstEntity = iterator.next();
1✔
995

996
                Spliterator<E> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);
1✔
997
                Stream<E> otherStream = StreamSupport.stream(spliterator, false);
1✔
998
                Stream<E> stream = Stream.concat(Stream.of(firstEntity), otherStream);
1✔
999

1000
                @SuppressWarnings("unchecked")
1001
                Class<E> type = (Class<E>) firstEntity.getClass();
1✔
1002

1003
                return updatesAndReturn(type, stream, condition);
1✔
1004
        }
1005

1006
        /**
1007
         * {@inheritDoc}
1008
         *
1009
         * @see jp.co.future.uroborosql.SqlAgent#updates(java.util.stream.Stream)
1010
         */
1011
        @Override
1012
        public <E> int updates(final Stream<E> entities) {
1013
                return updates(entities, DEFAULT_UPDATES_WHEN_CONDITION);
1✔
1014
        }
1015

1016
        /**
1017
         * {@inheritDoc}
1018
         *
1019
         * @see jp.co.future.uroborosql.SqlAgent#updatesAndReturn(java.util.stream.Stream)
1020
         */
1021
        @Override
1022
        public <E> Stream<E> updatesAndReturn(final Stream<E> entities) {
1023
                return updatesAndReturn(entities, DEFAULT_UPDATES_WHEN_CONDITION);
1✔
1024
        }
1025

1026
        /**
1027
         * {@inheritDoc}
1028
         *
1029
         * @see jp.co.future.uroborosql.SqlAgent#getFetchSize()
1030
         */
1031
        @Override
1032
        public int getFetchSize() {
1033
                return fetchSize;
1✔
1034
        }
1035

1036
        /**
1037
         * {@inheritDoc}
1038
         *
1039
         * @see jp.co.future.uroborosql.SqlAgent#setFetchSize(int)
1040
         */
1041
        @Override
1042
        public void setFetchSize(final int fetchSize) {
1043
                this.fetchSize = fetchSize;
×
1044
        }
×
1045

1046
        /**
1047
         * {@inheritDoc}
1048
         *
1049
         * @see jp.co.future.uroborosql.SqlAgent#getQueryTimeout()
1050
         */
1051
        @Override
1052
        public int getQueryTimeout() {
1053
                return queryTimeout;
1✔
1054
        }
1055

1056
        /**
1057
         * {@inheritDoc}
1058
         *
1059
         * @see jp.co.future.uroborosql.SqlAgent#setQueryTimeout(int)
1060
         */
1061
        @Override
1062
        public void setQueryTimeout(final int queryTimeout) {
1063
                this.queryTimeout = queryTimeout;
×
1064
        }
×
1065

1066
        /**
1067
         * SQL実行をリトライするSQLエラーコードのリスト を取得します
1068
         *
1069
         * @return SQL実行をリトライするSQLエラーコードのリスト
1070
         */
1071
        public List<String> getSqlRetryCodes() {
1072
                return sqlRetryCodes;
1✔
1073
        }
1074

1075
        /**
1076
         * SQL実行をリトライするSQLエラーコードのリスト を設定します
1077
         *
1078
         * @param sqlRetryCodes SQL実行をリトライするSQLエラーコードのリスト
1079
         */
1080
        public void setSqlRetryCodes(final List<String> sqlRetryCodes) {
1081
                this.sqlRetryCodes = sqlRetryCodes;
×
1082
        }
×
1083

1084
        /**
1085
         * 最大リトライ回数 を取得します
1086
         *
1087
         * @return 最大リトライ回数
1088
         */
1089
        public int getMaxRetryCount() {
1090
                return maxRetryCount;
1✔
1091
        }
1092

1093
        /**
1094
         * 最大リトライ回数 を設定します
1095
         *
1096
         * @param maxRetryCount 最大リトライ回数
1097
         */
1098
        public void setMaxRetryCount(final int maxRetryCount) {
1099
                this.maxRetryCount = maxRetryCount;
×
1100
        }
×
1101

1102
        /**
1103
         * リトライタイムアウト時間(ms) を取得します
1104
         *
1105
         * @return リトライタイムアウト時間(ms)
1106
         */
1107
        public int getRetryWaitTime() {
1108
                return retryWaitTime;
1✔
1109
        }
1110

1111
        /**
1112
         * リトライタイムアウト時間(ms) を設定します
1113
         *
1114
         * @param retryWaitTime リトライタイムアウト時間(ms)
1115
         */
1116
        public void setRetryWaitTime(final int retryWaitTime) {
1117
                this.retryWaitTime = retryWaitTime;
×
1118
        }
×
1119

1120
        /**
1121
         * Queryの結果を格納するMapのキーを生成する際に使用するCaseFormatを取得する
1122
         *
1123
         * @return Queryの結果を格納するMapのキーを生成する際に使用するCaseFormat
1124
         */
1125
        @Override
1126
        public CaseFormat getDefaultMapKeyCaseFormat() {
1127
                return defaultMapKeyCaseFormat;
1✔
1128
        }
1129

1130
        /**
1131
         * Queryの結果を格納するMapのキーを生成する際に使用するCaseFormatを設定する。
1132
         *
1133
         * @param defaultMapKeyCaseFormat Queryの結果を格納するMapのキーを生成する際に使用するCaseFormat
1134
         */
1135
        @Override
1136
        public void setDefaultMapKeyCaseFormat(final CaseFormat defaultMapKeyCaseFormat) {
1137
                this.defaultMapKeyCaseFormat = defaultMapKeyCaseFormat;
×
1138
        }
×
1139

1140
        /**
1141
         * デフォルトの{@link InsertsType}を取得する
1142
         *
1143
         * @return insertsType
1144
         * @see jp.co.future.uroborosql.enums.InsertsType
1145
         */
1146
        @Override
1147
        public InsertsType getDefaultInsertsType() {
1148
                return defaultInsertsType;
×
1149
        }
1150

1151
        /**
1152
         * デフォルトの{@link InsertsType}を設定する
1153
         *
1154
         * @param defaultInsertsType デフォルトの{@link InsertsType}
1155
         * @see jp.co.future.uroborosql.enums.InsertsType
1156
         */
1157
        @Override
1158
        public void setDefaultInsertsType(final InsertsType defaultInsertsType) {
1159
                this.defaultInsertsType = defaultInsertsType;
1✔
1160
        }
1✔
1161

1162
        /**
1163
         * ステートメント初期化。
1164
         *
1165
         * @param sqlContext SQLコンテキスト
1166
         * @return PreparedStatement
1167
         * @throws SQLException SQL例外
1168
         */
1169
        protected PreparedStatement getPreparedStatement(final SqlContext sqlContext) throws SQLException {
1170
                PreparedStatement stmt = ((LocalTransactionManager) transactionManager).getPreparedStatement(sqlContext);
1✔
1171
                // プロパティ設定
1172
                applyProperties(stmt);
1✔
1173
                return stmt;
1✔
1174
        }
1175

1176
        /**
1177
         * Callableステートメント初期化
1178
         *
1179
         * @param sqlContext SQLコンテキスト
1180
         * @return CallableStatement
1181
         * @throws SQLException SQL例外
1182
         */
1183
        protected CallableStatement getCallableStatement(final SqlContext sqlContext) throws SQLException {
1184
                CallableStatement stmt = ((LocalTransactionManager) transactionManager).getCallableStatement(sqlContext);
1✔
1185
                // プロパティ設定
1186
                applyProperties(stmt);
1✔
1187
                return stmt;
1✔
1188
        }
1189

1190
        /**
1191
         * 複数エンティティのBULK INSERTを実行
1192
         *
1193
         * @param <E> エンティティの型
1194
         * @param entityType エンティティの型
1195
         * @param entities エンティティ
1196
         * @param condition 一括INSERT用のフレームの判定条件
1197
         * @param insertedEntities INSERTしたEntityのList. <code>null</code>の場合は格納されない
1198
         * @return SQL実行結果
1199
         */
1200
        protected abstract <E> int batchInsert(final Class<E> entityType, final Stream<E> entities,
1201
                        final InsertsCondition<? super E> condition, List<E> insertedEntities);
1202

1203
        /**
1204
         * 複数エンティティのINSERTをバッチ実行
1205
         *
1206
         * @param <E> エンティティの型
1207
         * @param entityType エンティティの型
1208
         * @param entities エンティティ
1209
         * @param condition 一括INSERT用のフレームの判定条件
1210
         * @param insertedEntities INSERTしたEntityのList. <code>null</code>の場合は格納されない
1211
         * @return SQL実行結果
1212
         */
1213
        protected abstract <E> int bulkInsert(final Class<E> entityType, final Stream<E> entities,
1214
                        final InsertsCondition<? super E> condition, List<E> insertedEntities);
1215

1216
        /**
1217
         * 複数エンティティのBULK UPDATEを実行
1218
         *
1219
         * @param <E> エンティティの型
1220
         * @param entityType エンティティの型
1221
         * @param entities エンティティ
1222
         * @param condition 一括更新用のフレームの判定条件
1223
         * @param updatedEntities INSERTしたEntityのList. <code>null</code>の場合は格納されない
1224
         * @return SQL実行結果
1225
         */
1226
        protected abstract <E> int batchUpdate(final Class<E> entityType, final Stream<E> entities,
1227
                        final UpdatesCondition<? super E> condition, List<E> updatedEntities);
1228

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