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

torand / FasterSQL / 13457551617

21 Feb 2025 01:12PM UTC coverage: 63.175% (+0.2%) from 62.933%
13457551617

push

github

torand
feat: add support for order by column indices + null ordering

190 of 386 branches covered (49.22%)

Branch coverage included in aggregate %.

50 of 71 new or added lines in 13 files covered. (70.42%)

1 existing line in 1 file now uncovered.

968 of 1447 relevant lines covered (66.9%)

3.52 hits per line

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

55.88
/src/main/java/io/github/torand/fastersql/order/Descending.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.order;
17

18
import io.github.torand.fastersql.Context;
19
import io.github.torand.fastersql.Field;
20
import io.github.torand.fastersql.dialect.Capability;
21
import io.github.torand.fastersql.projection.Projection;
22

23
import java.util.stream.Stream;
24

25
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
26
import static java.lang.Boolean.FALSE;
27
import static java.lang.Boolean.TRUE;
28
import static java.util.Objects.nonNull;
29
import static java.util.Objects.requireNonNull;
30

31
public class Descending implements Order {
32
    private final Projection projection;
33
    private final String alias;
34
    private final Integer index;
35
    private final Boolean nullsFirst;
36

37
    Descending(Projection projection) {
38
        this(requireNonNull(projection, "No projection specified"), projection.alias(), null, null);
10✔
39
    }
1✔
40

41
    Descending(String alias) {
NEW
42
        this(null, requireNonBlank(alias, "No alias specified"), null, null);
×
NEW
43
    }
×
44

45
    Descending(Integer index) {
NEW
46
        this(null, null, requireNonNull(index, "No index specified"), null);
×
NEW
47
    }
×
48

49
    private Descending(Projection projection, String alias, Integer index, Boolean nullsFirst) {
2✔
50
        this.projection = projection;
3✔
51
        this.alias = alias;
3✔
52
        this.index = index;
3✔
53
        this.nullsFirst = nullsFirst;
3✔
54
    }
1✔
55

56
    public Descending nullsFirst() {
NEW
57
        return new Descending(projection, alias, index, true);
×
58
    }
59

60
    public Descending nullsLast() {
NEW
61
        return new Descending(projection, alias, index, false);
×
62
    }
63

64
    // Sql
65

66
    @Override
67
    public String sql(Context context) {
68
        if (nonNull(nullsFirst) && !context.getDialect().supports(Capability.NULL_ORDERING)) {
4!
NEW
69
            throw new UnsupportedOperationException("%s does not support 'nulls first' or 'nulls last'".formatted(context.getDialect().getProductName()));
×
70
        }
71

72
        return (nonNull(index) ? index : alias)
8!
73
            + " desc"
74
            + (TRUE.equals(nullsFirst) ? " nulls first" : "")
6!
75
            + (FALSE.equals(nullsFirst) ? " nulls last" : "");
7!
76
    }
77

78
    @Override
79
    public Stream<Object> params(Context context) {
80
        return Stream.empty();
×
81
    }
82

83
    // Order
84

85
    @Override
86
    public String alias() {
87
        return alias;
3✔
88
    }
89

90
    @Override
91
    public Stream<Field> fieldRefs() {
92
        return projection instanceof Field ? Stream.of((Field)projection) : Stream.empty();
10!
93
    }
94
}
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