• 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

95.83
/src/main/java/io/github/torand/fastersql/model/Column.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.model;
17

18
import io.github.torand.fastersql.alias.ColumnAlias;
19
import io.github.torand.fastersql.expression.Expression;
20
import io.github.torand.fastersql.join.Join;
21
import io.github.torand.fastersql.order.OrderExpression;
22
import io.github.torand.fastersql.predicate.LeftOperand;
23
import io.github.torand.fastersql.projection.Projection;
24
import io.github.torand.fastersql.sql.Context;
25

26
import java.util.Optional;
27
import java.util.stream.Stream;
28

29
import static io.github.torand.fastersql.sql.Command.SELECT;
30
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
31
import static java.util.Objects.requireNonNull;
32

33
/**
34
 * A column in a database table.
35
 */
36
public class Column implements LeftOperand, Expression, OrderExpression {
37
    private final Table<?> table;
38
    private final String name;
39
    private final ColumnAlias alias;
40

41
    /**
42
     * Creates a representation of a column inside a database table.
43
     * @param table the table representation.
44
     * @param name the column name.
45
     */
46
    public Column(Table<?> table, String name) {
2✔
47
        this.table = requireNonNull(table, "No table specified");
6✔
48
        this.name = requireNonBlank(name, "No name specified");
7✔
49
        this.alias = defaultAlias(table, name);
6✔
50
    }
1✔
51

52
    private Column(Table<?> table, String name, String alias) {
2✔
53
        this.table = requireNonNull(table, "No table specified");
6✔
54
        this.name = requireNonBlank(name, "No name specified");
7✔
55
        this.alias = new ColumnAlias(requireNonBlank(alias, "No alias specified"));
10✔
56
    }
1✔
57

58
    /**
59
     * Creates a JOIN clause by associating this column with specified column of another table.
60
     * @param other the other column.
61
     * @return the JOIN clause.
62
     */
63
    public Join on(Column other) {
64
        return new Join(this, other);
6✔
65
    }
66

67
    /**
68
     * Gets the column name.
69
     * @return the column name.
70
     */
71
    public String name() {
72
        return name;
×
73
    }
74

75
    /**
76
     * Gets the table this column belongs to.
77
     * @return the table.
78
     */
79
    public Table<?> table() {
80
        return table;
3✔
81
    }
82

83
    // Sql
84

85
    @Override
86
    public String sql(Context context) {
87
        if (context.isCommand(SELECT)) {
4✔
88
            return table.alias().name() + "." + name;
8✔
89
        } else {
90
            return name;
3✔
91
        }
92
    }
93

94
    @Override
95
    public Stream<Object> params(Context context) {
96
        return Stream.empty();
2✔
97
    }
98

99
    @Override
100
    public Stream<Column> columnRefs() {
101
        return Stream.of(this);
3✔
102
    }
103

104
    @Override
105
    public Stream<ColumnAlias> aliasRefs() {
106
        return Stream.of(alias);
4✔
107
    }
108

109
    // Projection
110

111
    @Override
112
    public Projection as(String alias) {
113
        return new Column(table, name, alias);
9✔
114
    }
115

116
    @Override
117
    public Optional<ColumnAlias> alias() {
118
        return Optional.ofNullable(alias);
4✔
119
    }
120

121
    private ColumnAlias defaultAlias(Table<?> table, String name) {
122
        return new ColumnAlias((table.alias().name() + "_" + name).toUpperCase());
10✔
123
    }
124
}
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