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

torand / FasterSQL / 17012572989

16 Aug 2025 08:26PM UTC coverage: 68.265% (-0.008%) from 68.273%
17012572989

push

github

torand
refactor: sonar cloud issues

299 of 598 branches covered (50.0%)

Branch coverage included in aggregate %.

33 of 47 new or added lines in 18 files covered. (70.21%)

1 existing line in 1 file now uncovered.

1680 of 2301 relevant lines covered (73.01%)

3.89 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.javacommons.contract.Requires.requireNonBlank;
27

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

37
    /**
38
     * Creates a representation (model) of a database table.
39
     * @param name the table name.
40
     * @param tableFactory the instance factory.
41
     */
NEW
42
    protected Table(String name, TableFactory<T> 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 (model) 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<T> 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 model of a column belonging to this table.
62
     * @param name the column name.
63
     * @return the column model.
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 T 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