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

future-architect / uroborosql / #892

17 Aug 2025 05:09PM UTC coverage: 87.81% (-0.5%) from 88.265%
#892

Pull #365

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

77 of 146 new or added lines in 5 files covered. (52.74%)

1 existing line in 1 file now uncovered.

8911 of 10148 relevant lines covered (87.81%)

0.88 hits per line

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

65.38
/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
         */
24
        public enum SchemaOption {
1✔
25
                /** キャッシュしない */
26
                NONE,
1✔
27
                /** キャッシュする */
28
                CACHE,
1✔
29
                /** 固定する */
30
                FIX
1✔
31
        }
32

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

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

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

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

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

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

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