Package org.mybatis.dynamic.sql
Class SqlColumn<T>
- java.lang.Object
-
- org.mybatis.dynamic.sql.SqlColumn<T>
-
- All Implemented Interfaces:
BasicColumn
,BindableColumn<T>
,SortSpecification
public class SqlColumn<T> extends Object implements BindableColumn<T>, SortSpecification
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlColumn.Builder<T>
-
Field Summary
Fields Modifier and Type Field Description protected String
alias
protected boolean
isDescending
protected Class<T>
javaType
protected JDBCType
jdbcType
protected String
name
protected ParameterTypeConverter<T,?>
parameterTypeConverter
protected RenderingStrategy
renderingStrategy
protected SqlTable
table
protected BiFunction<TableAliasCalculator,SqlTable,Optional<String>>
tableQualifierFunction
protected String
typeHandler
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<String>
alias()
Returns the columns alias if one has been specified.SqlColumn<T>
as(String alias)
Override the base method definition to make it more specific to this interface.SqlColumn<T>
asCamelCase()
Set an alias with a camel cased string based on the column name.Object
convertParameterType(T value)
SortSpecification
descending()
Returns a new instance of the SortSpecification that should render as descending in an ORDER BY clause.boolean
isDescending()
Return true if the sort order is descending.Optional<Class<T>>
javaType()
Optional<JDBCType>
jdbcType()
String
name()
static <T> SqlColumn<T>
of(String name, SqlTable table)
static <T> SqlColumn<T>
of(String name, SqlTable table, JDBCType jdbcType)
String
orderByName()
Return the phrase that should be written into a rendered order by clause.SqlColumn<T>
qualifiedWith(String tableQualifier)
Override the calculated table qualifier if there is one.Optional<RenderingStrategy>
renderingStrategy()
String
renderWithTableAlias(TableAliasCalculator tableAliasCalculator)
Returns the name of the item aliased with a table name if appropriate.SqlTable
table()
Optional<String>
typeHandler()
<S> SqlColumn<S>
withJavaType(Class<S> javaType)
<S> SqlColumn<S>
withParameterTypeConverter(ParameterTypeConverter<S,?> parameterTypeConverter)
<S> SqlColumn<S>
withRenderingStrategy(RenderingStrategy renderingStrategy)
<S> SqlColumn<S>
withTypeHandler(String typeHandler)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mybatis.dynamic.sql.BasicColumn
renderWithTableAndColumnAlias
-
-
-
-
Field Detail
-
name
protected final String name
-
table
protected final SqlTable table
-
jdbcType
protected final JDBCType jdbcType
-
isDescending
protected final boolean isDescending
-
alias
protected final String alias
-
typeHandler
protected final String typeHandler
-
renderingStrategy
protected final RenderingStrategy renderingStrategy
-
parameterTypeConverter
protected final ParameterTypeConverter<T,?> parameterTypeConverter
-
tableQualifierFunction
protected final BiFunction<TableAliasCalculator,SqlTable,Optional<String>> tableQualifierFunction
-
-
Method Detail
-
name
public String name()
-
table
public SqlTable table()
-
jdbcType
public Optional<JDBCType> jdbcType()
- Specified by:
jdbcType
in interfaceBindableColumn<T>
-
alias
public Optional<String> alias()
Description copied from interface:BasicColumn
Returns the columns alias if one has been specified.- Specified by:
alias
in interfaceBasicColumn
- Returns:
- the column alias
-
typeHandler
public Optional<String> typeHandler()
- Specified by:
typeHandler
in interfaceBindableColumn<T>
-
convertParameterType
public Object convertParameterType(T value)
- Specified by:
convertParameterType
in interfaceBindableColumn<T>
-
descending
public SortSpecification descending()
Description copied from interface:SortSpecification
Returns a new instance of the SortSpecification that should render as descending in an ORDER BY clause.- Specified by:
descending
in interfaceSortSpecification
- Returns:
- new instance of SortSpecification
-
as
public SqlColumn<T> as(String alias)
Description copied from interface:BindableColumn
Override the base method definition to make it more specific to this interface.- Specified by:
as
in interfaceBasicColumn
- Specified by:
as
in interfaceBindableColumn<T>
- Parameters:
alias
- the column alias to set- Returns:
- new instance with alias set
-
qualifiedWith
public SqlColumn<T> qualifiedWith(String tableQualifier)
Override the calculated table qualifier if there is one. This is useful for sub-queries where the calculated table qualifier may not be correct in all cases.- Parameters:
tableQualifier
- the table qualifier to apply to the rendered column name- Returns:
- a new column that will be rendered with the specified table qualifier
-
asCamelCase
public SqlColumn<T> asCamelCase()
Set an alias with a camel cased string based on the column name. The can be useful for queries using theCommonSelectMapper
where the columns are placed into a map based on the column name returned from the database.A camel case string is mixed case, and most databases do not support unquoted mixed case strings as identifiers. Therefore the generated alias will be surrounded by double quotes thereby making it a quoted identifier. Most databases will respect quoted mixed case identifiers.
- Returns:
- a new column aliased with a camel case version of the column name
-
isDescending
public boolean isDescending()
Description copied from interface:SortSpecification
Return true if the sort order is descending.- Specified by:
isDescending
in interfaceSortSpecification
- Returns:
- true if the SortSpecification should render as descending
-
orderByName
public String orderByName()
Description copied from interface:SortSpecification
Return the phrase that should be written into a rendered order by clause. This should NOT include the "DESC" word for descending sort specifications.- Specified by:
orderByName
in interfaceSortSpecification
- Returns:
- the order by phrase
-
renderWithTableAlias
public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator)
Description copied from interface:BasicColumn
Returns the name of the item aliased with a table name if appropriate. For example, "a.foo". This is appropriate for where clauses and order by clauses.- Specified by:
renderWithTableAlias
in interfaceBasicColumn
- Parameters:
tableAliasCalculator
- the table alias calculator for the current renderer- Returns:
- the item name with the table alias applied
-
renderingStrategy
public Optional<RenderingStrategy> renderingStrategy()
- Specified by:
renderingStrategy
in interfaceBindableColumn<T>
-
withRenderingStrategy
@NotNull public <S> SqlColumn<S> withRenderingStrategy(RenderingStrategy renderingStrategy)
-
withParameterTypeConverter
@NotNull public <S> SqlColumn<S> withParameterTypeConverter(ParameterTypeConverter<S,?> parameterTypeConverter)
-
-