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

future-architect / uroborosql / #891

17 Aug 2025 04:56PM UTC coverage: 87.808% (-0.5%) from 88.265%
#891

Pull #365

HidekiSugimoto189
Add ConnectionSupplier Fix schema name option for master.
Pull Request #365: Add ConnectionSupplier Fix schema name option for master.

75 of 144 new or added lines in 5 files covered. (52.08%)

1 existing line in 1 file now uncovered.

8909 of 10146 relevant lines covered (87.81%)

0.88 hits per line

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

92.68
/src/main/java/jp/co/future/uroborosql/connection/JdbcConnectionSupplierImpl.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.connection;
8

9
import java.sql.Connection;
10
import java.sql.DriverManager;
11
import java.sql.SQLException;
12
import java.util.Objects;
13

14
import jp.co.future.uroborosql.exception.UroborosqlSQLException;
15

16
/**
17
 * JDBCドライバーを使用したコネクション供給クラス<br>
18
 * 指定されたプロパティをもとにコネクションを都度生成する
19
 *
20
 * @author H.Sugimoto
21
 */
22
public class JdbcConnectionSupplierImpl implements ConnectionSupplier {
23

24
        /** デフォルトDB接続情報 */
25
        private final JdbcConnectionContext defaultConnectionContext;
26

27
        /**
28
         * コンストラクタ
29
         *
30
         * @param connectionContext DB接続情報
31
         */
32
        public JdbcConnectionSupplierImpl(final JdbcConnectionContext connectionContext) {
1✔
33
                this.defaultConnectionContext = connectionContext;
1✔
34
        }
1✔
35

36
        /**
37
         * {@inheritDoc}
38
         *
39
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection()
40
         */
41
        @Override
42
        public Connection getConnection() {
43
                return getConnection(defaultConnectionContext);
1✔
44
        }
45

46
        /**
47
         * {@inheritDoc}
48
         *
49
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection(jp.co.future.uroborosql.connection.ConnectionContext)
50
         */
51
        @Override
52
        public Connection getConnection(final ConnectionContext ctx) {
53
                if (!(ctx instanceof JdbcConnectionContext)) {
1✔
54
                        throw new IllegalArgumentException("ctx must be of type JdbcConnectionContext.");
1✔
55
                }
56
                var jdbcCtx = (JdbcConnectionContext) ctx;
1✔
57
                try {
58
                        var original = DriverManager.getConnection(jdbcCtx.url(), jdbcCtx.toProperties());
1✔
59
                        Connection connection;
60
                        if (jdbcCtx.fixSchema()) {
1✔
61
                                var schemaName = jdbcCtx.fixedSchemaName();
1✔
62
                                if (schemaName == null) {
1✔
63
                                        schemaName = original.getSchema();
1✔
64
                                        jdbcCtx.fixedSchemaName(schemaName);
1✔
65
                                }
66
                                connection = new SchemaFixedConnectionWrapper(original, schemaName);
1✔
67
                        } else {
1✔
68
                                connection = new MetadataCachedConnectionWrapper(original, jdbcCtx.cacheSchema());
1✔
69
                                var schema = jdbcCtx.schema();
1✔
70
                                if (schema != null && !Objects.equals(connection.getSchema(), schema)) {
1✔
NEW
71
                                        connection.setSchema(schema);
×
72
                                }
73
                        }
74

75
                        if (jdbcCtx.autoCommit() != connection.getAutoCommit()) {
1✔
76
                                connection.setAutoCommit(jdbcCtx.autoCommit());
1✔
77
                        }
78
                        if (jdbcCtx.readOnly() != connection.isReadOnly()) {
1✔
79
                                connection.setReadOnly(jdbcCtx.readOnly());
1✔
80
                        }
81
                        var transactionIsolation = jdbcCtx.transactionIsolation();
1✔
82
                        if (transactionIsolation > 0 && transactionIsolation != connection.getTransactionIsolation()) {
1✔
83
                                connection.setTransactionIsolation(transactionIsolation);
1✔
84
                        }
85
                        return connection;
1✔
86
                } catch (SQLException ex) {
×
87
                        throw new UroborosqlSQLException("Connection[" + jdbcCtx.url() + "] can not be acquired.", ex);
×
88
                }
89
        }
90

91
        /**
92
         * デフォルトのDB接続情報にJDBCスキーマ名を設定
93
         *
94
         * @param schema スキーマ名
95
         */
96
        public void setDefaultSchema(final String schema) {
97
                defaultConnectionContext.schema(schema);
1✔
98
        }
1✔
99

100
        /**
101
         * デフォルトのDB接続情報にAutoCommitオプションの指定
102
         *
103
         * @param autoCommit AutoCommitを行う場合は<code>true</code>
104
         */
105
        public void setDefaultAutoCommit(final boolean autoCommit) {
106
                defaultConnectionContext.autoCommit(autoCommit);
1✔
107
        }
1✔
108

109
        /**
110
         * デフォルトのDB接続情報にReadOnlyオプションを指定
111
         *
112
         * @param readOnly readOnlyを指定する場合は<code>true</code>
113
         */
114
        public void setDefaultReadOnly(final boolean readOnly) {
115
                defaultConnectionContext.readOnly(readOnly);
1✔
116
        }
1✔
117

118
        /**
119
         * デフォルトのDB接続情報にtransactionIsolationオプションを指定
120
         *
121
         * @see Connection#TRANSACTION_READ_UNCOMMITTED
122
         * @see Connection#TRANSACTION_READ_COMMITTED
123
         * @see Connection#TRANSACTION_REPEATABLE_READ
124
         * @see Connection#TRANSACTION_SERIALIZABLE
125
         *
126
         * @param transactionIsolation transactionIsolationオプション
127
         */
128
        public void setDefaultTransactionIsolation(final int transactionIsolation) {
129
                defaultConnectionContext.transactionIsolation(transactionIsolation);
1✔
130
        }
1✔
131

132
        /**
133
         * デフォルトのDB接続情報にスキーマ名のキャッシュオプションを指定
134
         *
135
         * @param cache スキーマ名をキャッシュする場合は<code>true</code>
136
         */
137
        public void setDefaultCacheSchema(final boolean cache) {
138
                defaultConnectionContext.cacheSchema(cache);
1✔
139
        }
1✔
140

141
        /**
142
         * デフォルトのDB接続情報にスキーマ名の固定オプションを指定
143
         *
144
         * @param fixed スキーマ名を固定する場合は<code>true</code>
145
         */
146
        public void setDefaultFixSchema(final boolean fixed) {
147
                defaultConnectionContext.fixSchema(fixed);
1✔
148
        }
1✔
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc