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

torand / FasterSQL / 13591799490

28 Feb 2025 03:59PM UTC coverage: 65.237% (-1.3%) from 66.563%
13591799490

push

github

web-flow
Merge pull request #14 from torand/having-support

feat: supporting the HAVING clause + IS NULL operator now supports an…

214 of 408 branches covered (52.45%)

Branch coverage included in aggregate %.

273 of 389 new or added lines in 69 files covered. (70.18%)

3 existing lines in 3 files now uncovered.

1079 of 1574 relevant lines covered (68.55%)

3.68 hits per line

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

62.79
/src/main/java/io/github/torand/fastersql/Join.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;
17

18
import io.github.torand.fastersql.alias.ColumnAlias;
19

20
import java.util.List;
21
import java.util.stream.Stream;
22

23
import static io.github.torand.fastersql.util.collection.CollectionHelper.asList;
24
import static io.github.torand.fastersql.util.collection.CollectionHelper.concat;
25
import static io.github.torand.fastersql.util.collection.CollectionHelper.headOf;
26
import static io.github.torand.fastersql.util.collection.CollectionHelper.streamSafely;
27
import static io.github.torand.fastersql.util.contract.Requires.require;
28
import static java.util.Objects.requireNonNull;
29

30
public class Join implements Sql {
31
    private enum JoinMode {
3✔
32
        INNER("inner join"), LEFT_OUTER("left outer join"), RIGHT_OUTER("right outer join");
21✔
33

34
        final String sql;
35

36
        JoinMode(String sql) {
4✔
37
            this.sql = sql;
3✔
38
        }
1✔
39
    }
40

41
    private final List<Column> lefts;
42
    private final List<Column> rights;
43
    private final JoinMode mode;
44

45
    public Join(Column left, Column right) {
2✔
46
        this.lefts = asList(requireNonNull(left, "No left column specified"));
12✔
47
        this.rights = asList(requireNonNull(right, "No right column specified"));
12✔
48
        this.mode = JoinMode.INNER;
3✔
49
    }
1✔
50

NEW
51
    private Join(List<Column> lefts, List<Column> rights, JoinMode mode) {
×
52
        this.lefts = asList(lefts);
×
53
        this.rights = asList(rights);
×
54
        this.mode = mode;
×
55
    }
×
56

57
    public Join leftOuter() {
58
        return new Join(lefts, rights, JoinMode.LEFT_OUTER);
×
59
    }
60

61
    public Join rightOuter() {
62
        return new Join(lefts, rights, JoinMode.RIGHT_OUTER);
×
63
    }
64

65
    public Join and(Join next) {
66
        require(() -> headOf(this.lefts).table().equals(headOf(next.lefts).table()), "Left side of nested joins must belong to the same table");
×
67
        require(() -> headOf(this.rights).table().equals(headOf(next.rights).table()), "Right side of nested joins must belong to the same table");
×
68

NEW
69
        List<Column> concatenatedLefts = concat(this.lefts, next.lefts);
×
NEW
70
        List<Column> concatenatedRights = concat(this.rights, next.rights);
×
71

72
        return new Join(concatenatedLefts, concatenatedRights, mode);
×
73
    }
74

75
    public Table<?> joined() {
76
        return headOf(rights).table();
6✔
77
    }
78

79
    // Sql
80

81
    @Override
82
    public String sql(Context context) {
83
        Table<?> rightTable = headOf(this.rights).table();
6✔
84
        StringBuilder sql = new StringBuilder()
6✔
85
            .append(mode.sql)
2✔
86
            .append(" ")
3✔
87
            .append(rightTable.sql(context))
3✔
88
            .append(" on ");
2✔
89

90
        for (int i = 0; i < this.lefts.size(); i++) {
9✔
91
            if (i > 0) {
2!
92
                sql.append(" and ");
×
93
            }
94
            sql.append(this.lefts.get(i).sql(context))
10✔
95
                .append(" = ")
4✔
96
                .append(this.rights.get(i).sql(context));
6✔
97
        }
98

99
        return sql.toString();
3✔
100
    }
101

102
    @Override
103
    public Stream<Object> params(Context context) {
NEW
104
        return Stream.empty();
×
105
    }
106

107
    @Override
108
    public Stream<Column> columnRefs() {
109
        return Stream.concat(streamSafely(lefts), streamSafely(rights));
8✔
110
    }
111

112
    @Override
113
    public Stream<ColumnAlias> aliasRefs() {
NEW
114
        return Stream.empty();
×
115
    }
116
}
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