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

future-architect / uroborosql / #784

24 Sep 2024 09:27AM UTC coverage: 90.525% (+0.02%) from 90.502%
#784

push

web-flow
Add Dialect (#334)

- Oracle12
- Oracle18
- Oracle19
- Oracle21
- Oracle23
- MariaDB5
- MariaDB10

43 of 46 new or added lines in 8 files covered. (93.48%)

8723 of 9636 relevant lines covered (90.53%)

0.91 hits per line

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

87.5
/src/main/java/jp/co/future/uroborosql/dialect/MariaDbDialect.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.dialect;
8

9
import java.util.List;
10
import java.util.Set;
11
import java.util.stream.Collectors;
12

13
import jp.co.future.uroborosql.connection.ConnectionSupplier;
14
import jp.co.future.uroborosql.exception.UroborosqlRuntimeException;
15

16
/**
17
 * MariaDB用のデフォルト設定用Dialect
18
 *
19
 * @author H.Sugimoto
20
 */
21
public abstract class MariaDbDialect extends AbstractDialect {
22
        /**
23
         * 悲観ロックのErrorCode もしくは SqlState. MySQLの場合はErrorCodeで判定する.
24
         * <pre>ERROR 3572 (HY000): Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.</pre>
25
         */
26
        private static final Set<String> pessimisticLockingErrorCodes = Set.of("3572");
1✔
27

28
        /**
29
         * コンストラクタ
30
         */
31
        protected MariaDbDialect() {
1✔
32
        }
1✔
33

34
        /**
35
         * {@inheritDoc}
36
         *
37
         * @see jp.co.future.uroborosql.dialect.Dialect#accept(jp.co.future.uroborosql.connection.ConnectionSupplier)
38
         */
39
        @Override
40
        public boolean accept(final ConnectionSupplier supplier) {
41
                if (supplier == null) {
1✔
NEW
42
                        return false;
×
43
                }
44

45
                var parts = supplier.getDatabaseName().split("-", 2);
1✔
46
                var databaseName = parts[0];
1✔
47

48
                if (!databaseName.startsWith(getDatabaseName())) {
1✔
49
                        return false;
1✔
50
                }
51

52
                var databaseVersion = parts[1];
1✔
53

54
                try {
55
                        var majorVersion = Integer.parseInt(databaseVersion.substring(0, databaseVersion.indexOf(".")));
1✔
56
                        return isTargetVersion(majorVersion);
1✔
NEW
57
                } catch (NumberFormatException ex) {
×
NEW
58
                        return false;
×
59
                }
60
        }
61

62
        /**
63
         * 対象のMariaDBバージョンかどうかを判定する
64
         *
65
         * @param majorVersion コネクションから取得したメジャーバージョン
66
         * @return 対象のバージョンの場合<code>true</code>
67
         */
68
        protected abstract boolean isTargetVersion(int majorVersion);
69

70
        /**
71
         * {@inheritDoc}
72
         *
73
         * @see jp.co.future.uroborosql.dialect.Dialect#getDatabaseName()
74
         */
75
        @Override
76
        public String getDatabaseName() {
77
                return "MariaDB";
1✔
78
        }
79

80
        /**
81
         * {@inheritDoc}
82
         *
83
         * @see jp.co.future.uroborosql.dialect.Dialect#supportsBulkInsert()
84
         */
85
        @Override
86
        public boolean supportsBulkInsert() {
87
                return true;
1✔
88
        }
89

90
        /**
91
         * {@inheritDoc}
92
         *
93
         * @see jp.co.future.uroborosql.dialect.Dialect#supportsLimitClause()
94
         */
95
        @Override
96
        public boolean supportsLimitClause() {
97
                return true;
1✔
98
        }
99

100
        /**
101
         * {@inheritDoc}
102
         *
103
         * @see jp.co.future.uroborosql.dialect.Dialect#supportsSequence()
104
         */
105
        @Override
106
        public boolean supportsSequence() {
107
                return false;
1✔
108
        }
109

110
        /**
111
         * {@inheritDoc}
112
         *
113
         * @see jp.co.future.uroborosql.dialect.Dialect#supportsForUpdateWait()
114
         */
115
        @Override
116
        public boolean supportsForUpdateWait() {
117
                return false;
1✔
118
        }
119

120
        /**
121
         * {@inheritDoc}
122
         *
123
         * @see jp.co.future.uroborosql.dialect.Dialect#supportsOptimizerHints()
124
         */
125
        @Override
126
        public boolean supportsOptimizerHints() {
127
                return true;
1✔
128
        }
129

130
        /**
131
         * {@inheritDoc}
132
         *
133
         * @see jp.co.future.uroborosql.dialect.Dialect#getSequenceNextValSql(java.lang.String)
134
         */
135
        @Override
136
        public String getSequenceNextValSql(final String sequenceName) {
137
                throw new UroborosqlRuntimeException("MariaDB does not support Sequence.");
1✔
138
        }
139

140
        /**
141
         * {@inheritDoc}
142
         *
143
         * @see jp.co.future.uroborosql.dialect.Dialect#addOptimizerHints(java.lang.StringBuilder, java.util.List)
144
         */
145
        @Override
146
        public StringBuilder addOptimizerHints(final StringBuilder sql, final List<String> hints) {
147
                var hintStr = "$1 " + hints.stream().collect(Collectors.joining(" ")) + System.lineSeparator();
1✔
148
                return new StringBuilder(sql.toString().replaceFirst("((FROM|from)\\s+[^\\s]+)\\s*", hintStr));
1✔
149
        }
150

151
        /**
152
         * {@inheritDoc}
153
         *
154
         * @see jp.co.future.uroborosql.dialect.Dialect#getPessimisticLockingErrorCodes()
155
         */
156
        @Override
157
        public Set<String> getPessimisticLockingErrorCodes() {
158
                return pessimisticLockingErrorCodes;
1✔
159
        }
160

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