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

torand / FasterSQL / 13411942092

19 Feb 2025 11:56AM UTC coverage: 61.269% (-0.7%) from 61.922%
13411942092

push

github

torand
chore: prepare release

161 of 346 branches covered (46.53%)

Branch coverage included in aggregate %.

872 of 1340 relevant lines covered (65.07%)

3.43 hits per line

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

65.85
/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 java.util.List;
19
import java.util.stream.Stream;
20

21
import static io.github.torand.fastersql.util.collection.CollectionHelper.*;
22
import static io.github.torand.fastersql.util.contract.Requires.require;
23
import static java.util.Objects.requireNonNull;
24

25
public class Join {
26
    private enum JoinMode {
3✔
27
        INNER("inner join"), LEFT_OUTER("left outer join"), RIGHT_OUTER("right outer join");
21✔
28

29
        final String sql;
30

31
        JoinMode(String sql) {
4✔
32
            this.sql = sql;
3✔
33
        }
1✔
34
    }
35

36
    private final List<Field> lefts;
37
    private final List<Field> rights;
38
    private final JoinMode mode;
39

40
    public Join(Field left, Field right) {
2✔
41
        this.lefts = asList(requireNonNull(left, "No left field specified"));
12✔
42
        this.rights = asList(requireNonNull(right, "No right field specified"));
12✔
43
        this.mode = JoinMode.INNER;
3✔
44
    }
1✔
45

46
    private Join(List<Field> lefts, List<Field> rights, JoinMode mode) {
×
47
        this.lefts = asList(lefts);
×
48
        this.rights = asList(rights);
×
49
        this.mode = mode;
×
50
    }
×
51

52
    public Join leftOuter() {
53
        return new Join(lefts, rights, JoinMode.LEFT_OUTER);
×
54
    }
55

56
    public Join rightOuter() {
57
        return new Join(lefts, rights, JoinMode.RIGHT_OUTER);
×
58
    }
59

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

64
        List<Field> concatenatedLefts = concat(this.lefts, next.lefts);
×
65
        List<Field> concatenatedRights = concat(this.rights, next.rights);
×
66

67
        return new Join(concatenatedLefts, concatenatedRights, mode);
×
68
    }
69

70
    public String sql(Context context) {
71
        Table<?> rightTable = headOf(this.rights).table();
6✔
72
        StringBuilder sql = new StringBuilder()
6✔
73
            .append(mode.sql)
2✔
74
            .append(" ")
3✔
75
            .append(rightTable.sql(context))
3✔
76
            .append(" on ");
2✔
77

78
        for (int i = 0; i < this.lefts.size(); i++) {
9✔
79
            if (i > 0) {
2!
80
                sql.append(" and ");
×
81
            }
82
            sql.append(this.lefts.get(i).sql(context))
10✔
83
                .append(" = ")
4✔
84
                .append(this.rights.get(i).sql(context));
6✔
85
        }
86

87
        return sql.toString();
3✔
88
    }
89

90
    public Table<?> joined() {
91
        return headOf(rights).table();
6✔
92
    }
93

94
    public Stream<Field> fieldRefs() {
95
        return Stream.concat(streamSafely(lefts), streamSafely(rights));
8✔
96
    }
97
}
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