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

torand / FasterSQL / 15346133148

30 May 2025 11:50AM UTC coverage: 70.397% (+0.1%) from 70.298%
15346133148

push

github

torand
chore: test javadoc publish

235 of 420 branches covered (55.95%)

Branch coverage included in aggregate %.

1237 of 1671 relevant lines covered (74.03%)

3.9 hits per line

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

87.88
/src/main/java/io/github/torand/fastersql/dialect/OracleDialect.java
1
/*
2
 * Copyright (c) 2024-2025 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.util.EnumSet;
19
import java.util.List;
20
import java.util.Optional;
21

22
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
23
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
24
import static io.github.torand.fastersql.dialect.Capability.NULL_ORDERING;
25
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
26
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
27
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
28

29
/**
30
 * Defines the <a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/">Oracle</a> SQL dialect.
31
 */
32
public class OracleDialect implements Dialect {
33
    private final EnumSet<Capability> supportedCaps;
34

35
    /**
36
     * Creates an Oracle {@link Dialect} implementation.
37
     */
38
    public OracleDialect() {
39
        this(EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, NULL_ORDERING, SELECT_FOR_UPDATE, TRUNCATE_TABLE));
8✔
40
    }
1✔
41

42
    private OracleDialect(EnumSet<Capability> capabilities) {
2✔
43
        this.supportedCaps = EnumSet.copyOf(capabilities);
4✔
44
    }
1✔
45

46
    @Override
47
    public String getProductName() {
48
        return "Oracle";
2✔
49
    }
50

51
    @Override
52
    public boolean offsetBeforeLimit() {
53
        return true;
2✔
54
    }
55

56
    /**
57
     * Row offset clause is supported from Oracle 12c onwards
58
     */
59
    @Override
60
    public Optional<String> formatRowOffsetClause() {
61
        return Optional.of("offset ? rows");
3✔
62
    }
63

64
    /**
65
     * Row limit clause is supported from Oracle 12c onwards
66
     */
67
    @Override
68
    public Optional<String> formatRowLimitClause() {
69
        return Optional.of("fetch next ? rows only");
3✔
70
    }
71

72
    @Override
73
    public Optional<String> formatRowNumLiteral() {
74
        return Optional.of("rownum");
3✔
75
    }
76

77
    @Override
78
    public String formatToNumberFunction(String operand, int precision, int scale) {
79
        StringBuilder mask = new StringBuilder();
4✔
80
        if (precision-scale > 0) {
4!
81
            mask.append(generate("9", precision-scale));
8✔
82
        }
83
        if (scale > 0) {
2!
84
            mask.append(".").append(generate("9", scale));
×
85
        }
86

87
        return "to_number(" + operand + ", '" + mask + "')";
5✔
88
    }
89

90
    @Override
91
    public String formatToCharFunction(String operand, String format) {
92
        return "to_char(" + operand + ", " + format + ")";
4✔
93
    }
94

95
    @Override
96
    public String formatSubstringFunction(String operand, int startPos, int length) {
97
        return "substr(" + operand + ", " + startPos + ", " + length + ")";
5✔
98
    }
99

100
    @Override
101
    public String formatConcatFunction(List<String> operands) {
102
        throw new UnsupportedOperationException("Oracle does not support the concat() function (use the concat infix operator instead)");
×
103
    }
104

105
    @Override
106
    public String formatLengthFunction(String operand) {
107
        return "length(" + operand + ")";
3✔
108
    }
109

110
    @Override
111
    public String formatCeilFunction(String operand) {
112
        return "ceil(" + operand + ")";
3✔
113
    }
114

115
    @Override
116
    public String formatRoundFunction(String operand) {
117
        return "round(" + operand + ")";
3✔
118
    }
119

120
    @Override
121
    public String formatModuloFunction(String divisor, String dividend) {
122
        return "mod(" + divisor + ", " + dividend + ")";
4✔
123
    }
124

125
    @Override
126
    public String formatCurrentDateFunction() {
127
        return "current_date";
2✔
128
    }
129

130
    @Override
131
    public Optional<String> getConcatOperator() {
132
        return Optional.of("||");
3✔
133
    }
134

135
    @Override
136
    public boolean supports(Capability capability) {
137
        return supportedCaps.contains(capability);
5✔
138
    }
139

140
    /**
141
     * Enables emulating OFFSET and LIMIT constructs for older Oracle versions.
142
     * Row offset and limit clauses are supported from Oracle 12c onwards.
143
     * Invoke this method when using previous versions of Oracle, to simulate these clauses with subqueries.
144
     * @return the modified dialect.
145
     */
146
    public OracleDialect withLegacyRowLimiting() {
147
        EnumSet<Capability> reducedCaps = EnumSet.copyOf(supportedCaps);
4✔
148
        reducedCaps.remove(LIMIT_OFFSET);
4✔
149
        return new OracleDialect(reducedCaps);
5✔
150
    }
151
}
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