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