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

torand / FasterSQL / 13389227868

18 Feb 2025 11:10AM UTC coverage: 59.667% (+0.9%) from 58.785%
13389227868

push

github

torand
test: H2 specific testing of select and insert clauses

157 of 346 branches covered (45.38%)

Branch coverage included in aggregate %.

846 of 1335 relevant lines covered (63.37%)

3.35 hits per line

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

58.33
/src/main/java/io/github/torand/fastersql/dialect/Dialect.java
1
/*
2
 * Copyright (c) 2024 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.dialect;
17

18
import java.sql.Connection;
19
import java.sql.SQLException;
20
import java.util.List;
21
import java.util.Optional;
22

23
public interface Dialect {
24
    /**
25
     * Gets the name of the RDBMS product.
26
     * @return the name of the RDBMS product.
27
     */
28
    String getProductName();
29

30
    /**
31
     * Indicates whether offset clause must be specified before limit clause; if supported.
32
     * @return whether offset clause must be specified before limit clause; if supported.
33
     */
34
    boolean offsetBeforeLimit();
35
    /**
36
     * Returns the _row offset clause_ formatted for a specific SQL dialect.
37
     * @return the _row offset clause_ formatted for a specific SQL dialect.
38
     */
39
    Optional<String> formatRowOffsetClause();
40

41
    /**
42
     * Returns the _row limit clause_ formatted for a specific SQL dialect.
43
     * @return the _row limit clause_ formatted for a specific SQL dialect.
44
     */
45
    Optional<String> formatRowLimitClause();
46

47
    /**
48
     * Returns the _row number_ literal formatted for a specific SQL dialect.
49
     * @return the _row number_ literal formatted for a specific SQL dialect.
50
     */
51
    Optional<String> formatRowNumLiteral();
52

53
    /**
54
     * Returns the 'to_number' function formatted for a specific SQL dialect.
55
     * @param operand the string expression to be evaluated as a number
56
     * @param precision the precision that represents the number of significant digits
57
     * @param scale the scale that that represents the number of digits after the decimal point. Must be less than or equal to the precision.
58
     * @return the 'to_number' function for a specific SQL dialect.
59
     */
60
    String formatToNumberFunction(String operand, int precision, int scale);
61

62
    /**
63
     * Returns the 'substring' function formatted for a specific SQL dialect.
64
     * @param operand the string expression to get substring from
65
     * @param startPos the start position (1-based) of the substring
66
     * @param length the length of the substring
67
     * @return the 'substring' function for a specific SQL dialect.
68
     */
69
    String formatSubstringFunction(String operand, int startPos, int length);
70

71
    /**
72
     * Returns the 'concat' function formatted for a specific SQL dialect.
73
     * @param operands the string expressions to concatenate
74
     * @return the 'concat' function for a specific SQL dialect.
75
     */
76
    String formatConcatFunction(List<String> operands);
77

78
    /**
79
     * Returns the 'length' function formatted for a specific SQL dialect.
80
     * @param operand the string expression to get length of
81
     * @return the 'length' function for a specific SQL dialect.
82
     */
83
    String formatLengthFunction(String operand);
84

85
    /**
86
     * Indicates whether a capability is supported by a specific SQL dialect.
87
     * @param capability the capability to check support for
88
     * @return true if specified capability is supported; else false
89
     */
90
    boolean supports(Capability capability);
91

92
    static Dialect fromConnection(Connection connection) {
93
        try {
94
            String productName = connection.getMetaData().getDatabaseProductName().toLowerCase();
5✔
95

96
            if (productName.contains("h2")) {
4✔
97
                return new H2Dialect();
4✔
98
            } else if (productName.contains("mysql")) {
4!
99
                return new MySqlDialect();
×
100
            } else if (productName.contains("mariadb")) {
4!
101
                return new MariaDbDialect();
×
102
            } else if (productName.contains("postgresql")) {
4!
103
                return new PostgreSqlDialect();
×
104
            } else if (productName.contains("oracle")) {
4!
105
                return new OracleDialect();
4✔
106
            } else {
107
                throw new UnsupportedOperationException("Database with product name " + productName + " not supported");
×
108
            }
109
        } catch (SQLException e) {
×
110
            throw new RuntimeException("Failed to detect SQL dialect from connection metadata", e);
×
111
        }
112
    }
113
}
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