• 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

65.22
/src/main/java/io/github/torand/fastersql/model/Table.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.alias.TableAlias;
20
import io.github.torand.fastersql.relation.Relation;
21
import io.github.torand.fastersql.sql.Context;
22

23
import java.util.stream.Stream;
24

25
import static io.github.torand.fastersql.sql.Command.SELECT;
26
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
27

28
/**
29
 * A database table.
30
 * @param <ENTITY> the concrete table class with columns.
31
 */
32
public abstract class Table<ENTITY extends Table<?>> implements Relation {
33
    private final String name;
34
    private final TableAlias alias;
35
    private final TableFactory<ENTITY> tableFactory;
36

37
    /**
38
     * Creates a representation of a database table.
39
     * @param name the table name.
40
     * @param tableFactory the instance factory.
41
     */
42
    protected Table(String name, TableFactory<ENTITY> tableFactory) {
×
43
        this.name = requireNonBlank(name, "No name specified");
×
44
        this.alias = defaultAlias(name);
×
45
        this.tableFactory = tableFactory;
×
46
    }
×
47

48
    /**
49
     * Creates a representation of a database table.
50
     * @param name the table name.
51
     * @param alias the table alias.
52
     * @param tableFactory the instance factory.
53
     */
54
    protected Table(String name, String alias, TableFactory<ENTITY> tableFactory) {
2✔
55
        this.name = requireNonBlank(name, "No name specified");
7✔
56
        this.alias = new TableAlias(requireNonBlank(alias, "No alias specified"));
10✔
57
        this.tableFactory = tableFactory;
3✔
58
    }
1✔
59

60
    /**
61
     * Creates a column of this table.
62
     * @param name the column name.
63
     * @return the column.
64
     */
65
    public Column column(String name) {
66
        return new Column(this, name);
6✔
67
    }
68

69
    /**
70
     * Gets the table name.
71
     * @return the table name.
72
     */
73
    public String name() {
74
        return name;
3✔
75
    }
76

77
    // Sql
78

79
    @Override
80
    public String sql(Context context) {
81
        if (context.isCommand(SELECT)) {
4✔
82
            return name + " " + alias.sql(context);
8✔
83
        } else {
84
            return name;
3✔
85
        }
86
    }
87

88
    @Override
89
    public Stream<Object> params(Context context) {
90
        return Stream.empty();
2✔
91
    }
92

93
    @Override
94
    public Stream<Column> columnRefs() {
95
        return Stream.empty();
×
96
    }
97

98
    @Override
99
    public Stream<ColumnAlias> aliasRefs() {
100
        return Stream.empty();
×
101
    }
102

103
    // Relation
104

105
    @Override
106
    public ENTITY as(String alias) {
107
        return tableFactory.newInstance(alias);
6✔
108
    }
109

110
    @Override
111
    public TableAlias alias() {
112
        return alias;
3✔
113
    }
114

115
    private TableAlias defaultAlias(String name) {
116
        return new TableAlias(name);
×
117
    }
118
}
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