1 | package org.sqlorm.querybuilder; |
2 | |
3 | /** |
4 | * @author kasper graversen |
5 | */ |
6 | class ColumnIdentifierExpr implements IPositionSelectColumn, IPositionOrderBy { |
7 | private final String select; |
8 | private final String alias; |
9 | |
10 | public ColumnIdentifierExpr(final String select) { |
11 | this(select, ""); |
12 | } |
13 | |
14 | public ColumnIdentifierExpr(final String select, final String alias) { |
15 | if(select.trim().equals("")) |
16 | throw new IllegalArgumentException("Select parameter cannot be the empty string"); |
17 | this.select = select; |
18 | this.alias = alias; |
19 | } |
20 | |
21 | @Override |
22 | public boolean equals(final Object other) { |
23 | if(other instanceof ColumnIdentifierExpr == false) |
24 | return false; |
25 | final ColumnIdentifierExpr o = (ColumnIdentifierExpr) other; |
26 | return select.equals(o.select) && alias.equals(o.alias); |
27 | } |
28 | |
29 | public void toSql(final StringBuilder sb, final String indent) { |
30 | sb.append(indent + select + (alias.equals("") ? "" : " AS " + alias)); |
31 | } |
32 | } |