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

future-architect / uroborosql / #890

17 Aug 2025 03:45PM UTC coverage: 88.613% (+0.1%) from 88.472%
#890

Pull #364

HidekiSugimoto189
fix javadoc comment
Pull Request #364: Add ConnectionSupplier Fix schema name option.

128 of 140 new or added lines in 5 files covered. (91.43%)

6 existing lines in 3 files now uncovered.

8202 of 9256 relevant lines covered (88.61%)

0.89 hits per line

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

94.0
/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 url JDBC URL(必須)
31
         * @param user 接続ユーザ名
32
         * @param password 接続パスワード
33
         */
34
        @Deprecated
35
        public JdbcConnectionSupplierImpl(final String url, final String user, final String password) {
36
                this(ConnectionContextBuilder.jdbc(url, user, password));
1✔
37
        }
1✔
38

39
        /**
40
         * コンストラクタ
41
         *
42
         * @param url JDBC URL(必須)
43
         * @param user 接続ユーザ名
44
         * @param password 接続パスワード
45
         * @param schema JDBCスキーマ名
46
         */
47
        @Deprecated
48
        public JdbcConnectionSupplierImpl(final String url, final String user, final String password, final String schema) {
49
                this(ConnectionContextBuilder.jdbc(url, user, password, schema));
1✔
50
        }
1✔
51

52
        /**
53
         * コンストラクタ
54
         *
55
         * @param url JDBC URL(必須)
56
         * @param user 接続ユーザ名
57
         * @param password 接続パスワード
58
         * @param schema JDBCスキーマ名
59
         * @param autoCommit 自動コミットするかどうか
60
         * @param readOnly 参照のみかどうか
61
         */
62
        @Deprecated
63
        public JdbcConnectionSupplierImpl(final String url, final String user, final String password, final String schema,
64
                        final boolean autoCommit, final boolean readOnly) {
65
                this(ConnectionContextBuilder.jdbc(url, user, password, schema).autoCommit(autoCommit)
1✔
66
                                .readOnly(readOnly));
1✔
67
        }
1✔
68

69
        /**
70
         * コンストラクタ
71
         *
72
         * @param connectionContext DB接続情報
73
         */
74
        public JdbcConnectionSupplierImpl(final JdbcConnectionContext connectionContext) {
1✔
75
                this.defaultConnectionContext = connectionContext;
1✔
76
        }
1✔
77

78
        /**
79
         * {@inheritDoc}
80
         *
81
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection()
82
         */
83
        @Override
84
        public Connection getConnection() {
85
                return getConnection(defaultConnectionContext);
1✔
86
        }
87

88
        /**
89
         * {@inheritDoc}
90
         *
91
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection(jp.co.future.uroborosql.connection.ConnectionContext)
92
         */
93
        @Override
94
        public Connection getConnection(final ConnectionContext ctx) {
95
                if (!(ctx instanceof JdbcConnectionContext)) {
1✔
96
                        throw new IllegalArgumentException("ctx must be of type JdbcConnectionContext.");
1✔
97
                }
98
                JdbcConnectionContext jdbcCtx = (JdbcConnectionContext) ctx;
1✔
99
                try {
100
                        Connection original = DriverManager.getConnection(jdbcCtx.url(), jdbcCtx.toProperties());
1✔
101
                        Connection connection;
102
                        if (jdbcCtx.fixSchema()) {
1✔
103
                                String schemaName = jdbcCtx.fixedSchemaName();
1✔
104
                                if (schemaName == null) {
1✔
105
                                        schemaName = original.getSchema();
1✔
106
                                        jdbcCtx.fixedSchemaName(schemaName);
1✔
107
                                }
108
                                connection = new SchemaFixedConnectionWrapper(original, schemaName);
1✔
109
                        } else {
1✔
110
                                connection = new MetadataCachedConnectionWrapper(original, jdbcCtx.cacheSchema());
1✔
111
                                String schema = jdbcCtx.schema();
1✔
112
                                if (schema != null && !Objects.equals(connection.getSchema(), schema)) {
1✔
NEW
113
                                        connection.setSchema(schema);
×
114
                                }
115
                        }
116
                        if (jdbcCtx.autoCommit() != connection.getAutoCommit()) {
1✔
117
                                connection.setAutoCommit(jdbcCtx.autoCommit());
1✔
118
                        }
119
                        if (jdbcCtx.readOnly() != connection.isReadOnly()) {
1✔
120
                                connection.setReadOnly(jdbcCtx.readOnly());
1✔
121
                        }
122
                        int transactionIsolation = jdbcCtx.transactionIsolation();
1✔
123
                        if (transactionIsolation > 0 && transactionIsolation != connection.getTransactionIsolation()) {
1✔
124
                                connection.setTransactionIsolation(transactionIsolation);
1✔
125
                        }
126
                        return connection;
1✔
UNCOV
127
                } catch (SQLException ex) {
×
UNCOV
128
                        throw new UroborosqlSQLException("Connection[" + jdbcCtx.url() + "] can not be acquired.", ex);
×
129
                }
130
        }
131

132
        /**
133
         * JDBCスキーマ名を設定
134
         *
135
         * @param schema スキーマ名
136
         */
137
        @Deprecated
138
        public void setSchema(final String schema) {
139
                setDefaultSchema(schema);
1✔
140
        }
1✔
141

142
        /**
143
         * デフォルトのDB接続情報にJDBCスキーマ名を設定
144
         *
145
         * @param schema スキーマ名
146
         */
147
        public void setDefaultSchema(final String schema) {
148
                defaultConnectionContext.schema(schema);
1✔
149
        }
1✔
150

151
        /**
152
         * デフォルトのDB接続情報にAutoCommitオプションの指定
153
         *
154
         * @param autoCommit AutoCommitを行う場合は<code>true</code>
155
         */
156
        public void setDefaultAutoCommit(final boolean autoCommit) {
157
                defaultConnectionContext.autoCommit(autoCommit);
1✔
158
        }
1✔
159

160
        /**
161
         * デフォルトのDB接続情報にReadOnlyオプションを指定
162
         *
163
         * @param readOnly readOnlyを指定する場合は<code>true</code>
164
         */
165
        public void setDefaultReadOnly(final boolean readOnly) {
166
                defaultConnectionContext.readOnly(readOnly);
1✔
167
        }
1✔
168

169
        /**
170
         * デフォルトのDB接続情報にtransactionIsolationオプションを指定
171
         *
172
         * @see Connection#TRANSACTION_READ_UNCOMMITTED
173
         * @see Connection#TRANSACTION_READ_COMMITTED
174
         * @see Connection#TRANSACTION_REPEATABLE_READ
175
         * @see Connection#TRANSACTION_SERIALIZABLE
176
         *
177
         * @param transactionIsolation transactionIsolationオプション
178
         */
179
        public void setDefaultTransactionIsolation(final int transactionIsolation) {
180
                defaultConnectionContext.transactionIsolation(transactionIsolation);
1✔
181
        }
1✔
182

183
        /**
184
         * デフォルトのDB接続情報にスキーマ名のキャッシュオプションを指定
185
         *
186
         * @param cache スキーマ名をキャッシュする場合は<code>true</code>
187
         */
188
        public void setDefaultCacheSchema(final boolean cache) {
189
                defaultConnectionContext.cacheSchema(cache);
1✔
190
        }
1✔
191

192
        /**
193
         * デフォルトのDB接続情報にスキーマ名の固定オプションを指定
194
         *
195
         * @param fixed スキーマ名を固定する場合は<code>true</code>
196
         */
197
        public void setDefaultFixSchema(final boolean fixed) {
198
                defaultConnectionContext.fixSchema(fixed);
1✔
199
        }
1✔
200
}
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