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

mybatis / mybatis-dynamic-sql / #1260

pending completion
#1260

Pull #566

github

web-flow
Merge 57821f321 into c79619396
Pull Request #566: Update dependency org.mybatis:mybatis-parent to v37

4227 of 4227 relevant lines covered (100.0%)

1.0 hits per line

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

100.0
/src/main/java/org/mybatis/dynamic/sql/BasicColumn.java
1
/*
2
 *    Copyright 2016-2022 the original author or authors.
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
 *       https://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 org.mybatis.dynamic.sql;
17

18
import java.util.Optional;
19

20
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
21

22
/**
23
 * Describes attributes of columns that are necessary for rendering if the column is not expected to
24
 * be bound as a JDBC parameter.  Columns in select lists, join expressions, and group by expressions
25
 * are typically not bound.
26
 *
27
 * @author Jeff Butler
28
 */
29
public interface BasicColumn {
30

31
    /**
32
     * Returns the columns alias if one has been specified.
33
     *
34
     * @return the column alias
35
     */
36
    Optional<String> alias();
37

38
    /**
39
     * Returns a new instance of a BasicColumn with the alias set.
40
     *
41
     * @param alias
42
     *            the column alias to set
43
     *
44
     * @return new instance with alias set
45
     */
46
    BasicColumn as(String alias);
47

48
    /**
49
     * Returns the name of the item aliased with a table name if appropriate.
50
     * For example, "a.foo".  This is appropriate for where clauses and order by clauses.
51
     *
52
     * @param tableAliasCalculator the table alias calculator for the current renderer
53
     * @return the item name with the table alias applied
54
     */
55
    String renderWithTableAlias(TableAliasCalculator tableAliasCalculator);
56

57
    /**
58
     * Returns the name of the item aliased with a table name and column alias if appropriate.
59
     * For example, "a.foo as bar".  This is appropriate for select list clauses.
60
     *
61
     * @param tableAliasCalculator the table alias calculator for the current renderer
62
     * @return the item name with the table and column aliases applied
63
     */
64
    default String renderWithTableAndColumnAlias(TableAliasCalculator tableAliasCalculator) {
65
        String nameAndTableAlias = renderWithTableAlias(tableAliasCalculator);
1✔
66

67
        return alias().map(a -> nameAndTableAlias + " as " + a) //$NON-NLS-1$
1✔
68
                .orElse(nameAndTableAlias);
1✔
69
    }
70

71
    /**
72
     * Utility method to make it easier to build column lists for methods that require an
73
     * array rather than the varargs method.
74
     *
75
     * @param columns list of BasicColumn
76
     * @return an array of BasicColumn
77
     */
78
    static BasicColumn[] columnList(BasicColumn... columns) {
79
        return columns;
1✔
80
    }
81
}
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

© 2025 Coveralls, Inc