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

future-architect / uroborosql / #893

17 Aug 2025 05:16PM UTC coverage: 88.615% (+0.1%) from 88.472%
#893

Pull #364

HidekiSugimoto189
add null guard
Pull Request #364: Add ConnectionSupplier Fix schema name option.

130 of 142 new or added lines in 5 files covered. (91.55%)

2 existing lines in 1 file now uncovered.

8204 of 9258 relevant lines covered (88.62%)

0.89 hits per line

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

80.77
/src/main/java/jp/co/future/uroborosql/connection/DefaultConnectionSupplierImpl.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.SQLException;
11

12
/**
13
 * デフォルトコネクション供給クラス<br>
14
 * コネクションを保持して返すだけの実装。<br>
15
 * 保持しているコネクションはクローズされないようWrapper経由で提供される。<br>
16
 *
17
 * @author H.Sugimoto
18
 */
19
public class DefaultConnectionSupplierImpl implements ConnectionSupplier {
20
        /**
21
         * コネクションのスキーマ名の取り扱いを指定するオプション
22
         */
23
        public enum SchemaOption {
1✔
24
                /** キャッシュしない */
25
                NONE,
1✔
26
                /** キャッシュする */
27
                CACHE,
1✔
28
                /** 固定する */
29
                FIX
1✔
30
        }
31

32
        /**  コネクション */
33
        private final Connection connection;
34

35
        /** スキーマ名を固定する場合のスキーマ名 */
36
        private String fixedSchemaName = null;
1✔
37

38
        /**
39
         * コンストラクタ.
40
         *
41
         * @param connection コネクション
42
         */
43
        public DefaultConnectionSupplierImpl(final Connection connection) {
44
                this(connection, SchemaOption.NONE);
1✔
45
        }
1✔
46

47
        /**
48
         * コンストラクタ.
49
         *
50
         * @param connection コネクション
51
         * @param schemaOption コネクションのスキーマ名の取り扱いを指定するオプション
52
         */
53
        public DefaultConnectionSupplierImpl(final Connection connection, final SchemaOption schemaOption) {
1✔
54
                if (schemaOption == SchemaOption.FIX) {
1✔
55
                        if (fixedSchemaName == null) {
1✔
56
                                try {
57
                                        fixedSchemaName = connection.getSchema();
1✔
NEW
58
                                } catch (SQLException ex) {
×
NEW
59
                                        throw new UnsupportedOperationException(ex);
×
60
                                }
1✔
61
                        }
62
                        this.connection = new SchemaFixedConnectionWrapper(new CloseIgnoringConnectionWrapper(connection),
1✔
63
                                        fixedSchemaName);
64
                } else {
65
                        this.connection = new MetadataCachedConnectionWrapper(new CloseIgnoringConnectionWrapper(connection),
1✔
66
                                        schemaOption == SchemaOption.CACHE);
67
                }
68
        }
1✔
69

70
        /**
71
         * {@inheritDoc}
72
         *
73
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection()
74
         */
75
        @Override
76
        public Connection getConnection() {
77
                return connection;
1✔
78
        }
79

80
        /**
81
         * {@inheritDoc}
82
         *
83
         * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection(jp.co.future.uroborosql.connection.ConnectionContext)
84
         */
85
        @Override
86
        public Connection getConnection(final ConnectionContext ctx) {
87
                throw new UnsupportedOperationException();
1✔
88
        }
89

90
        /**
91
         * 保持しているConnectionにスキーマ名のキャッシュオプションを指定
92
         *
93
         * @param cache スキーマ名をキャッシュする場合は<code>true</code>
94
         */
95
        public void setCacheSchema(final boolean cache) {
96
                try {
97
                        if (connection.isWrapperFor(MetadataCachedConnectionWrapper.class)) {
1✔
98
                                connection.unwrap(MetadataCachedConnectionWrapper.class).setCacheSchema(cache);
1✔
99
                        } else {
NEW
100
                                throw new UnsupportedOperationException("Schema is fixed.");
×
101
                        }
NEW
102
                } catch (SQLException ex) {
×
NEW
103
                        throw new IllegalStateException(ex);
×
104
                }
1✔
105
        }
1✔
106

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