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

future-architect / uroborosql / #872

04 Aug 2025 02:28PM UTC coverage: 88.472% (-1.7%) from 90.172%
#872

push

web-flow
cache DatabaseMetaData fixed value and Connection getSchema value. (#360)

* cache DatabaseMetaData fixed value and Connection getSchema value.

* add setCacheSchema API for ConnectionSupplier.

* add Connection#toString()

* fix review comment.

144 of 329 new or added lines in 8 files covered. (43.77%)

2 existing lines in 1 file now uncovered.

8074 of 9126 relevant lines covered (88.47%)

0.88 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

693
        /**
694
         * {@inheritDoc}
695
         *
696
         * @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)
697
         */
698
        @Override
699
        public <E> int inserts(final Class<E> entityType, final Stream<E> entities,
700
                        final InsertsCondition<? super E> condition,
701
                        final InsertsType insertsType) {
702
                if (insertsType == InsertsType.BULK && sqlConfig.getDialect().supportsBulkInsert()) {
1✔
703
                        return bulkInsert(entityType, entities, condition, null);
1✔
704
                } else {
705
                        return batchInsert(entityType, entities, condition, null);
1✔
706
                }
707
        }
708

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

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

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

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

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

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

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

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

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

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

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

802
        /**
803
         * {@inheritDoc}
804
         *
805
         * @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)
806
         */
807
        @Override
808
        public <E> Stream<E> insertsAndReturn(final Class<E> entityType, final Stream<E> entities,
809
                        final InsertsCondition<? super E> condition,
810
                        final InsertsType insertsType) {
811
                List<E> insertedEntities = new ArrayList<>();
1✔
812
                if (insertsType == InsertsType.BULK && sqlConfig.getDialect().supportsBulkInsert()) {
1✔
813
                        bulkInsert(entityType, entities, condition, insertedEntities);
1✔
814
                } else {
815
                        batchInsert(entityType, entities, condition, insertedEntities);
1✔
816
                }
817
                return insertedEntities.stream();
1✔
818
        }
819

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1163
        /**
1164
         *
1165
         * {@inheritDoc}
1166
         *
1167
         * @see jp.co.future.uroborosql.SqlAgent#setCacheSchema(boolean)
1168
         */
1169
        @Override
1170
        public void setCacheSchema(final boolean cache) throws SQLException {
NEW
1171
                Connection conn = getConnection();
×
NEW
1172
                if (conn.isWrapperFor(MetadataCachedConnectionWrapper.class)) {
×
NEW
1173
                        ((MetadataCachedConnectionWrapper) conn).setCacheSchema(cache);
×
1174
                } else {
NEW
1175
                        throw new SQLException("Cannot set cacheSchema option.");
×
1176
                }
NEW
1177
        }
×
1178

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

1193
        /**
1194
         * Callableステートメント初期化
1195
         *
1196
         * @param sqlContext SQLコンテキスト
1197
         * @return CallableStatement
1198
         * @throws SQLException SQL例外
1199
         */
1200
        protected CallableStatement getCallableStatement(final SqlContext sqlContext) throws SQLException {
1201
                CallableStatement stmt = ((LocalTransactionManager) transactionManager).getCallableStatement(sqlContext);
1✔
1202
                // プロパティ設定
1203
                applyProperties(stmt);
1✔
1204
                return stmt;
1✔
1205
        }
1206

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

1220
        /**
1221
         * 複数エンティティのINSERTをバッチ実行
1222
         *
1223
         * @param <E> エンティティの型
1224
         * @param entityType エンティティの型
1225
         * @param entities エンティティ
1226
         * @param condition 一括INSERT用のフレームの判定条件
1227
         * @param insertedEntities INSERTしたEntityのList. <code>null</code>の場合は格納されない
1228
         * @return SQL実行結果
1229
         */
1230
        protected abstract <E> int bulkInsert(final Class<E> entityType, final Stream<E> entities,
1231
                        final InsertsCondition<? super E> condition, List<E> insertedEntities);
1232

1233
        /**
1234
         * 複数エンティティのBULK UPDATEを実行
1235
         *
1236
         * @param <E> エンティティの型
1237
         * @param entityType エンティティの型
1238
         * @param entities エンティティ
1239
         * @param condition 一括更新用のフレームの判定条件
1240
         * @param updatedEntities INSERTしたEntityのList. <code>null</code>の場合は格納されない
1241
         * @return SQL実行結果
1242
         */
1243
        protected abstract <E> int batchUpdate(final Class<E> entityType, final Stream<E> entities,
1244
                        final UpdatesCondition<? super E> condition, List<E> updatedEntities);
1245

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